本文整理汇总了Java中org.apache.tinkerpop.gremlin.process.traversal.Compare类的典型用法代码示例。如果您正苦于以下问题:Java Compare类的具体用法?Java Compare怎么用?Java Compare使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Compare类属于org.apache.tinkerpop.gremlin.process.traversal包,在下文中一共展示了Compare类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: lookupEdges
import org.apache.tinkerpop.gremlin.process.traversal.Compare; //导入依赖的package包/类
private Iterator<Edge> lookupEdges(final Traverser.Admin<Vertex> traverser, final List<HasContainer> hasContainers) {
final HBaseGraph graph = (HBaseGraph) this.getTraversal().getGraph().get();
if (getEdgeLabels().length == 1) {
final String label = getEdgeLabels()[0];
// find an edge by label and key/value
for (final HasContainer hasContainer : hasContainers) {
if (Compare.eq == hasContainer.getBiPredicate() && !hasContainer.getKey().equals(T.label.getAccessor())) {
if (graph.hasIndex(OperationType.READ, ElementType.EDGE, label, hasContainer.getKey())) {
return IteratorUtils.stream(((HBaseVertex) traverser.get()).edges(getDirection(), label, hasContainer.getKey(), hasContainer.getValue()))
.filter(vertex -> HasContainer.testAll(vertex, hasContainers)).iterator();
}
}
}
}
// linear scan
return CloseableIteratorUtils.filter(traverser.get().edges(getDirection(), getEdgeLabels()),
edge -> HasContainer.testAll(edge, hasContainers));
}
示例2: convertInternal
import org.apache.tinkerpop.gremlin.process.traversal.Compare; //导入依赖的package包/类
/**
* 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;
}
示例3: translate
import org.apache.tinkerpop.gremlin.process.traversal.Compare; //导入依赖的package包/类
@Override
public <V> P<V> translate(P<V> predicate) {
BiPredicate<V, V> biPredicate = predicate.getBiPredicate();
if (biPredicate instanceof Compare){
String predicateString = biPredicate.toString();
V value = predicate.getValue();
switch (predicateString){
case "eq":
return Date.eq(value);
case "neq":
return Date.neq(value);
case "lt":
return Date.lt(value);
case "gt":
return Date.gt(value);
case "lte":
return Date.lte(value);
case "gte":
return Date.gte(value);
default:
throw new IllegalArgumentException("cant convert '" + predicateString +"' to DatePredicate");
}
} else
throw new IllegalArgumentException("cant convert '" + biPredicate.toString() +"' to DatePredicate");
}
示例4: getTypeFilter
import org.apache.tinkerpop.gremlin.process.traversal.Compare; //导入依赖的package包/类
private static QueryBuilder getTypeFilter(HasContainer has) {
BiPredicate<?, ?> biPredicate = has.getBiPredicate();
if (biPredicate instanceof Compare) {
QueryBuilder query = QueryBuilders.typeQuery(has.getValue().toString());
if (biPredicate.equals(Compare.eq)) return query;
return QueryBuilders.boolQuery().mustNot(query);
} else if (biPredicate instanceof Contains) {
Collection values = (Collection) has.getValue();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolean within = biPredicate.equals(Contains.within);
values.forEach(label -> {
TypeQueryBuilder typeQueryBuilder = QueryBuilders.typeQuery(label.toString());
if (within) boolQueryBuilder.should(typeQueryBuilder);
else boolQueryBuilder.mustNot(typeQueryBuilder);
});
return boolQueryBuilder;
} else throw new IllegalArgumentException("predicate not supported by unipop: " + biPredicate.toString());
}
示例5: predicateToQuery
import org.apache.tinkerpop.gremlin.process.traversal.Compare; //导入依赖的package包/类
private Condition predicateToQuery(String field, Object value, BiPredicate<?, ?> biPredicate) {
if (biPredicate instanceof Compare) {
return getCompareCondition(value, biPredicate, field(field));
} else if (biPredicate instanceof Contains) {
Condition x = getContainsCondition(value, biPredicate, field(field));
if (x != null) return x;
}
else if (biPredicate instanceof Text.TextPredicate) {
return getTextCondition(value, biPredicate, field(field));
} else if (biPredicate instanceof Date.DatePredicate) {
try {
return getDateCondition(value, biPredicate, field(field));
} catch (ParseException e) {
throw new IllegalArgumentException("cant convert to date");
}
}
throw new IllegalArgumentException("can't create condition");
}
示例6: getGremlinPredicate
import org.apache.tinkerpop.gremlin.process.traversal.Compare; //导入依赖的package包/类
private Compare getGremlinPredicate(ComparisionOperator op) {
switch (op) {
case EQUAL:
return Compare.eq;
case GREATER_THAN:
return Compare.gt;
case GREATER_THAN_EQUAL:
return Compare.gte;
case LESS_THAN:
return Compare.lt;
case LESS_THAN_EQUAL:
return Compare.lte;
case NOT_EQUAL:
return Compare.neq;
default:
throw new RuntimeException("Unsupported comparison operator:" + op);
}
}
示例7: testMultiplePath
import org.apache.tinkerpop.gremlin.process.traversal.Compare; //导入依赖的package包/类
@Test
public void testMultiplePath(){
Vertex v1 = this.sqlgGraph.addVertex(T.label, "Person", "name", "johnny", "score",2,"experience",3);
Vertex v2 = this.sqlgGraph.addVertex(T.label, "Person", "name", "pietie", "score",2,"experience",2);
Vertex v3 = this.sqlgGraph.addVertex(T.label, "Person", "name", "koosie", "score",2,"experience",1);
Vertex v4 = this.sqlgGraph.addVertex(T.label, "Group", "name", "Friends");
v4.addEdge("contains", v1);
v4.addEdge("contains", v2);
v4.addEdge("contains", v3);
Vertex v5 = this.sqlgGraph.addVertex(T.label, "Company", "name", "Acme");
v5.addEdge("groups", v4);
this.sqlgGraph.tx().commit();
GraphTraversal<Vertex, Map<String,Object>> traversal =sqlgGraph.traversal()
.V().hasLabel("Company").as("c").out("groups")
.as("g").out("contains").has("score",propertyRef(Compare.eq, "experience")).as("p")
.select("c","p");
List<Map<String,Object>> l =traversal.toList();
assertEquals(1,l.size());
assertEquals(v2,l.get(0).get("p"));
}
示例8: compareToSql
import org.apache.tinkerpop.gremlin.process.traversal.Compare; //导入依赖的package包/类
private static String compareToSql(Compare compare) {
switch (compare) {
case eq:
return " = ?";
case neq:
return " <> ?";
case gt:
return " > ?";
case gte:
return " >= ?";
case lt:
return " < ?";
case lte:
return " <= ?";
default:
throw new RuntimeException("Unknown Compare " + compare.name());
}
}
示例9: addIdHasContainers
import org.apache.tinkerpop.gremlin.process.traversal.Compare; //导入依赖的package包/类
private void addIdHasContainers(SchemaTableTree schemaTableTree1, List<Multimap<BiPredicate, RecordId>> biPredicateRecordIds) {
if (biPredicateRecordIds != null) {
for (Multimap<BiPredicate, RecordId> biPredicateRecordId : biPredicateRecordIds) {
for (BiPredicate biPredicate : biPredicateRecordId.keySet()) {
Collection<RecordId> recordIds = biPredicateRecordId.get(biPredicate);
HasContainer idHasContainer;
//id hasContainers are only optimized for BaseStrategy.SUPPORTED_ID_BI_PREDICATE within, without, eq, neq
if (biPredicate == Contains.without || biPredicate == Contains.within) {
idHasContainer = new HasContainer(T.id.getAccessor(), P.test(biPredicate, recordIds));
schemaTableTree1.getHasContainers().add(idHasContainer);
} else {
Preconditions.checkState(biPredicate == Compare.eq || biPredicate == Compare.neq);
for (RecordId recordId : recordIds) {
idHasContainer = new HasContainer(T.id.getAccessor(), P.test(biPredicate, recordId));
schemaTableTree1.getHasContainers().add(idHasContainer);
}
}
}
}
}
}
示例10: getIndexKey
import org.apache.tinkerpop.gremlin.process.traversal.Compare; //导入依赖的package包/类
private HasContainer getIndexKey(final Class<? extends Element> indexedClass) {
final Set<String> indexedKeys = ((TinkerGraph) this.getTraversal().getGraph().get()).getIndexedKeys(indexedClass);
final Iterator<HasContainer> itty = IteratorUtils.filter(hasContainers.iterator(),
c -> c.getPredicate().getBiPredicate() == Compare.eq && indexedKeys.contains(c.getKey()));
return itty.hasNext() ? itty.next() : null;
}
示例11: labelFromWhereEqPredicate
import org.apache.tinkerpop.gremlin.process.traversal.Compare; //导入依赖的package包/类
private Optional<String> labelFromWhereEqPredicate(WherePredicateStep<Vertex> whereStep) {
Optional<P<?>> optionalPredicate = whereStep.getPredicate();
return optionalPredicate.flatMap(predicate -> {
if (!predicate.getBiPredicate().equals(Compare.eq)) return Optional.empty();
return Optional.of((String) predicate.getValue());
});
}
示例12: processHasContainerIds
import org.apache.tinkerpop.gremlin.process.traversal.Compare; //导入依赖的package包/类
/**
* 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()) && (hasContainer.getBiPredicate() == Compare.eq || hasContainer.getBiPredicate() == Contains.within)) {
graphStep.addIds(hasContainer.getValue());
return true;
}
return false;
}
示例13: getIndexKey
import org.apache.tinkerpop.gremlin.process.traversal.Compare; //导入依赖的package包/类
private HasContainer getIndexKey(final Class<? extends Element> indexedClass) {
final Set<String> indexedKeys = ((LiteGraph) this.getTraversal().getGraph().get()).getIndexedKeys(indexedClass);
final Iterator<HasContainer> itty = IteratorUtils.filter(hasContainers.iterator(),
c -> c.getPredicate().getBiPredicate() == Compare.eq && indexedKeys.contains(c.getKey()));
return itty.hasNext() ? itty.next() : null;
}
示例14: predicateToQuery
import org.apache.tinkerpop.gremlin.process.traversal.Compare; //导入依赖的package包/类
private static QueryBuilder predicateToQuery(String key, Object value, BiPredicate<?, ?> biPredicate) {
if (biPredicate instanceof Compare) return getCompareFilter(key, value, biPredicate.toString());
else if (biPredicate instanceof Contains) return getContainsFilter(key, value, biPredicate);
// else if (biPredicate instanceof Geo) return getGeoFilter(key, value, (Geo) biPredicate);
else if (biPredicate instanceof Text.TextPredicate)
return getTextFilter(key, value, (Text.TextPredicate) biPredicate);
else throw new IllegalArgumentException("predicate not supported by unipop: " + biPredicate.toString());
}
示例15: findIndex
import org.apache.tinkerpop.gremlin.process.traversal.Compare; //导入依赖的package包/类
@VisibleForTesting
public Set<OrientIndexQuery> findIndex() {
final Set<OrientIndexQuery> indexedQueries = new HashSet<>();
final OrientGraph graph = getGraph();
final OIndexManagerProxy indexManager = graph.database().getMetadata().getIndexManager();
// find indexed keys only for the element subclasses (if present)
final Set<String> classLabels = findClassLabelsInHasContainers();
if (!classLabels.isEmpty()) {
final Set<String> indexedKeys = new HashSet<>();// classLabels.isPresent() ? graph.getIndexedKeys(this.returnClass, classLabels.get()) : graph.getIndexedKeys(this.returnClass);
classLabels.forEach(label -> indexedKeys.addAll(graph.getIndexedKeys(this.returnClass, label)));
this.hasContainers.stream()
.filter(c -> indexedKeys.contains(c.getKey()) && (c.getPredicate().getBiPredicate() == Compare.eq ||
c.getPredicate().getBiPredicate() == Contains.within))
.findAny()
.ifPresent(requestedKeyValue -> {
String key = requestedKeyValue.getKey();
classLabels.forEach(classLabel -> {
Iterator<Object> values = getValueIterator(requestedKeyValue);
String className = graph.labelToClassName(classLabel, isVertexStep() ? OClass.VERTEX_CLASS_NAME : OClass.EDGE_CLASS_NAME);
Set<OIndex<?>> classIndexes = indexManager.getClassIndexes(className);
Iterator<OIndex<?>> keyIndexes = classIndexes.stream().filter(idx -> idx.getDefinition().getFields().contains(key)).iterator();
if (keyIndexes.hasNext()) {
// TODO: select best index if there are multiple options
indexedQueries.add(new OrientIndexQuery(keyIndexes.next(), values));
} else {
OLogManager.instance().warn(this, "no index found for class=[" + className + "] and key=[" + key + "]");
}
});
});
}
return indexedQueries;
}