@Test public void testCollectMany() { for (List<Long> ids: someLists(longs(), 10, 100)) { List<Double> values = lists(doubles(), ids.size()).next(); ResultList results = IntStream.range(0, ids.size()) .mapToObj(i -> Results.create(ids.get(i), values.get(i))) .collect(Results.listCollector()); assertThat(results.stream().map(Result::getId).collect(Collectors.toList()), equalTo(ids)); assertThat(results.stream().map(Result::getScore).collect(Collectors.toList()), equalTo(values)); } }
@Test public void testParallelCollect() { for (List<Long> ids: someLists(longs(), 100, 10000)) { List<Double> values = lists(doubles(), ids.size()).next(); ResultList results = IntStream.range(0, ids.size()) .parallel() .mapToObj(i -> Results.create(ids.get(i), values.get(i))) .collect(Results.listCollector()); assertThat(results.stream().map(Result::getId).collect(Collectors.toList()), equalTo(ids)); assertThat(results.stream().map(Result::getScore).collect(Collectors.toList()), equalTo(values)); } } }
/** * Create a generator of lists with values from the content generator. * Length is at least low. * * @param <T> * type of list elements generated * @param content * generator providing the content of lists generated * @param low * minimal size. If low is larger than * {@link CombinedGenerators#DEFAULT_COLLECTION_MAX_SIZE} then it * is the upper size bound as well. */ public static <T> Generator<List<T>> lists(Generator<? extends T> content, int low) { return lists(content, low, Math.max(low, ListGenerator.MAX_SIZE) ); }
/** * Create a generator of non-empty lists with values from the content * generator. Length values of lists generated will be created with * {@link Distribution#UNIFORM}. * * @param <T> * type of list elements generated * @param content * generator providing the content of lists generated */ public static <T> Generator<List<T>> nonEmptyLists(Generator<? extends T> content) { return lists(content, positiveIntegers(MAX_SIZE)); }
/** * Create a generator of lists with values from the content generator. * Length is between high and low. * * @param <T> * type of list elements generated * @param content * generator providing the content of lists generated * @param low * minimal size * @param high * max size */ public static <T> Generator<List<T>> lists(Generator<? extends T> content, int low, int high) { return lists(content, new IntegerGenerator(low, high)); }
@Override public TableSchema next() { final List<ColumnSchema> columnSchemas = COLUMNS_GEN.next(); ImmutableList.Builder<String> columns = ImmutableList.builder(); for (ColumnSchema columnSchema : columnSchemas) { columns.add(columnSchema.getColumnName()); } final Generator<List<IndexSchema>> indexGen = CombinedGenerators.lists( new IndexSchemaGenerator(columns.build()), numIndicesGen); return new TableSchema(columnSchemas, indexGen.next()); } }