List of usage examples for java.util Collections emptyIterator
@SuppressWarnings("unchecked") public static <T> Iterator<T> emptyIterator()
From source file:org.apache.sling.contextaware.config.resource.impl.ContextPathStrategyMultiplexer.java
/** * Merges all results from the detected implementations into a single answer. *//*from www.j av a 2 s .c o m*/ @Override public Iterator<Resource> findContextResources(Resource resource) { List<Iterator<Resource>> allResults = getAllResults(resource); if (allResults.isEmpty()) { return Collections.emptyIterator(); } if (allResults.size() == 1) { return allResults.get(0); } return mergeResults(allResults); }
From source file:org.apache.tinkerpop.gremlin.process.remote.RemoteGraph.java
/** * This method returns an empty {@link Iterator} - it is not meant to be called directly. *//* w ww . j a v a 2 s . c o m*/ @Override public Iterator<Vertex> vertices(final Object... vertexIds) { return Collections.emptyIterator(); }
From source file:org.apache.tinkerpop.gremlin.process.remote.RemoteGraph.java
/** * This method returns an empty {@link Iterator} - it is not meant to be called directly. *///from w ww .j a va 2s.c om @Override public Iterator<Edge> edges(final Object... edgeIds) { return Collections.emptyIterator(); }
From source file:org.apache.tinkerpop.gremlin.server.op.traversal.TraversalOpProcessor.java
@Override public ThrowingConsumer<Context> select(final Context ctx) throws OpProcessorException { final RequestMessage message = ctx.getRequestMessage(); logger.debug("Selecting processor for RequestMessage {}", message); final ThrowingConsumer<Context> op; switch (message.getOp()) { case Tokens.OPS_BYTECODE: validateTraversalSourceAlias(ctx, message, validateTraversalRequest(message)); op = this::iterateBytecodeTraversal; break;/*from www.j a v a2 s. co m*/ case Tokens.OPS_GATHER: final Optional<String> sideEffectForGather = message.optionalArgs(Tokens.ARGS_SIDE_EFFECT); if (!sideEffectForGather.isPresent()) { final String msg = String.format("A message with an [%s] op code requires a [%s] argument.", Tokens.OPS_GATHER, Tokens.ARGS_SIDE_EFFECT); throw new OpProcessorException(msg, ResponseMessage.build(message) .code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).statusMessage(msg) .create()); } final Optional<String> sideEffectKey = message.optionalArgs(Tokens.ARGS_SIDE_EFFECT_KEY); if (!sideEffectKey.isPresent()) { final String msg = String.format("A message with an [%s] op code requires a [%s] argument.", Tokens.OPS_GATHER, Tokens.ARGS_SIDE_EFFECT_KEY); throw new OpProcessorException(msg, ResponseMessage.build(message) .code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).statusMessage(msg) .create()); } validateTraversalSourceAlias(ctx, message, validatedAliases(message).get()); op = this::gatherSideEffect; break; case Tokens.OPS_KEYS: final Optional<String> sideEffectForKeys = message.optionalArgs(Tokens.ARGS_SIDE_EFFECT); if (!sideEffectForKeys.isPresent()) { final String msg = String.format("A message with an [%s] op code requires a [%s] argument.", Tokens.OPS_GATHER, Tokens.ARGS_SIDE_EFFECT); throw new OpProcessorException(msg, ResponseMessage.build(message) .code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).statusMessage(msg) .create()); } op = context -> { final RequestMessage msg = context.getRequestMessage(); final Optional<UUID> sideEffect = msg.optionalArgs(Tokens.ARGS_SIDE_EFFECT); final TraversalSideEffects sideEffects = cache.getIfPresent(sideEffect.get()); if (null == sideEffects) logger.warn("Request for side-effect keys on {} returned no side-effects in the cache", sideEffect.get()); handleIterator(context, null == sideEffects ? Collections.emptyIterator() : sideEffects.keys().iterator()); }; break; case Tokens.OPS_CLOSE: final Optional<String> sideEffectForClose = message.optionalArgs(Tokens.ARGS_SIDE_EFFECT); if (!sideEffectForClose.isPresent()) { final String msg = String.format("A message with an [%s] op code requires a [%s] argument.", Tokens.OPS_CLOSE, Tokens.ARGS_SIDE_EFFECT); throw new OpProcessorException(msg, ResponseMessage.build(message) .code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).statusMessage(msg) .create()); } op = context -> { final RequestMessage msg = context.getRequestMessage(); logger.debug("Close request {} for in thread {}", msg.getRequestId(), Thread.currentThread().getName()); final Optional<UUID> sideEffect = msg.optionalArgs(Tokens.ARGS_SIDE_EFFECT); cache.invalidate(sideEffect.get()); final String successMessage = String.format("Successfully cleared side effect cache for [%s].", Tokens.ARGS_SIDE_EFFECT); ctx.getChannelHandlerContext().writeAndFlush(ResponseMessage.build(message) .code(ResponseStatusCode.NO_CONTENT).statusMessage(successMessage).create()); }; break; case Tokens.OPS_INVALID: final String msgInvalid = String .format("Message could not be parsed. Check the format of the request. [%s]", message); throw new OpProcessorException(msgInvalid, ResponseMessage.build(message) .code(ResponseStatusCode.REQUEST_ERROR_MALFORMED_REQUEST).statusMessage(msgInvalid).create()); default: final String msgDefault = String.format("Message with op code [%s] is not recognized.", message.getOp()); throw new OpProcessorException(msgDefault, ResponseMessage.build(message) .code(ResponseStatusCode.REQUEST_ERROR_MALFORMED_REQUEST).statusMessage(msgDefault).create()); } return op; }
From source file:org.apache.tinkerpop.gremlin.spark.structure.io.OutputFormatRDD.java
@Override public <K, V> Iterator<KeyValue<K, V>> writeMemoryRDD(final Configuration configuration, final String memoryKey, JavaPairRDD<K, V> memoryRDD) { final org.apache.hadoop.conf.Configuration hadoopConfiguration = ConfUtil .makeHadoopConfiguration(configuration); final String outputLocation = hadoopConfiguration.get(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION); if (null != outputLocation) { // map back to a Hadoop stream for output memoryRDD.mapToPair(keyValue -> new Tuple2<>(new ObjectWritable<>(keyValue._1()), new ObjectWritable<>(keyValue._2()))).saveAsNewAPIHadoopFile( Constants.getMemoryLocation(outputLocation, memoryKey), ObjectWritable.class, ObjectWritable.class, SequenceFileOutputFormat.class, hadoopConfiguration); try {//from w w w .j ava 2s . com return (Iterator) new ObjectWritableIterator(hadoopConfiguration, new Path(Constants.getMemoryLocation(outputLocation, memoryKey))); } catch (final IOException e) { throw new IllegalStateException(e.getMessage(), e); } } return Collections.emptyIterator(); }
From source file:org.apache.tinkerpop.gremlin.spark.structure.io.OutputRDD.java
/** * Write the sideEffect memoryRDD to an output location. The {@link Configuration} maintains the specified location via {@link org.apache.tinkerpop.gremlin.hadoop.Constants#GREMLIN_HADOOP_OUTPUT_LOCATION}. * The default implementation returns an empty iterator. * * @param configuration the configuration of the Spark job * @param memoryKey the memory key of the memoryRDD * @param memoryRDD the memoryRDD//from w w w. j a v a 2 s . c o m * @param <K> the key class of the RDD * @param <V> the value class of the RDD * @return the {@link KeyValue} iterator to store in the final resultant {@link org.apache.tinkerpop.gremlin.process.computer.Memory}. */ public default <K, V> Iterator<KeyValue<K, V>> writeMemoryRDD(final Configuration configuration, final String memoryKey, final JavaPairRDD<K, V> memoryRDD) { return Collections.emptyIterator(); }
From source file:org.apache.tinkerpop.gremlin.structure.util.batch.BatchGraph.java
@Override public Iterator<Vertex> vertexIterator(final Object... vertexIds) { if (vertexIds.length > 1) throw new IllegalArgumentException("BatchGraph only allows a single vertex id at one time"); if ((this.previousOutVertexId != null) && (this.previousOutVertexId.equals(vertexIds[0]))) { return IteratorUtils.of(new BatchVertex(this.previousOutVertexId)); } else {/*from w w w . j av a 2s .c o m*/ Vertex vertex = retrieveFromCache(vertexIds[0]); if (null == vertex) { if (!this.incrementalLoading) return Collections.emptyIterator(); else { final Iterator<Vertex> iterator = this.baseGraph.V().has(this.vertexIdKey, vertexIds[0]); if (!iterator.hasNext()) return Collections.emptyIterator(); vertex = iterator.next(); if (iterator.hasNext()) throw new IllegalStateException( "There are multiple vertices with the provided id in the graph: " + vertexIds[0]); this.cache.set(vertex, vertexIds[0]); } } return IteratorUtils.of(new BatchVertex(vertexIds[0])); } }
From source file:org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph.java
@Override public Iterator<Vertex> vertices(final Object... vertexIds) { return Collections.emptyIterator(); }
From source file:org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph.java
@Override public Iterator<Edge> edges(final Object... edgeIds) { return Collections.emptyIterator(); }
From source file:org.apache.tinkerpop.gremlin.structure.util.star.StarGraph.java
@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 (ElementHelper.idExists(this.starVertex.id(), vertexIds)) return IteratorUtils.of(this.starVertex); else//from w w w . j ava 2s . com 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();*/ }