return P.outside(((List) value).get(0), ((List) value).get(1)); case "within": return P.within((Collection) value); case "without": return P.without((Collection) value);
/** * Determines if a value is within the specified list of values. * * @since 3.0.0-incubating */ public static <V> P<V> within(final V... values) { return P.within(Arrays.asList(values)); }
/** * Finds users by name. */ public default GraphTraversal<S, Vertex> users(final String username, final String... more) { if (more.length == 0) { return (CredentialTraversal<S, Vertex>) has(VERTEX_LABEL_USER, PROPERTY_USERNAME, username); } final int lastIndex; final String[] usernames = Arrays.copyOf(more, (lastIndex = more.length) + 1); usernames[lastIndex] = username; return (CredentialTraversal<S, Vertex>)has(VERTEX_LABEL_USER, PROPERTY_USERNAME, P.within(usernames)); }
@Override public Traversal<Vertex, Long> get_g_V_hasIdXwithinXemptyXX_count() { return g.V().hasId(P.within(Collections.emptyList())).count(); }
@Override public Traversal<Vertex, Long> get_g_V_notXhasIdXwithinXemptyXXX_count() { return g.V().not(__.hasId(P.within(Collections.emptyList()))).count(); }
@Override public Traversal<Vertex, Long> get_g_V_hasXage_withinX27_29X_count() { return g.V().has("age", P.within(27, 29)).count(); }
@Override public Traversal<Vertex, Long> get_g_V_hasXage_withinX27X_count() { return g.V().has("age", P.within(27)).count(); }
return P.outside(((List) value).get(0), ((List) value).get(1)); else if (predicate.equals("within")) return P.within((Collection) value); else if (predicate.equals("without")) return P.without((Collection) value);
/** * Filters vertices, edges and vertex properties based on their value. * * @param value the value of the {@link Element} * @param otherValues additional values of the {@link Element} * @return the traversal with an appended {@link HasStep} * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#has-step" target="_blank">Reference Documentation - Has Step</a> */ public default GraphTraversal<S, E> hasValue(final Object value, final Object... otherValues) { if (value instanceof P) return this.hasValue((P) value); else { final List<Object> values = new ArrayList<>(); if (value instanceof Object[]) { Collections.addAll(values, (Object[]) value); } else values.add(value); for (final Object v : otherValues) { if (v instanceof Object[]) { Collections.addAll(values, (Object[]) v); } else values.add(v); } this.asAdmin().getBytecode().addStep(Symbols.hasValue, values.toArray()); return TraversalHelper.addHasContainer(this.asAdmin(), new HasContainer(T.value.getAccessor(), values.size() == 1 ? P.eq(values.get(0)) : P.within(values))); } }
/** * Finds users by name. */ public GraphTraversal<Vertex, Vertex> users(final String username, final String... more) { if (more.length == 0) { return this.clone().V().has(VERTEX_LABEL_USER, PROPERTY_USERNAME, username); } final int lastIndex; final String[] usernames = Arrays.copyOf(more, (lastIndex = more.length) + 1); usernames[lastIndex] = username; return this.clone().V().has(VERTEX_LABEL_USER, PROPERTY_USERNAME, P.within(usernames)); }
@Override public Traversal<Vertex, String> get_g_withSideEffectXa_josh_peterX_VX1X_outXcreatedX_inXcreatedX_name_whereXwithinXaXX(final Object v1Id) { return g.withSideEffect("a", Arrays.asList("josh", "peter")).V(v1Id).out("created").in("created").<String>values("name").where(P.within("a")); }
@Override public Traversal<Vertex, Vertex> get_g_VX1X_out_aggregateXxX_out_whereXnotXwithinXaXXX(final Object v1Id) { return g.V(v1Id).out().aggregate("x").out().where(not(within("x"))); }
/** * Filters vertices, edges and vertex properties based on their label. * * @param label the label of the {@link Element} * @param otherLabels additional labels of the {@link Element} * @return the traversal with an appended {@link HasStep} * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#has-step" target="_blank">Reference Documentation - Has Step</a> * @since 3.2.2 */ public default GraphTraversal<S, E> hasLabel(final String label, final String... otherLabels) { final String[] labels = new String[otherLabels.length + 1]; labels[0] = label; System.arraycopy(otherLabels, 0, labels, 1, otherLabels.length); this.asAdmin().getBytecode().addStep(Symbols.hasLabel, labels); return TraversalHelper.addHasContainer(this.asAdmin(), new HasContainer(T.label.getAccessor(), labels.length == 1 ? P.eq(labels[0]) : P.within(labels))); }
/** * Filters vertices, edges and vertex properties based on their key. * * @param label the key of the {@link Element} * @param otherLabels additional key of the {@link Element} * @return the traversal with an appended {@link HasStep} * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#has-step" target="_blank">Reference Documentation - Has Step</a> * @since 3.2.2 */ public default GraphTraversal<S, E> hasKey(final String label, final String... otherLabels) { final String[] labels = new String[otherLabels.length + 1]; labels[0] = label; System.arraycopy(otherLabels, 0, labels, 1, otherLabels.length); this.asAdmin().getBytecode().addStep(Symbols.hasKey, labels); return TraversalHelper.addHasContainer(this.asAdmin(), new HasContainer(T.key.getAccessor(), labels.length == 1 ? P.eq(labels[0]) : P.within(labels))); }
((HasContainerHolder) graphStep).addHasContainer(new HasContainer(this.idPropertyKey, P.within(Arrays.asList(graphStep.getIds())))); else TraversalHelper.insertAfterStep(new HasStep(traversal, new HasContainer(this.idPropertyKey, P.within(Arrays.asList(graphStep.getIds())))), graphStep, traversal); graphStep.clearIds();
@Test public void testQueryVerticesByIdsWithHasIdFilterAndNumberId() { HugeGraph graph = graph(); SchemaManager schema = graph.schema(); schema.vertexLabel("user").useCustomizeNumberId().create(); graph.addVertex(T.label, "user", T.id, 123); graph.addVertex(T.label, "user", T.id, 456); graph.addVertex(T.label, "user", T.id, 789); graph.tx().commit(); GraphTraversalSource g = graph.traversal(); List<Vertex> vertices; vertices = g.V().hasId(P.within(123)).toList(); Assert.assertEquals(1, vertices.size()); vertices = g.V(123, 456).hasId(P.within(123)).toList(); Assert.assertEquals(1, vertices.size()); vertices = g.V(123, 456).hasId(123).toList(); Assert.assertEquals(1, vertices.size()); vertices = g.V(123, 456, 789).hasId(P.within(123, 456)).toList(); Assert.assertEquals(2, vertices.size()); vertices = g.V(123, 456, 789).hasId(456, 789).toList(); Assert.assertEquals(2, vertices.size()); vertices = g.V(123, 456, 789).hasId(P.within(123, 456, 789)).toList(); Assert.assertEquals(3, vertices.size()); }
@Test(expected = NoSuchElementException.class) @LoadGraphWith(MODERN) public void shouldGetExcludedVertex() throws Exception { final Traversal<Vertex, ?> vertexCriterion = has("name", P.within("josh", "lop", "ripple")); final GraphTraversalSource sg = g.withStrategies(SubgraphStrategy.build().vertices(vertexCriterion).create()); sg.V(convertToVertexId("marko")).next(); }
@Test @LoadGraphWith(MODERN) public void shouldFilterVertexCriterionAndKeepLabels() throws Exception { // this will exclude "peter" final Traversal<Vertex, ?> vertexCriterion = has("name", P.within("ripple", "josh", "marko")); final GraphTraversalSource sg = g.withStrategies(SubgraphStrategy.build().vertices(vertexCriterion).create()); assertEquals(9, g.V().as("a").out().in().as("b").dedup("a", "b").count().next().intValue()); assertEquals(2, sg.V().as("a").out().in().as("b").dedup("a", "b").count().next().intValue()); final List<Object> list = sg.V().as("a").out().in().as("b").dedup("a", "b").values("name").toList(); assertThat(list, hasItems("marko", "josh")); }
@Override public Traversal<Vertex, String> getClassicRecommendation() { return g.V().has("name", "DARK STAR").as("a").out("followedBy").aggregate("stash"). in("followedBy").where(neq("a").and(P.not(P.within("stash")))). groupCount(). unfold(). project("x", "y", "z"). by(select(keys).values("name")). by(select(keys).values("performances")). by(select(values)). order(). by(select("z"), Order.desc). by(select("y"), Order.asc). limit(5).store("m").select("x"); }
SubgraphStrategy strategy; strategy = SubgraphStrategy.build().vertices(has("name", P.within("josh", "lop", "ripple"))).create(); sg = g.withStrategies(strategy);