@Test public void shouldAddEmptyIterableOfEntities() { // Given // [A] -> [E] -> [D] -> [A] // \ \ // (BasicEntity) (EmptyIterable) // When final Walk walk = new Walk.Builder() .edge(EDGE_AE) .entity(ENTITY_E) .edges(EDGE_ED, EDGE_DA) .entities(new EmptyClosableIterable<>()) .build(); // Then assertThat(walk.getEntitiesAsEntries(), hasSize(4)); // A, D, E, A assertThat(walk.getEdges(), hasSize(3)); // A -> E, E -> D, D -> A assertThat(walk.getEdges().stream().flatMap(Set::stream).collect(Collectors.toList()), contains(EDGE_AE, EDGE_ED, EDGE_DA)); assertThat(walk.getEntities(), contains(Collections.emptySet(), Sets.newHashSet(ENTITY_E), Collections.emptySet(), Collections.emptySet())); assertThat(walk.getVerticesOrdered(), contains("A", "E", "D", "A")); }
public WrappedCloseableIterable(final Iterable<T> iterable) { if (null == iterable) { this.iterable = new EmptyClosableIterable<>(); } else { this.iterable = iterable; } }
public LimitedCloseableIterable(final CloseableIterable<T> iterable, final int start, final Integer end, final Boolean truncate) { if (null != end && start > end) { throw new IllegalArgumentException("The start pointer must be less than the end pointer."); } if (null == iterable) { this.iterable = new EmptyClosableIterable<>(); } else { this.iterable = iterable; } this.start = start; this.end = end; this.truncate = truncate; }
@Override protected O mergeResults(final List<O> results, final OP operation, final Context context, final Store store) { if (results.isEmpty()) { return (O) new EmptyClosableIterable<>(); } // Concatenate all the results into 1 iterable return (O) new ChainedIterable<>(CollectionUtil.toIterableArray(results)); } }
private CloseableIterable<EntityId> doOperation(final GetAdjacentIds operation, final MapStore mapStore) throws OperationException { if (null == operation.getInput() || !operation.getInput().iterator().hasNext()) { return new EmptyClosableIterable<>(); } return new EntityIdIterable(mapStore.getMapImpl(), operation, mapStore.getSchema()); }
@Override public CloseableIterable<? extends Element> doOperation(final GetElements operation, final Context context, final Store store) throws OperationException { final CloseableIterable<? extends Element> result; final Iterable<? extends ElementId> input = operation.getInput(); if (null == input) { throw new OperationException("Operation input is undefined - please specify an input."); } else { final Iterator<? extends ElementId> inputIter = input.iterator(); if (inputIter.hasNext()) { result = doOperation(operation, (ParquetStore) store, context.getUser()); } else { result = new EmptyClosableIterable<>(); } if (inputIter instanceof CloseableIterator) { ((CloseableIterator) inputIter).close(); } } if (input instanceof CloseableIterable) { ((CloseableIterable) input).close(); } return result; }
private CloseableIterable<Element> doOperation(final GetElements operation, final MapStore mapStore) throws OperationException { final MapImpl mapImpl = mapStore.getMapImpl(); if (!mapImpl.isMaintainIndex()) { throw new OperationException("Cannot execute getElements if the properties request that an index is not created"); } final Iterable<? extends ElementId> seeds = operation.getInput(); if (null == seeds) { return new EmptyClosableIterable<>(); } return new ElementsIterable(mapImpl, operation, mapStore.getSchema()); }