org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP Java Examples

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP. 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: JanusGraphPredicate.java    From grakn with GNU Affero General Public License v3.0 6 votes vote down vote up
public static List<Object> convert(ConnectiveP<?> predicate, ConnectiveJanusPredicate connectivePredicate) {
    final List<Object> toReturn = new ArrayList<>();
    for (P<?> p : predicate.getPredicates()) {
        if (p instanceof ConnectiveP) {
            final ConnectiveJanusPredicate subPredicate = instanceConnectiveJanusPredicate(p);
            toReturn.add(convert((ConnectiveP<?>) p, subPredicate));
            connectivePredicate.add(subPredicate);
        } else if (p.getBiPredicate() instanceof Text) {
            Text text = (Text) p.getBiPredicate();
            connectivePredicate.add(new TinkerPopTextWrappingPredicate(text));
            toReturn.add(p.getValue());
        } else {
            connectivePredicate.add(Converter.convert(p.getBiPredicate()));
            toReturn.add(p.getValue());
        }
    }
    return toReturn;
}
 
Example #2
Source File: GryoSerializersV1d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: GryoSerializersV3d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@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: TraversalSerializersV3d0.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@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 #5
Source File: PSerializer.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@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 #6
Source File: GroovyTranslator.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
protected Script convertPToScript(final P p) {
    if (p instanceof TextP) {
        return convertTextPToScript((TextP) p);
    }
    if (p instanceof ConnectiveP) {
        final List<P<?>> list = ((ConnectiveP) p).getPredicates();
        for (int i = 0; i < list.size(); i++) {
            convertPToScript(list.get(i));
            if (i < list.size() - 1) {
                script.append(p instanceof OrP ? ".or(" : ".and(");
            }
        }
        script.append(")");
    } else {
        script.append("P.").append(p.getBiPredicate().toString()).append("(");
        convertToScript(p.getValue());
        script.append(")");
    }
    return script;
}
 
Example #7
Source File: TraversalUtil.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void collectPredicates(List<P<Object>> results,
                                      List<P<?>> predicates) {
    for (P<?> p : predicates) {
        if (p instanceof ConnectiveP) {
            collectPredicates(results, ((ConnectiveP) p).getPredicates());
        } else {
            results.add((P<Object>) p);
        }
    }
}
 
Example #8
Source File: JanusGraphPredicate.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
public static HasContainer convert(HasContainer container) {
    if (!(container.getPredicate() instanceof ConnectiveP)) {
        return container;
    }
    final ConnectiveJanusPredicate connectivePredicate = instanceConnectiveJanusPredicate(container.getPredicate());
    return new HasContainer(container.getKey(), new ConnectiveJanusGraphP(connectivePredicate, convert(((ConnectiveP<?>) container.getPredicate()), connectivePredicate)));
}
 
Example #9
Source File: HasStepFolder.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
static boolean validJanusGraphHas(HasContainer has) {
    if (has.getPredicate() instanceof ConnectiveP) {
        List<? extends P<?>> predicates = ((ConnectiveP<?>) has.getPredicate()).getPredicates();
        return predicates.stream().allMatch(p -> validJanusGraphHas(new HasContainer(has.getKey(), p)));
    } else {
        return JanusGraphPredicate.Converter.supports(has.getBiPredicate());
    }
}
 
Example #10
Source File: GryoClassResolverV1d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Class coerceType(final Class clazz) {
    // force all instances of Vertex, Edge, VertexProperty, etc. to their respective interface
    final Class type;
    if (!ReferenceVertex.class.isAssignableFrom(clazz) && !DetachedVertex.class.isAssignableFrom(clazz) && Vertex.class.isAssignableFrom(clazz))
        type = Vertex.class;
    else if (!ReferenceEdge.class.isAssignableFrom(clazz) && !DetachedEdge.class.isAssignableFrom(clazz) && Edge.class.isAssignableFrom(clazz))
        type = Edge.class;
    else if (!ReferenceVertexProperty.class.isAssignableFrom(clazz) && !DetachedVertexProperty.class.isAssignableFrom(clazz) && VertexProperty.class.isAssignableFrom(clazz))
        type = VertexProperty.class;
    else if (!ReferenceProperty.class.isAssignableFrom(clazz) && !DetachedProperty.class.isAssignableFrom(clazz) && !DetachedVertexProperty.class.isAssignableFrom(clazz) && !ReferenceVertexProperty.class.isAssignableFrom(clazz) && Property.class.isAssignableFrom(clazz))
        type = Property.class;
    else if (!ReferencePath.class.isAssignableFrom(clazz) && !DetachedPath.class.isAssignableFrom(clazz) && Path.class.isAssignableFrom(clazz))
        type = Path.class;
    else if (Lambda.class.isAssignableFrom(clazz))
        type = Lambda.class;
    else if (ByteBuffer.class.isAssignableFrom(clazz))
        type = ByteBuffer.class;
    else if (Class.class.isAssignableFrom(clazz))
        type = Class.class;
    else if (InetAddress.class.isAssignableFrom(clazz))
        type = InetAddress.class;
    else if (ConnectiveP.class.isAssignableFrom(clazz))
        type = P.class;
    else
        type = clazz;

    return type;
}
 
