org.apache.tinkerpop.gremlin.process.traversal.util.AndP Java Examples
The following examples show how to use
org.apache.tinkerpop.gremlin.process.traversal.util.AndP.
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: PSerializer.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override protected void writeValue(final T value, final Buffer buffer, final GraphBinaryWriter context) throws IOException { // the predicate name is either a static method of P or an instance method when a type ConnectiveP final boolean isConnectedP = value instanceof ConnectiveP; final String predicateName = isConnectedP ? (value instanceof AndP ? "and" : "or") : value.getBiPredicate().toString(); final Object args = isConnectedP ? ((ConnectiveP<?>) value).getPredicates() : value.getValue(); final List<Object> argsAsList = args instanceof Collection ? new ArrayList<>((Collection) args) : Collections.singletonList(args); final int length = argsAsList.size(); context.writeValue(predicateName, buffer, false); context.writeValue(length, buffer, false); for (Object o : argsAsList) { context.write(o, buffer); } }
Example #2
Source File: TraversalSerializersV3d0.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public void serialize(final P p, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField(GraphSONTokens.PREDICATE, p instanceof ConnectiveP ? p instanceof AndP ? GraphSONTokens.AND : GraphSONTokens.OR : p.getBiPredicate().toString()); if (p instanceof ConnectiveP) { jsonGenerator.writeArrayFieldStart(GraphSONTokens.VALUE); for (final P<?> predicate : ((ConnectiveP<?>) p).getPredicates()) { jsonGenerator.writeObject(predicate); } jsonGenerator.writeEndArray(); } else jsonGenerator.writeObjectField(GraphSONTokens.VALUE, p.getValue()); jsonGenerator.writeEndObject(); }
Example #3
Source File: GryoSerializersV1d0.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final O output, final P p) { output.writeString(p instanceof ConnectiveP ? (p instanceof AndP ? "and" : "or") : p.getBiPredicate().toString()); if (p instanceof ConnectiveP || p.getValue() instanceof Collection) { output.writeByte((byte) 0); final Collection<?> coll = p instanceof ConnectiveP ? ((ConnectiveP<?>) p).getPredicates() : (Collection) p.getValue(); output.writeInt(coll.size()); coll.forEach(v -> kryo.writeClassAndObject(output, v)); } else { output.writeByte((byte) 1); kryo.writeClassAndObject(output, p.getValue()); } }
Example #4
Source File: GryoSerializersV3d0.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public <O extends OutputShim> void write(final KryoShim<?, O> kryo, final O output, final P p) { output.writeString(p instanceof ConnectiveP ? (p instanceof AndP ? "and" : "or") : p.getBiPredicate().toString()); if (p instanceof ConnectiveP || p.getValue() instanceof Collection) { output.writeByte((byte) 0); final Collection<?> coll = p instanceof ConnectiveP ? ((ConnectiveP<?>) p).getPredicates() : (Collection) p.getValue(); output.writeInt(coll.size()); coll.forEach(v -> kryo.writeClassAndObject(output, v)); } else { output.writeByte((byte) 1); kryo.writeClassAndObject(output, p.getValue()); } }
Example #5
Source File: TraversalUtil.java From hugegraph with Apache License 2.0 | 6 votes |
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 #6
Source File: TraversalSerializersV2d0.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public void serialize(final P p, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField(GraphSONTokens.PREDICATE, p instanceof ConnectiveP ? p instanceof AndP ? GraphSONTokens.AND : GraphSONTokens.OR : p.getBiPredicate().toString()); if (p instanceof ConnectiveP) { jsonGenerator.writeArrayFieldStart(GraphSONTokens.VALUE); for (final P<?> predicate : ((ConnectiveP<?>) p).getPredicates()) { jsonGenerator.writeObject(predicate); } jsonGenerator.writeEndArray(); } else { if (p.getValue() instanceof Collection) { jsonGenerator.writeArrayFieldStart(GraphSONTokens.VALUE); for (final Object object : (Collection) p.getValue()) { jsonGenerator.writeObject(object); } jsonGenerator.writeEndArray(); } else jsonGenerator.writeObjectField(GraphSONTokens.VALUE, p.getValue()); } jsonGenerator.writeEndObject(); }
Example #7
Source File: Neo4jGraphStep.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public void addHasContainer(final HasContainer hasContainer) { if (hasContainer.getPredicate() instanceof AndP) { for (final P<?> predicate : ((AndP<?>) hasContainer.getPredicate()).getPredicates()) { this.addHasContainer(new HasContainer(hasContainer.getKey(), predicate)); } } else this.hasContainers.add(hasContainer); }
Example #8
Source File: TinkerGraphStep.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public void addHasContainer(final HasContainer hasContainer) { if (hasContainer.getPredicate() instanceof AndP) { for (final P<?> predicate : ((AndP<?>) hasContainer.getPredicate()).getPredicates()) { this.addHasContainer(new HasContainer(hasContainer.getKey(), predicate)); } } else this.hasContainers.add(hasContainer); }
Example #9
Source File: PTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void shouldComposeCorrectly() { assertEquals(P.eq(1), P.eq(1)); assertEquals(P.eq(1).and(P.eq(2)), new AndP<>(Arrays.asList(P.eq(1), P.eq(2)))); assertEquals(P.eq(1).and(P.eq(2).and(P.eq(3))), new AndP<>(Arrays.asList(P.eq(1), P.eq(2), P.eq(3)))); assertEquals(P.eq(1).and(P.eq(2).and(P.eq(3).and(P.eq(4)))), new AndP<>(Arrays.asList(P.eq(1), P.eq(2), P.eq(3), P.eq(4)))); assertEquals(P.eq(1).or(P.eq(2).or(P.eq(3).or(P.eq(4)))), new OrP<>(Arrays.asList(P.eq(1), P.eq(2), P.eq(3), P.eq(4)))); assertEquals(P.eq(1).or(P.eq(2).and(P.eq(3).or(P.eq(4)))), new OrP<>(Arrays.asList(P.eq(1), new AndP<>(Arrays.asList(P.eq(2), new OrP<>(Arrays.asList(P.eq(3), P.eq(4)))))))); assertEquals(P.eq(1).and(P.eq(2).or(P.eq(3).and(P.eq(4)))), new AndP<>(Arrays.asList(P.eq(1), new OrP<>(Arrays.asList(P.eq(2), new AndP<>(Arrays.asList(P.eq(3), P.eq(4)))))))); assertEquals(P.eq(1).and(P.eq(2).and(P.eq(3).or(P.eq(4)))), new AndP<>(Arrays.asList(P.eq(1), P.eq(2), new OrP<>(Arrays.asList(P.eq(3), P.eq(4)))))); }
Example #10
Source File: HBaseGraphStep.java From hgraphdb with Apache License 2.0 | 5 votes |
@Override public void addHasContainer(final HasContainer hasContainer) { if (hasContainer.getPredicate() instanceof AndP) { for (final P<?> predicate : ((AndP<?>) hasContainer.getPredicate()).getPredicates()) { this.addHasContainer(new HasContainer(hasContainer.getKey(), predicate)); } } else this.hasContainers.add(hasContainer); }
Example #11
Source File: HasStepFolder.java From grakn with GNU Affero General Public License v3.0 | 5 votes |
static List<HasContainer> splitAndP(List<HasContainer> hasContainers, Iterable<HasContainer> has) { has.forEach(hasContainer -> { if (hasContainer.getPredicate() instanceof AndP) { for (P<?> predicate : ((AndP<?>) hasContainer.getPredicate()).getPredicates()) { hasContainers.add(new HasContainer(hasContainer.getKey(), predicate)); } } else { hasContainers.add(hasContainer); } }); return hasContainers; }
Example #12
Source File: JanusGraphPredicate.java From grakn with GNU Affero General Public License v3.0 | 5 votes |
public static ConnectiveJanusPredicate instanceConnectiveJanusPredicate(P<?> predicate) { final ConnectiveJanusPredicate connectivePredicate; if (predicate.getClass().isAssignableFrom(AndP.class)) { connectivePredicate = new AndJanusPredicate(); } else if (predicate.getClass().isAssignableFrom(OrP.class)) { connectivePredicate = new OrJanusPredicate(); } else { throw new IllegalArgumentException("JanusGraph does not support the given predicate: " + predicate); } return connectivePredicate; }
Example #13
Source File: BitsyGraphStep.java From bitsy with Apache License 2.0 | 5 votes |
@Override public void addHasContainer(final HasContainer hasContainer) { if (hasContainer.getPredicate() instanceof AndP) { for (final P<?> predicate : ((AndP<?>) hasContainer.getPredicate()).getPredicates()) { this.addHasContainer(new HasContainer(hasContainer.getKey(), predicate)); } } else this.hasContainers.add(hasContainer); }
Example #14
Source File: TinkerGraphStep.java From tinkergraph-gremlin with Apache License 2.0 | 5 votes |
@Override public void addHasContainer(final HasContainer hasContainer) { if (hasContainer.getPredicate() instanceof AndP) { for (final P<?> predicate : ((AndP<?>) hasContainer.getPredicate()).getPredicates()) { this.addHasContainer(new HasContainer(hasContainer.getKey(), predicate)); } } else this.hasContainers.add(hasContainer); }
Example #15
Source File: P.java From tinkerpop with Apache License 2.0 | 4 votes |
@Override public P<V> and(final Predicate<? super V> predicate) { if (!(predicate instanceof P)) throw new IllegalArgumentException("Only P predicates can be and'd together"); return new AndP<>(Arrays.asList(this, (P<V>) predicate)); }
Example #16
Source File: P.java From tinkerpop with Apache License 2.0 | 2 votes |
/** * Determines if a value is within (exclusive) the range of the two specified values. * * @since 3.0.0-incubating */ public static <V> P<V> inside(final V first, final V second) { return new AndP<V>(Arrays.asList(new P(Compare.gt, first), new P(Compare.lt, second))); }
Example #17
Source File: P.java From tinkerpop with Apache License 2.0 | 2 votes |
/** * Determines if a value is within (inclusive) of the range of the two specified values. * * @since 3.0.0-incubating */ public static <V> P<V> between(final V first, final V second) { return new AndP<V>(Arrays.asList(new P(Compare.gte, first), new P(Compare.lt, second))); }