本文整理汇总了Java中org.apache.tinkerpop.gremlin.process.traversal.Order类的典型用法代码示例。如果您正苦于以下问题:Java Order类的具体用法?Java Order怎么用?Java Order使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Order类属于org.apache.tinkerpop.gremlin.process.traversal包,在下文中一共展示了Order类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: data
import org.apache.tinkerpop.gremlin.process.traversal.Order; //导入依赖的package包/类
@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{"filter(x->true)", __.filter(x -> true), false},
{"map(Traverser::get)", __.map(Traverser::get), false},
{"sideEffect(x -> {int i = 1+1;})", __.sideEffect(x -> {
int i = 1 + 1;
}), false},
{"select('a','b').by(Object::toString)", __.select("a", "b").by(Object::toString), false},
{"order().by((a,b)->a.compareTo(b))", __.order().by((a, b) -> ((Integer) a).compareTo((Integer) b)), false},
{"order(local).by((a,b)->a.compareTo(b))", __.order(Scope.local).by((a, b) -> ((Integer) a).compareTo((Integer) b)), false},
{"__.choose(v->v.toString().equals(\"marko\"),__.out(),__.in())", __.choose(v -> v.toString().equals("marko"), __.out(), __.in()), false},
{"order(local).by(values,decr)", __.order(Scope.local).by(Column.values, (a, b) -> ((Double) a).compareTo((Double) b)), false},
//
{"order(local).by(values,decr)", __.order(Scope.local).by(Column.values, Order.decr), true},
{"order().by(label,decr)", __.order().by(T.label, Order.decr), true},
{"groupCount().by(label)", __.groupCount().by(T.label), true},
});
}
示例2: apply
import org.apache.tinkerpop.gremlin.process.traversal.Order; //导入依赖的package包/类
@Override
public void apply(Traversal.Admin<?, ?> traversal) {
TraversalHelper.getStepsOfAssignableClass(OrderGlobalStep.class, traversal).forEach(orderGlobalStep -> {
List<Pair<Traversal.Admin, Comparator>> comparators = orderGlobalStep.getComparators();
List<Pair<String, Order>> collect = comparators.stream()
.filter(pair -> pair.getValue0() instanceof ElementValueTraversal)
.filter(pair -> pair.getValue1() instanceof Order)
.map(pair -> Pair.with(((ElementValueTraversal) pair.getValue0()).getPropertyKey(),
((Order) pair.getValue1())))
.collect(Collectors.toList());
Collection<Orderable> orderableStepOf = getOrderableStepOf(orderGlobalStep, traversal);
if (orderableStepOf != null && orderableStepOf.size() == 1) {
Orderable step = orderableStepOf.iterator().next();
step.setOrders(collect);
Step nextStep = orderGlobalStep.getNextStep();
if (nextStep instanceof RangeGlobalStep){
if (step instanceof ReceivesPredicatesHolder) {
RangeGlobalStep rangeGlobalStep = (RangeGlobalStep) nextStep;
int limit = rangeGlobalStep.getHighRange() > Integer.MAX_VALUE ? -1 : (int) rangeGlobalStep.getHighRange();
((ReceivesPredicatesHolder) step).setLimit(limit);
}
}
}
});
}
示例3: getSearch
import org.apache.tinkerpop.gremlin.process.traversal.Order; //导入依赖的package包/类
@Override
public Select getSearch(SearchQuery<E> query, PredicatesHolder predicatesHolder) {
if (predicatesHolder.isAborted()) {
return null;
}
Condition conditions = new JdbcPredicatesTranslator().translate(predicatesHolder);
int finalLimit = query.getLimit() < 0 ? Integer.MAX_VALUE : query.getLimit();
SelectConditionStep<Record> where = createSqlQuery(query.getPropertyKeys())
.where(conditions);
List<Pair<String, Order>> orders = query.getOrders();
if (orders != null){
List<SortField<Object>> orderValues = orders.stream().filter(order -> !order.getValue1().equals(Order.shuffle))
.filter(order -> getFieldByPropertyKey(order.getValue0()) != null)
.map(order -> order.getValue1().equals(Order.incr) ?
field(getFieldByPropertyKey(order.getValue0())).asc() :
field(getFieldByPropertyKey(order.getValue0())).desc()).collect(Collectors.toList());
if (orderValues.size() > 0)
return where.orderBy(orderValues).limit(finalLimit);
}
return where.limit(finalLimit);
}
示例4: testSimple
import org.apache.tinkerpop.gremlin.process.traversal.Order; //导入依赖的package包/类
@Test
public void testSimple() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "order", 1);
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "order", 1);
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "order", 2);
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "order", 3);
a1.addEdge("ab", b1);
a1.addEdge("ab", b2);
a1.addEdge("ab", b3);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal()
.V().hasLabel("A")
.out()
.order().by("order", Order.decr);
Assert.assertEquals(4, traversal.getSteps().size());
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(1, traversal.getSteps().size());
assertStep(traversal.getSteps().get(0), true, false, false, false);
Assert.assertEquals(3, vertices.size());
Assert.assertEquals(b3, vertices.get(0));
Assert.assertEquals(b2, vertices.get(1));
Assert.assertEquals(b1, vertices.get(2));
}
示例5: testSelectBeforeOrder
import org.apache.tinkerpop.gremlin.process.traversal.Order; //导入依赖的package包/类
@Test
public void testSelectBeforeOrder() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2");
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "name", "b3");
a1.addEdge("ab", b1, "weight", 3);
a1.addEdge("ab", b2, "weight", 2);
a1.addEdge("ab", b3, "weight", 1);
this.sqlgGraph.tx().commit();
List<String> names = this.sqlgGraph.traversal()
.V()
.outE().as("e")
.inV().as("v")
.select("e")
.order().by("weight", Order.incr)
.select("v")
.<String>values("name")
.dedup()
.toList();
Assert.assertEquals(3, names.size());
Assert.assertEquals("b3", names.get(0));
Assert.assertEquals("b2", names.get(1));
Assert.assertEquals("b1", names.get(2));
}
示例6: testOrderByWithLambdaTraversal
import org.apache.tinkerpop.gremlin.process.traversal.Order; //导入依赖的package包/类
@Test
public void testOrderByWithLambdaTraversal() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "age", 1, "name", "name1");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "age", 5, "name", "name2");
Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "age", 10, "name", "name3");
Vertex a4 = this.sqlgGraph.addVertex(T.label, "A", "age", 15, "name", "name4");
this.sqlgGraph.tx().commit();
List<String> names = this.sqlgGraph.traversal()
.V().hasLabel("A")
.order()
.<Vertex>by(v -> v.value("age"), Order.decr)
.<String>values("name")
.toList();
Assert.assertEquals(4, names.size());
Assert.assertEquals("name4", names.get(0));
Assert.assertEquals("name1", names.get(3));
}
示例7: testOrderByWithByTraversalCount
import org.apache.tinkerpop.gremlin.process.traversal.Order; //导入依赖的package包/类
@Test
public void testOrderByWithByTraversalCount() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2");
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "name", "b3");
a1.addEdge("ab", b1);
a1.addEdge("ab", b2);
a1.addEdge("ab", b3);
this.sqlgGraph.tx().commit();
List<Vertex> vertices = this.sqlgGraph.traversal().V().order().by(__.outE().count(), Order.incr).toList();
Assert.assertEquals(4, vertices.size());
Assert.assertEquals(a1, vertices.get(3));
vertices = this.sqlgGraph.traversal().V().order().by(__.outE().count(), Order.decr).toList();
Assert.assertEquals(4, vertices.size());
Assert.assertEquals(a1, vertices.get(0));
}
示例8: testOrderByWithShuffleComparator
import org.apache.tinkerpop.gremlin.process.traversal.Order; //导入依赖的package包/类
@Test
public void testOrderByWithShuffleComparator() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2");
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "name", "b3");
a1.addEdge("ab", b1);
a1.addEdge("ab", b2);
a1.addEdge("ab", b3);
this.sqlgGraph.tx().commit();
List<Map<String, Object>> result = this.sqlgGraph.traversal().V().as("a")
.out("ab").as("b")
.order().by(Order.shuffle)
.select("a", "b")
.toList();
Assert.assertEquals(3, result.size());
}
示例9: testOrderByWith2ShuffleComparator
import org.apache.tinkerpop.gremlin.process.traversal.Order; //导入依赖的package包/类
@Test
public void testOrderByWith2ShuffleComparator() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a2");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2");
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "name", "b3");
Vertex b4 = this.sqlgGraph.addVertex(T.label, "B", "name", "b4");
Vertex b5 = this.sqlgGraph.addVertex(T.label, "B", "name", "b5");
Vertex b6 = this.sqlgGraph.addVertex(T.label, "B", "name", "b6");
a1.addEdge("ab", b1);
a1.addEdge("ab", b2);
a1.addEdge("ab", b3);
a2.addEdge("ab", b4);
a2.addEdge("ab", b5);
a2.addEdge("ab", b6);
this.sqlgGraph.tx().commit();
List<Map<String, Object>> result = this.sqlgGraph.traversal().V().as("a")
.order().by("name", Order.decr)
.out("ab").as("b")
.order().by(Order.shuffle)
.select("a", "b")
.toList();
Assert.assertEquals(6, result.size());
}
示例10: testOrderBy_assert
import org.apache.tinkerpop.gremlin.process.traversal.Order; //导入依赖的package包/类
private void testOrderBy_assert(SqlgGraph sqlgGraph, Vertex a1, Vertex a2, Vertex a3, Vertex b1, Vertex b2, Vertex b3) {
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) sqlgGraph.traversal()
.V().hasLabel("A")
.order()
.by("name", Order.incr).by("surname", Order.decr);
Assert.assertEquals(3, traversal.getSteps().size());
List<Vertex> result = traversal.toList();
Assert.assertEquals(1, traversal.getSteps().size());
Assert.assertEquals(6, result.size());
Assert.assertEquals(a3, result.get(0));
Assert.assertEquals(a2, result.get(1));
Assert.assertEquals(a1, result.get(2));
Assert.assertEquals(b3, result.get(3));
Assert.assertEquals(b2, result.get(4));
Assert.assertEquals(b1, result.get(5));
}
示例11: testOrderBy3_assert
import org.apache.tinkerpop.gremlin.process.traversal.Order; //导入依赖的package包/类
private void testOrderBy3_assert(SqlgGraph sqlgGraph) {
DefaultGraphTraversal<Vertex, Map<String, Vertex>> traversal = (DefaultGraphTraversal<Vertex, Map<String, Vertex>>) sqlgGraph.traversal().V()
.hasLabel("A").as("a")
.out("ab").as("b")
.<Vertex>select("a", "b")
.order()
.by(__.select("a").by("name"), Order.incr)
.by(__.select("b").by("name"), Order.decr);
Assert.assertEquals(5, traversal.getSteps().size());
List<Map<String, Vertex>> result = traversal.toList();
Assert.assertEquals(3, traversal.getSteps().size());
Assert.assertEquals(4, result.size());
Map<String, Vertex> map1 = result.get(0);
Map<String, Vertex> map2 = result.get(1);
Map<String, Vertex> map3 = result.get(2);
Map<String, Vertex> map4 = result.get(3);
Assert.assertEquals("aa", map1.get("a").value("name"));
Assert.assertEquals("bb", map1.get("b").value("name"));
Assert.assertEquals("aa", map2.get("a").value("name"));
Assert.assertEquals("ba", map2.get("b").value("name"));
Assert.assertEquals("ab", map3.get("a").value("name"));
Assert.assertEquals("bd", map3.get("b").value("name"));
Assert.assertEquals("ab", map4.get("a").value("name"));
Assert.assertEquals("bc", map4.get("b").value("name"));
}
示例12: testMultipleOrder
import org.apache.tinkerpop.gremlin.process.traversal.Order; //导入依赖的package包/类
@Test
public void testMultipleOrder() {
Vertex a = this.sqlgGraph.addVertex(T.label, "A", "name", "a");
for (int i = 0; i < 2; i++) {
Vertex b = this.sqlgGraph.addVertex(T.label, "B", "name", "b" + i);
a.addEdge("ab", b);
}
this.sqlgGraph.tx().commit();
// last one should win
List<Vertex> vertices = this.sqlgGraph.traversal()
.V().hasLabel("A").as("a")
.out().order().by("name")
.in().order().by("name")
.out().order().by("name", Order.decr)
.toList();
Assert.assertEquals(4, vertices.size());
Assert.assertEquals("b1", vertices.get(0).value("name"));
Assert.assertEquals("b1", vertices.get(1).value("name"));
Assert.assertEquals("b0", vertices.get(2).value("name"));
Assert.assertEquals("b0", vertices.get(3).value("name"));
}
示例13: testComparatorViolations
import org.apache.tinkerpop.gremlin.process.traversal.Order; //导入依赖的package包/类
@Test
public void testComparatorViolations() {
loadGratefulDead();
final Traversal<Vertex, Vertex> traversal = this.sqlgGraph.traversal().V().has("song", "name", "OH BOY").out("followedBy").out("followedBy").order().by("performances").by("songType", Order.decr);
printTraversalForm(traversal);
int counter = 0;
String lastSongType = "a";
int lastPerformances = Integer.MIN_VALUE;
while (traversal.hasNext()) {
final Vertex vertex = traversal.next();
final String currentSongType = vertex.value("songType");
final int currentPerformances = vertex.value("performances");
Assert.assertTrue(currentPerformances == lastPerformances || currentPerformances > lastPerformances);
if (currentPerformances == lastPerformances)
Assert.assertTrue(currentSongType.equals(lastSongType) || currentSongType.compareTo(lastSongType) < 0);
lastSongType = currentSongType;
lastPerformances = currentPerformances;
counter++;
}
Assert.assertEquals(144, counter);
}
示例14: getTraversalReturnsATraversalThatOrdersByStringValue
import org.apache.tinkerpop.gremlin.process.traversal.Order; //导入依赖的package包/类
@Test
public void getTraversalReturnsATraversalThatOrdersByStringValue() {
GraphTraversal<Vertex, Vertex> traversal = newGraph()
.withVertex(v -> v.withTimId("id1").withProperty(PROPERTY, "123"))
.withVertex(v -> v.withTimId("id2").withProperty(PROPERTY, "1234"))
.withVertex(v -> v.withTimId("id3").withProperty(PROPERTY, "254"))
.build()
.traversal()
.V();
Property instance = Property.localProperty().withName(PROPERTY).build();
GraphTraversal<?, ?> orderTraversal = instance.getTraversal();
List<Vertex> vertices = traversal.order().by(orderTraversal, Order.incr).toList();
assertThat(vertices, contains(
likeVertex().withTimId("id1"),
likeVertex().withTimId("id2"),
likeVertex().withTimId("id3")));
}
示例15: getTraversalReturnsATraversalThatLetsTheParserDetermineTheOrder
import org.apache.tinkerpop.gremlin.process.traversal.Order; //导入依赖的package包/类
@Test
public void getTraversalReturnsATraversalThatLetsTheParserDetermineTheOrder() {
GraphTraversal<Vertex, Vertex> traversal = newGraph()
.withVertex(v -> v.withTimId("id1").withProperty(PROPERTY, "123"))
.withVertex(v -> v.withTimId("id2").withProperty(PROPERTY, "1234"))
.withVertex(v -> v.withTimId("id3").withProperty(PROPERTY, "254"))
.build()
.traversal()
.V();
Property instance = Property.localProperty().withName(PROPERTY).withParser(new IntegerParser()).build();
GraphTraversal<?, ?> orderTraversal = instance.getTraversal();
List<Vertex> vertices = traversal.order().by(orderTraversal, Order.incr).toList();
assertThat(vertices, contains(
likeVertex().withTimId("id1"),
likeVertex().withTimId("id3"),
likeVertex().withTimId("id2")));
}