Example #11
Source File: GryoClassResolverV3d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public Class coerceType(final Class clazz) {
    // force all instances of Vertex, Edge, VertexProperty, etc. to their respective interface
    final Class type;
    if (!ReferenceVertex.class.isAssignableFrom(clazz) && !DetachedVertex.class.isAssignableFrom(clazz) && Vertex.class.isAssignableFrom(clazz))
        type = Vertex.class;
    else if (!ReferenceEdge.class.isAssignableFrom(clazz) && !DetachedEdge.class.isAssignableFrom(clazz) && Edge.class.isAssignableFrom(clazz))
        type = Edge.class;
    else if (!ReferenceVertexProperty.class.isAssignableFrom(clazz) && !DetachedVertexProperty.class.isAssignableFrom(clazz) && VertexProperty.class.isAssignableFrom(clazz))
        type = VertexProperty.class;
    else if (!ReferenceProperty.class.isAssignableFrom(clazz) && !DetachedProperty.class.isAssignableFrom(clazz) && !DetachedVertexProperty.class.isAssignableFrom(clazz) && !ReferenceVertexProperty.class.isAssignableFrom(clazz) && Property.class.isAssignableFrom(clazz))
        type = Property.class;
    else if (!ReferencePath.class.isAssignableFrom(clazz) && !DetachedPath.class.isAssignableFrom(clazz) && Path.class.isAssignableFrom(clazz))
        type = Path.class;
    else if (Lambda.class.isAssignableFrom(clazz))
        type = Lambda.class;
    else if (ByteBuffer.class.isAssignableFrom(clazz))
        type = ByteBuffer.class;
    else if (Class.class.isAssignableFrom(clazz))
        type = Class.class;
    else if (InetAddress.class.isAssignableFrom(clazz))
        type = InetAddress.class;
    else if (ConnectiveP.class.isAssignableFrom(clazz))
        type = P.class;
    else if (Metrics.class.isAssignableFrom(clazz))
        type = Metrics.class;
    else if (TraversalMetrics.class.isAssignableFrom(clazz))
        type = TraversalMetrics.class;
    else
        type = clazz;

    return type;
}
 
Example #12
Source File: TraversalSerializersV2d0.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@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 #13
Source File: WherePredicateStep.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private void configurePredicates(final P<Object> predicate) {
    if (predicate instanceof ConnectiveP)
        ((ConnectiveP<Object>) predicate).getPredicates().forEach(this::configurePredicates);
    else {
        final String selectKey = (String) (predicate.getValue() instanceof Collection ? ((Collection) predicate.getValue()).iterator().next() : predicate.getValue()); // hack for within("x"))
        this.selectKeys.add(selectKey);
        this.scopeKeys.add(selectKey);
    }
}
 
Example #14
Source File: WherePredicateStep.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
private void setPredicateValues(final P<Object> predicate, final Traverser.Admin<S> traverser, final Iterator<String> selectKeysIterator) {
    if (predicate instanceof ConnectiveP)
        ((ConnectiveP<Object>) predicate).getPredicates().forEach(p -> this.setPredicateValues(p, traverser, selectKeysIterator));
    else
        predicate.setValue(TraversalUtil.applyNullable((S) this.getSafeScopeValue(Pop.last, selectKeysIterator.next(), traverser), this.traversalRing.next()));
}