@Test public void testUnion() throws Exception { List<String> words = asList("a", "b", "c", "d", "e"); DataGenerator<List<String>> batchGen = DataGenerator.union( DataGenerator.items(words), DataGenerator.range(0, 5), (t, n) -> t + '-' + n ).batch(25); List<String> data = batchGen.getValue(); data.sort(Comparator.naturalOrder()); List<String> expected = words.stream().flatMap(w -> { List<String> items = new ArrayList<>(); for (int i = 0; i < 5; i++) { items.add(w + '-' + i); } return items.stream(); }).collect(Collectors.toList()); assertThat(data).containsAll(expected); assertThat(batchGen.apply().isClosed()).isTrue(); }
@Override public DataGenerator<List<A>> apply() { UnionDataGenerator nextGen = new UnionDataGenerator(this, position + 1); return nextGen.isClosed() ? (DataGenerator<List<A>>) EOS : nextGen; }
UnionDataGenerator extends DataGenerator<List<A>> { @Override public DataGenerator<List<A>> apply() { UnionDataGenerator nextGen = new UnionDataGenerator(this, position + 1); return nextGen.isClosed() ? (DataGenerator<List<A>>) EOS : nextGen; } }
UnionDataGenerator extends DataGenerator<List<A>> { @Override public DataGenerator<List<A>> apply() { UnionDataGenerator nextGen = new UnionDataGenerator(this, position + 1); return nextGen.isClosed() ? (DataGenerator<List<A>>) EOS : nextGen; } private  UnionDataGenerator(List<DataGenerator<A>> sources, double density, int initialSlice); private  UnionDataGenerator(UnionDataGenerator<A> generator, int position); }
UnionDataGenerator extends DataGenerator<List<A>> { @Override public DataGenerator<List<A>> apply() { UnionDataGenerator nextGen = new UnionDataGenerator(this, position + 1); return nextGen.isClosed() ? (DataGenerator<List<A>>) EOS : nextGen; } private  UnionDataGenerator(List<DataGenerator<A>> sources, double density, int initialSlice); private  UnionDataGenerator(UnionDataGenerator<A> generator, int position); @Override DataGenerator<List<A>> apply(); @Override Optional<List<A>> getOptionalValue(); static DataGenerator<List<A>> newInstance(List<DataGenerator<A>> sources); static DataGenerator<List<A>> newInstance(List<DataGenerator<A>> sources, double density, int initialSlice); }
UnionDataGenerator extends DataGenerator<List<A>> { @Override public DataGenerator<List<A>> apply() { UnionDataGenerator nextGen = new UnionDataGenerator(this, position + 1); return nextGen.isClosed() ? (DataGenerator<List<A>>) EOS : nextGen; } private  UnionDataGenerator(List<DataGenerator<A>> sources, double density, int initialSlice); private  UnionDataGenerator(UnionDataGenerator<A> generator, int position); @Override DataGenerator<List<A>> apply(); @Override Optional<List<A>> getOptionalValue(); static DataGenerator<List<A>> newInstance(List<DataGenerator<A>> sources); static DataGenerator<List<A>> newInstance(List<DataGenerator<A>> sources, double density, int initialSlice);  }