org.apache.tinkerpop.gremlin.process.traversal.Contains Java Examples

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.Contains. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TraversalUtil.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
public static Condition convHas2Condition(HasContainer has,
                                          HugeType type,
                                          HugeGraph graph) {
    P<?> p = has.getPredicate();
    E.checkArgument(p != null, "The predicate of has(%s) is null", has);
    BiPredicate<?, ?> bp = p.getBiPredicate();
    Condition condition;
    if (keyForContainsKeyOrValue(has.getKey())) {
        condition = convContains2Relation(graph, has);
    } else if (bp instanceof Compare) {
        condition = convCompare2Relation(graph, type, has);
    } else if (bp instanceof RelationType) {
        condition = convRelationType2Relation(graph, type, has);
    } else if (bp instanceof Contains) {
        condition = convIn2Relation(graph, type, has);
    } else if (p instanceof AndP) {
        condition = convAnd(graph, type, has);
    } else if (p instanceof OrP) {
        condition = convOr(graph, type, has);
    } else {
        // TODO: deal with other Predicate
        throw newUnsupportedPredicate(p);
    }
    return condition;
}
 
Example #2
Source File: TitanPredicate.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
/**
 * Convert Tinkerpop's comparison operators to Titan's
 *
 * @param p Any predicate
 * @return A TitanPredicate equivalent to the given predicate
 * @throws IllegalArgumentException if the given Predicate is unknown
 */
public static final TitanPredicate convertInternal(BiPredicate p) {
    if (p instanceof TitanPredicate) {
        return (TitanPredicate)p;
    } else if (p instanceof Compare) {
        Compare comp = (Compare)p;
        switch(comp) {
            case eq: return Cmp.EQUAL;
            case neq: return Cmp.NOT_EQUAL;
            case gt: return Cmp.GREATER_THAN;
            case gte: return Cmp.GREATER_THAN_EQUAL;
            case lt: return Cmp.LESS_THAN;
            case lte: return Cmp.LESS_THAN_EQUAL;
            default: throw new IllegalArgumentException("Unexpected comparator: " + comp);
        }
    } else if (p instanceof Contains) {
        Contains con = (Contains)p;
        switch (con) {
            case within: return Contain.IN;
            case without: return Contain.NOT_IN;
            default: throw new IllegalArgumentException("Unexpected container: " + con);

        }
    } else return null;
}
 
Example #3
Source File: JanusGraphPredicate.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Convert Tinkerpop's comparison operators to JanusGraph's
 *
 * @param p Any predicate
 * @return A JanusGraphPredicate equivalent to the given predicate
 * @throws IllegalArgumentException if the given Predicate is unknown
 */
public static JanusGraphPredicate convertInternal(BiPredicate p) {
    if (p instanceof JanusGraphPredicate) {
        return (JanusGraphPredicate) p;
    } else if (p instanceof Compare) {
        final Compare comp = (Compare) p;
        switch (comp) {
            case eq:
                return Cmp.EQUAL;
            case neq:
                return Cmp.NOT_EQUAL;
            case gt:
                return Cmp.GREATER_THAN;
            case gte:
                return Cmp.GREATER_THAN_EQUAL;
            case lt:
                return Cmp.LESS_THAN;
            case lte:
                return Cmp.LESS_THAN_EQUAL;
            default:
                throw new IllegalArgumentException("Unexpected comparator: " + comp);
        }
    } else if (p instanceof Contains) {
        final Contains con = (Contains) p;
        switch (con) {
            case within:
                return Contain.IN;
            case without:
                return Contain.NOT_IN;
            default:
                throw new IllegalArgumentException("Unexpected container: " + con);

        }
    } else return null;
}
 
Example #4
Source File: GraphStep.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method for providers that want to "fold in" {@link HasContainer}'s based on id checking into the ids of the {@link GraphStep}.
 *
 * @param graphStep    the GraphStep to potentially {@link GraphStep#addIds(Object...)}.
 * @param hasContainer The {@link HasContainer} to check for id validation.
 * @return true if the {@link HasContainer} updated ids and thus, was processed.
 */
public static boolean processHasContainerIds(final GraphStep<?, ?> graphStep, final HasContainer hasContainer) {
    if (hasContainer.getKey().equals(T.id.getAccessor()) && graphStep.ids.length == 0 &&
            (hasContainer.getBiPredicate() == Compare.eq || hasContainer.getBiPredicate() == Contains.within)) {
        graphStep.addIds(hasContainer.getValue());
        return true;
    }
    return false;
}
 
Example #5
Source File: WhereClause.java    From sqlg with MIT License 5 votes vote down vote up
private static String containsToSql(Contains contains, int size) {
    String result;
    if (size == 1) {
        switch (contains) {
            case within:
                result = " = ?";
                break;
            case without:
                result = " <> ?";
                break;
            default:
                throw new RuntimeException("Unknown Contains" + contains.name());
        }
    } else {
        switch (contains) {
            case within:
                result = " in (";
                break;
            case without:
                result = " not in (";
                break;
            default:
                throw new RuntimeException("Unknown Contains" + contains.name());
        }
        for (int i = 0; i < size; i++) {
            result += "?";
            if (i < size - 1 && size > 1) {
                result += ", ";

            }
        }
        result += ")";
    }
    return result;
}
 
Example #6
Source File: SqlgUtil.java    From sqlg with MIT License 4 votes vote down vote up
public static boolean isBulkWithinAndOut(SqlgGraph sqlgGraph, HasContainer hasContainer) {
    BiPredicate p = hasContainer.getPredicate().getBiPredicate();
    return (p == Contains.within || p == Contains.without) && ((Collection) hasContainer.getPredicate().getValue()).size() > sqlgGraph.configuration().getInt("bulk.within.count", BULK_WITHIN_COUNT);
}
 
Example #7
Source File: SqlgUtil.java    From sqlg with MIT License 4 votes vote down vote up
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public static boolean isBulkWithin(SqlgGraph sqlgGraph, HasContainer hasContainer) {
    BiPredicate p = hasContainer.getPredicate().getBiPredicate();
    return p == Contains.within && ((Collection) hasContainer.getPredicate().getValue()).size() > sqlgGraph.configuration().getInt("bulk.within.count", BULK_WITHIN_COUNT);
}