GetWalksHandler implements OutputOperationHandler<GetWalks, Iterable<Walk>> { @Override public Iterable<Walk> doOperation(final GetWalks getWalks, final Context context, final Store store) throws OperationException { if (null == getWalks.getInput()) { return null; } if (null == getWalks.getOperations()) { return new EmptyClosableIterable<>(); } final Integer resultLimit = getWalks.getResultsLimit(); final int hops = getWalks.getNumberOfGetEdgeOperations(); final LimitedCloseableIterable limitedInputItr = new LimitedCloseableIterable<>(getWalks.getInput(), 0, resultLimit, false); final List<EntityId> originalInput = Lists.newArrayList(limitedInputItr); if (hops == 0) { return new EmptyClosableIterable<>(); } else if (maxHops != null && hops > maxHops) { throw new OperationException("GetWalks operation contains " + hops + " hops. The maximum number of hops is: " + maxHops); } final AdjacencyMaps adjacencyMaps = prune && !getWalks.isIncludePartial() ? new PrunedAdjacencyMaps() : new SimpleAdjacencyMaps(); final EntityMaps entityMaps = new SimpleEntityMaps(); List<?> seeds = originalInput; for (final OperationChain<Iterable<Element>> operation : getWalks.getOperations()) { if (isWhileOperation(operation)) { seeds = executeWhileOperation( operation, seeds, resultLimit, context, store, hops, adjacencyMaps, entityMaps ); } else { seeds = executeOperation( operation, seeds, resultLimit, context, store, hops, adjacencyMaps, entityMaps ); } } if (entityMaps.size() == adjacencyMaps.size()) { entityMaps.add(new EntityMap()); } final GraphWindow graphWindow = new GraphWindow(adjacencyMaps, entityMaps); return Streams.toStream(originalInput) .flatMap(seed -> walk(seed.getVertex(), null, graphWindow, new LinkedList<>(), new LinkedList<>(), hops, getWalks.isIncludePartial()).stream()) .collect(Collectors.toList()); }  @Override Iterable<Walk> doOperation(final GetWalks getWalks, final Context context, final Store store); Integer getMaxHops(); void setMaxHops(final Integer maxHops); Boolean getPrune(); void setPrune(final Boolean prune);  }
@Test public void shouldHandleNullInput() throws Exception { final GetElements getElements = new GetElements.Builder() .view(new View.Builder() .edge(TestGroups.EDGE) .build()) .build(); final GetWalks operation = new GetWalks.Builder() .operations(getElements) .build(); final GetWalksHandler handler = new GetWalksHandler(); final Iterable<Walk> result = handler.doOperation(operation, null, null); assertThat(result, is(nullValue())); }