@Override public void write(Kryo kryo, Output output, 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()); } }
public static List<Object> convert(final ConnectiveP<?> predicate, final ConnectiveJanusPredicate connectivePredicate) { final List<Object> toReturn = new ArrayList<>(); for (final P<?> p : predicate.getPredicates()){ if (p instanceof ConnectiveP) { final ConnectiveJanusPredicate subPredicate = instanceConnectiveJanusPredicate(p); toReturn.add(convert((ConnectiveP<?>)p, subPredicate)); connectivePredicate.add(subPredicate); } else { connectivePredicate.add(Converter.convert(p.getBiPredicate())); toReturn.add(p.getValue()); } } return toReturn; } }
public final Object getValue() { return this.predicate.getValue(); }
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); } }
public HasContainer(final String key, final P<?> predicate) { this.key = key; this.predicate = predicate; if (!this.key.equals(T.id.getAccessor())) testingIdString = false; else { // the values should be homogenous if a collection is submitted final Object predicateValue = this.predicate.getValue(); // enforce a homogenous collection of values when testing ids enforceHomogenousCollectionIfPresent(predicateValue); // grab an instance of a value which is either the first item in a homogeneous collection or the value itself final Object valueInstance = this.predicate.getValue() instanceof Collection ? ((Collection) this.predicate.getValue()).isEmpty() ? new Object() : ((Collection) this.predicate.getValue()).toArray()[0] : this.predicate.getValue(); // if the key being evaluated is id then the has() test can evaluate as a toString() representation of the // identifier. this could be done in the test() method but it seems cheaper to do the conversion once in // the constructor. the original value in P is maintained separately this.testingIdString = this.key.equals(T.id.getAccessor()) && valueInstance instanceof String; if (this.testingIdString) this.predicate.setValue(this.predicate.getValue() instanceof Collection ? IteratorUtils.set(IteratorUtils.map(((Collection<Object>) this.predicate.getValue()).iterator(), Object::toString)) : this.predicate.getValue().toString()); } }
protected StringBuilder convertPToString(final P p, final StringBuilder current) { if (p instanceof TextP) return convertTextPToString((TextP) p, current); if (p instanceof ConnectiveP) { final List<P<?>> list = ((ConnectiveP) p).getPredicates(); for (int i = 0; i < list.size(); i++) { convertPToString(list.get(i), current); if (i < list.size() - 1) current.append(p instanceof OrP ? ".or(" : ".and("); } current.append(")"); } else current.append("P.").append(p.getBiPredicate().toString()).append("(").append(convertToString(p.getValue())).append(")"); return current; }
private StringBuilder convertPToString(final P p, final StringBuilder current) { if (p instanceof TextP) return convertTextPToString((TextP) p, current); if (p instanceof ConnectiveP) { final List<P<?>> list = ((ConnectiveP) p).getPredicates(); for (int i = 0; i < list.size(); i++) { convertPToString(list.get(i), current); if (i < list.size() - 1) current.append(p instanceof OrP ? ".or_(" : ".and_("); } current.append(")"); } else current.append(convertStatic("P.")).append(p.getBiPredicate().toString()).append("(").append(convertToString(p.getValue())).append(")"); return current; }
@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()); } }
@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()); } }
private Iterator<? extends Edge> edges() { final TinkerGraph graph = (TinkerGraph) this.getTraversal().getGraph().get(); final HasContainer indexedContainer = getIndexKey(Edge.class); // ids are present, filter on them first if (null == this.ids) return Collections.emptyIterator(); else if (this.ids.length > 0) return this.iteratorList(graph.edges(this.ids)); else return null == indexedContainer ? this.iteratorList(graph.edges()) : TinkerHelper.queryEdgeIndex(graph, indexedContainer.getKey(), indexedContainer.getPredicate().getValue()).stream() .filter(edge -> HasContainer.testAll(edge, this.hasContainers)) .collect(Collectors.<Edge>toList()).iterator(); }
@Override protected ByteBuf writeValue(final T value, final ByteBufAllocator allocator, final GraphBinaryWriter context) throws SerializationException { // 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(); final CompositeByteBuf result = allocator.compositeBuffer(2 + length); result.addComponent(true, context.writeValue(predicateName, allocator, false)); result.addComponent(true, context.writeValue(length, allocator, false)); for (Object o : argsAsList) { result.addComponent(true, context.write(o, allocator)); } return result; } }
private static void convPredicateValue(HugeGraph graph, HasContainer has) { // No need to convert if key is sysprop if (isSysProp(has.getKey())) { return; } PropertyKey pkey = graph.propertyKey(has.getKey()); List<P<Object>> leafPredicates = new ArrayList<>(); collectPredicates(leafPredicates, ImmutableList.of(has.getPredicate())); for (P<Object> predicate : leafPredicates) { Object value = validPredicateValue(predicate.getValue(), pkey); predicate.setValue(value); } }
@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(); }
private Iterator<? extends Vertex> vertices() { final TinkerGraph graph = (TinkerGraph) this.getTraversal().getGraph().get(); final HasContainer indexedContainer = getIndexKey(Vertex.class); // ids are present, filter on them first if (null == this.ids) return Collections.emptyIterator(); else if (this.ids.length > 0) return this.iteratorList(graph.vertices(this.ids)); else return null == indexedContainer ? this.iteratorList(graph.vertices()) : IteratorUtils.filter(TinkerHelper.queryVertexIndex(graph, indexedContainer.getKey(), indexedContainer.getPredicate().getValue()).iterator(), vertex -> HasContainer.testAll(vertex, this.hasContainers)); }
@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(); }
boolean useNotStep = false, dismissCountIs = false; for (P p : isStepPredicate instanceof ConnectiveP ? ((ConnectiveP<?>) isStepPredicate).getPredicates() : Collections.singletonList(isStepPredicate)) { final Object value = p.getValue(); final BiPredicate predicate = p.getBiPredicate(); if (value instanceof Number) {
private static void convPredicateValue(HugeGraph graph, HasContainer has) { // No need to convert if key is sysprop if (isSysProp(has.getKey())) { return; } PropertyKey pkey = graph.propertyKey(has.getKey()); List<P<Object>> leafPredicates = new ArrayList<>(); collectPredicates(leafPredicates, ImmutableList.of(has.getPredicate())); for (P<Object> predicate : leafPredicates) { Object value = validPredicateValue(predicate.getValue(), pkey); predicate.setValue(value); } }