Refine search
/** * 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))); }
private static char isLocalStarGraph(final Traversal.Admin<?, ?> traversal, char state) { if (state == 'u' && (traversal instanceof ElementValueTraversal || (traversal instanceof TokenTraversal && !((TokenTraversal) traversal).getToken().equals(T.id)))) return 'x'; for (final Step step : traversal.getSteps()) { } else if (step instanceof HasContainerHolder && state == 'u') { for (final HasContainer hasContainer : ((HasContainerHolder) step).getHasContainers()) { if (!hasContainer.getKey().equals(T.id.getAccessor())) return 'x';
@Override public void addStart(final Traverser.Admin<S> start) { this.e = (E) this.t.apply(start.get()); }
/** * Filters vertices, edges and vertex properties based on their properties. * * @param label the label of the {@link Element} * @param propertyKey the key of the property to filter on * @param value the value to compare the accessor value to for equality * @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.0.0-incubating */ public default GraphTraversal<S, E> has(final String label, final String propertyKey, final Object value) { this.asAdmin().getBytecode().addStep(Symbols.has, label, propertyKey, value); TraversalHelper.addHasContainer(this.asAdmin(), new HasContainer(T.label.getAccessor(), P.eq(label))); return TraversalHelper.addHasContainer(this.asAdmin(), new HasContainer(propertyKey, value instanceof P ? (P) value : P.eq(value))); }
final List<String> edgeLabels = new ArrayList<>(); for (final HasContainer hasContainer : new ArrayList<>(step.getHasContainers())) { if (hasContainer.getKey().equals(T.label.getAccessor())) { if (hasContainer.getBiPredicate() == Compare.eq && hasContainer.getValue() instanceof String && edgeLabels.isEmpty()) { edgeLabels.add((String) hasContainer.getValue()); final List<String> newEdges = new ArrayList<>(); for (int i = 0; i < orps.size(); i++) { if (orps.get(i).getBiPredicate() == Compare.eq && orps.get(i).getValue() instanceof String) newEdges.add((String) orps.get(i).getValue()); else { removeContainer = false;
@Override public Iterator<Edge> edges(Object[] edgeIds) { Predicates predicates = new Predicates(); predicates.hasContainers.add(new HasContainer(T.id.getAccessor(), P.within(edgeIds))); return edges(predicates); }
return IteratorUtils.filter(graph.vertices(ids), vertex -> HasContainer.testAll(vertex, hasContainers)); .filter(hasContainer -> hasContainer.getKey().equals(T.label.getAccessor())) .filter(hasContainer -> Compare.eq == hasContainer.getBiPredicate()) .map(hasContainer -> (String) hasContainer.getValue()) .findAny(); if (!label.isPresent()) label = hasContainers.stream() .filter(hasContainer -> hasContainer.getKey().equals(T.label.getAccessor())) .filter(hasContainer -> hasContainer.getPredicate() instanceof LabelP) .map(hasContainer -> (String) hasContainer.getValue()) if (Compare.eq == hasContainer.getBiPredicate() && !hasContainer.getKey().equals(T.label.getAccessor())) { if (graph.getBaseGraph().hasSchemaIndex(label.get(), hasContainer.getKey())) { return IteratorUtils.stream(graph.getBaseGraph().findNodes(label.get(), hasContainer.getKey(), hasContainer.getValue()))
/** * Helper method for providers that want to "fold in" {@link HasContainer}'s based on id checking into the ids of the {@link GraphStep}. * * @param graphStep the GraphStep to potentially {@link GraphStep#addIds(Object...)}. * @param hasContainer The {@link HasContainer} to check for id validation. * @return true if the {@link HasContainer} updated ids and thus, was processed. */ public static boolean processHasContainerIds(final GraphStep<?, ?> graphStep, final HasContainer hasContainer) { if (hasContainer.getKey().equals(T.id.getAccessor()) && graphStep.ids.length == 0 && (hasContainer.getBiPredicate() == Compare.eq || hasContainer.getBiPredicate() == Contains.within)) { graphStep.addIds(hasContainer.getValue()); return true; } return false; } }
@Override public void apply(final Traversal.Admin<?, ?> traversal) { TraversalHelper.getStepsOfAssignableClass(HasStep.class, traversal).stream() .filter(hasStep -> ((HasStep<?>) hasStep).getHasContainers().get(0).getKey().equals(T.id.getAccessor())) .forEach(hasStep -> ((HasStep<?>) hasStep).getHasContainers().get(0).setKey(this.idPropertyKey)); ((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();
/** * Filters vertices, edges and vertex properties based on their label. * * @param predicate the filter to apply to the label 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.4 */ public default GraphTraversal<S, E> hasLabel(final P<String> predicate) { this.asAdmin().getBytecode().addStep(Symbols.hasLabel, predicate); return TraversalHelper.addHasContainer(this.asAdmin(), new HasContainer(T.label.getAccessor(), predicate)); }
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()); } }
public static boolean keyForContainsKeyOrValue(String key) { return key.equals(T.key.getAccessor()) || key.equals(T.value.getAccessor()); }
private void addIdHasContainers(SchemaTableTree schemaTableTree1, List<Multimap<BiPredicate, RecordId>> biPredicateRecordIds) { if (biPredicateRecordIds != null) { for (Multimap<BiPredicate, RecordId> biPredicateRecordId : biPredicateRecordIds) { for (BiPredicate biPredicate : biPredicateRecordId.keySet()) { Collection<RecordId> recordIds = biPredicateRecordId.get(biPredicate); HasContainer idHasContainer; //id hasContainers are only optimized for BaseStrategy.SUPPORTED_ID_BI_PREDICATE within, without, eq, neq if (biPredicate == Contains.without || biPredicate == Contains.within) { idHasContainer = new HasContainer(T.id.getAccessor(), P.test(biPredicate, recordIds)); schemaTableTree1.getHasContainers().add(idHasContainer); } else { Preconditions.checkState(biPredicate == Compare.eq || biPredicate == Compare.neq); for (RecordId recordId : recordIds) { idHasContainer = new HasContainer(T.id.getAccessor(), P.test(biPredicate, recordId)); schemaTableTree1.getHasContainers().add(idHasContainer); } } } } } }
public final boolean test(final Element element) { // it is OK to evaluate equality of ids via toString(), given that the test suite enforces the value of // id().toString() to be a first class representation of the identifier. a string test is only executed // if the predicate value is a String. this allows stuff like: g.V().has(id,lt(10)) to work properly if (this.key.equals(T.id.getAccessor())) return testingIdString ? testIdAsString(element) : testId(element); else if (this.key.equals(T.label.getAccessor())) return testLabel(element); else if (element instanceof VertexProperty && this.key.equals(T.value.getAccessor())) return testValue((VertexProperty) element); else if (element instanceof VertexProperty && this.key.equals(T.key.getAccessor())) return testKey((VertexProperty) element); else { if (element instanceof Vertex) { final Iterator<? extends Property> itty = element.properties(this.key); while (itty.hasNext()) { if (testValue(itty.next())) return true; } return false; } else { final Property property = element.property(this.key); return property.isPresent() && testValue(property); } } }
public default ElementRequirement getMaxRequirement() { ElementRequirement max = ElementRequirement.ID; if (this instanceof TraversalParent) { for (final Traversal.Admin<Object, Object> traversal : ((TraversalParent) this).getLocalChildren()) { if (traversal instanceof IdentityTraversal) { if (max.compareTo(ElementRequirement.ID) < 0) max = ElementRequirement.ID; } else if (traversal instanceof TokenTraversal && ((TokenTraversal) traversal).getToken().equals(T.id)) { if (max.compareTo(ElementRequirement.ID) < 0) max = ElementRequirement.ID; } else if (traversal instanceof TokenTraversal && ((TokenTraversal) traversal).getToken().equals(T.label)) { if (max.compareTo(ElementRequirement.LABEL) < 0) max = ElementRequirement.LABEL; } else if (traversal instanceof ElementValueTraversal) { if (max.compareTo(ElementRequirement.PROPERTIES) < 0) max = ElementRequirement.PROPERTIES; } else { max = ElementRequirement.EDGES; } } } return max; }
public UniElement(Map<String, Object> properties, ElementSchema schema, UniGraph graph) { this.graph = graph; this.schema = schema; this.id = ObjectUtils.firstNonNull( properties.remove(T.id.getAccessor()), properties.remove(T.id.toString()), UUID.randomUUID()) .toString(); this.label = ObjectUtils.firstNonNull( properties.remove(T.label.getAccessor()), properties.remove(T.label.toString()), getDefaultLabel()) .toString(); }
T item = getItem(position); if (item instanceof CharSequence) { text.setText((CharSequence)item); } else { text.setText(item.toString()); }
public BinarySearchTreeNode<T> getParent(BinarySearchTreeNode<T> e) { if (e == null) { return null; } BinarySearchTreeNode<T> current = this.root; T eValue = e.getValue(); while (current != null) { if (howManyChildren(current) == 0) { return null; } else if ((current.getLeft()!=null && eValue.equals(current.getLeft().getValue())) || (current.getRight()!=null) && eValue.equals(current.getRight().getValue())) { return current; } else if (eValue.compareTo(current.getValue()) < 0) { current = current.getLeft(); } else { current = current.getRight(); } } return null; }
@Override public int hashCode() { return this.getClass().hashCode() ^ this.t.hashCode(); }
/** * Filters vertices, edges and vertex properties based on their properties. * * @param label the label of the {@link Element} * @param propertyKey the key of the property to filter on * @param predicate the filter to apply to the key's value * @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.0.0-incubating */ public default GraphTraversal<S, E> has(final String label, final String propertyKey, final P<?> predicate) { this.asAdmin().getBytecode().addStep(Symbols.has, label, propertyKey, predicate); TraversalHelper.addHasContainer(this.asAdmin(), new HasContainer(T.label.getAccessor(), P.eq(label))); return TraversalHelper.addHasContainer(this.asAdmin(), new HasContainer(propertyKey, predicate)); }