Java Code Examples for org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils#of()
The following examples show how to use
org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils#of() .
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: Client.java From tinkerpop with Apache License 2.0 | 6 votes |
/** * Uses a {@link LoadBalancingStrategy} to choose the best {@link Host} and then selects the best connection * from that host's connection pool. */ @Override protected Connection chooseConnection(final RequestMessage msg) throws TimeoutException, ConnectionException { final Iterator<Host> possibleHosts; if (msg.optionalArgs(Tokens.ARGS_HOST).isPresent()) { // TODO: not sure what should be done if unavailable - select new host and re-submit traversal? final Host host = (Host) msg.getArgs().get(Tokens.ARGS_HOST); msg.getArgs().remove(Tokens.ARGS_HOST); possibleHosts = IteratorUtils.of(host); } else { possibleHosts = this.cluster.loadBalancingStrategy().select(msg); } // you can get no possible hosts in more than a few situations. perhaps the servers are just all down. // or perhaps the client is not configured properly (disables ssl when ssl is enabled on the server). if (!possibleHosts.hasNext()) throw new TimeoutException("Timed out while waiting for an available host - check the client configuration and connectivity to the server if this message persists"); final Host bestHost = possibleHosts.next(); final ConnectionPool pool = hostConnectionPools.get(bestHost); return pool.borrowConnection(cluster.connectionPoolSettings().maxWaitForConnection, TimeUnit.MILLISECONDS); }
Example 2
Source File: EdgeWriter.java From hgraphdb with Apache License 2.0 | 6 votes |
@Override public Iterator<Put> constructInsertions() { final String label = edge.label() != null ? edge.label() : Edge.DEFAULT_LABEL; Put put = new Put(ValueUtils.serializeWithSalt(edge.id())); put.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.TO_BYTES, ValueUtils.serialize(edge.inVertex().id())); put.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.FROM_BYTES, ValueUtils.serialize(edge.outVertex().id())); put.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.LABEL_BYTES, ValueUtils.serialize(label)); put.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.CREATED_AT_BYTES, ValueUtils.serialize(((HBaseEdge) edge).createdAt())); put.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.UPDATED_AT_BYTES, ValueUtils.serialize(((HBaseEdge) edge).updatedAt())); ((HBaseEdge) edge).getProperties().forEach((key, value) -> { byte[] bytes = ValueUtils.serializePropertyValue(graph, ElementType.EDGE, label, key, value); put.addColumn(Constants.DEFAULT_FAMILY_BYTES, Bytes.toBytes(key), bytes); }); return IteratorUtils.of(put); }
Example 3
Source File: RepeatStep.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override protected Iterator<Traverser.Admin<S>> standardAlgorithm() throws NoSuchElementException { final RepeatStep<S> repeatStep = (RepeatStep<S>) this.getTraversal().getParent(); while (true) { final Traverser.Admin<S> start = this.starts.next(); start.incrLoops(); if (repeatStep.doUntil(start, false)) { start.resetLoops(); return IteratorUtils.of(start); } else { if (!repeatStep.untilFirst && !repeatStep.emitFirst) repeatStep.repeatTraversal.addStart(start); else repeatStep.addStart(start); if (repeatStep.doEmit(start, false)) { final Traverser.Admin<S> emitSplit = start.split(); emitSplit.resetLoops(); return IteratorUtils.of(emitSplit); } } } }
Example 4
Source File: TinkerVertexProperty.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public <U> Iterator<Property<U>> properties(final String... propertyKeys) { if (null == this.properties) return Collections.emptyIterator(); if (propertyKeys.length == 1) { final Property<U> property = this.properties.get(propertyKeys[0]); return null == property ? Collections.emptyIterator() : IteratorUtils.of(property); } else return (Iterator) this.properties.entrySet().stream().filter(entry -> ElementHelper.keyExists(entry.getKey(), propertyKeys)).map(entry -> entry.getValue()).collect(Collectors.toList()).iterator(); }
Example 5
Source File: TinkerEdge.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public Iterator<Vertex> vertices(final Direction direction) { if (removed) return Collections.emptyIterator(); switch (direction) { case OUT: return IteratorUtils.of(this.outVertex); case IN: return IteratorUtils.of(this.inVertex); default: return IteratorUtils.of(this.outVertex, this.inVertex); } }
Example 6
Source File: LabelMetadataWriter.java From hgraphdb with Apache License 2.0 | 5 votes |
@Override public Iterator<Put> constructInsertions() { Put put = new Put(graph.getLabelMetadataModel().serialize(label.key())); put.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.CREATED_AT_BYTES, ValueUtils.serialize(label.createdAt())); put.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.UPDATED_AT_BYTES, ValueUtils.serialize(label.updatedAt())); put.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.ELEMENT_ID_BYTES, ValueUtils.serialize(label.idType().getCode())); label.propertyTypes().forEach((key, value) -> put.addColumn(Constants.DEFAULT_FAMILY_BYTES, Bytes.toBytes(key), ValueUtils.serialize(value.getCode()))); return IteratorUtils.of(put); }
Example 7
Source File: PropertyMetadataWriter.java From hgraphdb with Apache License 2.0 | 5 votes |
@Override public Iterator<Put> constructInsertions() { Put put = new Put(graph.getLabelMetadataModel().serialize(label.key())); put.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.CREATED_AT_BYTES, ValueUtils.serialize(label.createdAt())); put.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.UPDATED_AT_BYTES, ValueUtils.serialize(label.updatedAt())); put.addColumn(Constants.DEFAULT_FAMILY_BYTES, Bytes.toBytes(propertyKey), ValueUtils.serialize(type.getCode())); return IteratorUtils.of(put); }
Example 8
Source File: DetachedEdge.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public Iterator<Vertex> vertices(final Direction direction) { switch (direction) { case OUT: return IteratorUtils.of(this.outVertex); case IN: return IteratorUtils.of(this.inVertex); default: return IteratorUtils.of(this.outVertex, this.inVertex); } }
Example 9
Source File: IndexMetadataWriter.java From hgraphdb with Apache License 2.0 | 5 votes |
@Override public Iterator<Mutation> constructMutations() { Put put = new Put(graph.getIndexMetadataModel().serialize(index.key())); put.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.INDEX_STATE_BYTES, ValueUtils.serialize(index.state().toString())); put.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.UPDATED_AT_BYTES, ValueUtils.serialize(index.updatedAt())); return IteratorUtils.of(put); }
Example 10
Source File: StarGraph.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public Iterator<Vertex> vertices(final Object... vertexIds) { if (null == this.starVertex) return Collections.emptyIterator(); else if (vertexIds.length > 0 && vertexIds[0] instanceof StarVertex) return Stream.of(vertexIds).map(v -> (Vertex) v).iterator(); // todo: maybe do this better - not sure of star semantics here else if (idExists(this.starVertex.id(), vertexIds)) return IteratorUtils.of(this.starVertex); else return Collections.emptyIterator(); // TODO: is this the semantics we want? the only "real vertex" is star vertex. /*return null == this.starVertex ? Collections.emptyIterator() : Stream.concat( Stream.of(this.starVertex), Stream.concat( this.starVertex.outEdges.values() .stream() .flatMap(List::stream) .map(Edge::inVertex), this.starVertex.inEdges.values() .stream() .flatMap(List::stream) .map(Edge::outVertex))) .filter(vertex -> ElementHelper.idExists(vertex.id(), vertexIds)) .iterator();*/ }
Example 11
Source File: ComputerGraph.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public Iterator<Vertex> vertices(final Direction direction) { if (direction.equals(Direction.OUT)) return IteratorUtils.of(this.outVertex()); if (direction.equals(Direction.IN)) return IteratorUtils.of(this.inVertex()); else return IteratorUtils.of(this.outVertex(), this.inVertex()); }
Example 12
Source File: TinkerEdge.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public <V> Iterator<Property<V>> properties(final String... propertyKeys) { if (null == this.properties) return Collections.emptyIterator(); if (propertyKeys.length == 1) { final Property<V> property = this.properties.get(propertyKeys[0]); return null == property ? Collections.emptyIterator() : IteratorUtils.of(property); } else return (Iterator) this.properties.entrySet().stream().filter(entry -> ElementHelper.keyExists(entry.getKey(), propertyKeys)).map(entry -> entry.getValue()).collect(Collectors.toList()).iterator(); }
Example 13
Source File: SpecializedTinkerEdge.java From tinkergraph-gremlin with Apache License 2.0 | 5 votes |
@Override public Iterator<Vertex> vertices(final Direction direction) { if (removed) return Collections.emptyIterator(); switch (direction) { case OUT: return IteratorUtils.of(outVertex); case IN: return IteratorUtils.of(inVertex); default: return IteratorUtils.of(outVertex, inVertex); } }
Example 14
Source File: SpecializedTinkerEdge.java From tinkergraph-gremlin with Apache License 2.0 | 5 votes |
@Override public <V> Iterator<Property<V>> properties(String... propertyKeys) { if (propertyKeys.length == 0) { return (Iterator) specificKeys.stream().map(key -> property(key)).filter(vp -> vp.isPresent()).iterator(); } else if (propertyKeys.length == 1) { // treating as special case for performance // return IteratorUtils.of(property(propertyKeys[0])); final Property<V> prop = property(propertyKeys[0]); return prop.isPresent() ? IteratorUtils.of(prop) : Collections.emptyIterator(); } else { return Arrays.stream(propertyKeys).map(key -> (Property<V>) property(key)).filter(vp -> vp.isPresent()).iterator(); } }
Example 15
Source File: HadoopEdge.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public Iterator<Vertex> vertices(final Direction direction) { switch (direction) { case OUT: return IteratorUtils.of(this.graph.vertices(getBaseEdge().vertices(Direction.OUT).next().id())).next(); case IN: return IteratorUtils.of(this.graph.vertices(getBaseEdge().vertices(Direction.IN).next().id())).next(); default: { final Iterator<Vertex> iterator = getBaseEdge().vertices(Direction.BOTH); return IteratorUtils.of(this.graph.vertices(iterator.next().id()).next(), this.graph.vertices(iterator.next().id()).next()); } } }
Example 16
Source File: Neo4jEdge.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public Iterator<Vertex> vertices(final Direction direction) { this.graph.tx().readWrite(); switch (direction) { case OUT: return IteratorUtils.of(new Neo4jVertex(this.getBaseEdge().start(), this.graph)); case IN: return IteratorUtils.of(new Neo4jVertex(this.getBaseEdge().end(), this.graph)); default: return IteratorUtils.of(new Neo4jVertex(this.getBaseEdge().start(), this.graph), new Neo4jVertex(this.getBaseEdge().end(), this.graph)); } }
Example 17
Source File: PropertyIncrementer.java From hgraphdb with Apache License 2.0 | 5 votes |
@Override public Iterator<Mutation> constructMutations() { Increment incr = new Increment(ValueUtils.serializeWithSalt(element.id())); incr.addColumn(Constants.DEFAULT_FAMILY_BYTES, Bytes.toBytes(key), value); Put put = new Put(ValueUtils.serializeWithSalt(element.id())); put.addColumn(Constants.DEFAULT_FAMILY_BYTES, Constants.UPDATED_AT_BYTES, ValueUtils.serialize(((HBaseElement) element).updatedAt())); return IteratorUtils.of(incr, put); }
Example 18
Source File: FactEdge.java From act-platform with ISC License | 5 votes |
@Override public Iterator<Vertex> vertices(Direction direction) { switch (direction) { case OUT: return IteratorUtils.of(outVertex); case IN: return IteratorUtils.of(inVertex); case BOTH: return IteratorUtils.of(outVertex, inVertex); default: throw new IllegalArgumentException(String.format("Unknown direction %s.", direction)); } }
Example 19
Source File: LabelMetadataRemover.java From hgraphdb with Apache License 2.0 | 4 votes |
@Override public Iterator<Mutation> constructMutations() { Delete delete = new Delete(graph.getLabelMetadataModel().serialize(label.key())); return IteratorUtils.of(delete); }
Example 20
Source File: EdgeRemover.java From hgraphdb with Apache License 2.0 | 4 votes |
@Override public Iterator<Mutation> constructMutations() { Delete delete = new Delete(ValueUtils.serializeWithSalt(edge.id())); return IteratorUtils.of(delete); }