@Test public void shouldPassAccumulatedElementsToTheSuppliedBuilderFunctionAndReturnTheResult() throws Exception { CollectionBuilder<Integer> collectionBuilder = collectionBuilderWith(1, 2, 3); Collection<Integer> expected = collectionWith(1, 2, 3); Collection<Integer> actual = collectionBuilder.build(new UnaryFunction<Iterable<Integer>, Collection<Integer>>() { @Override public Collection<Integer> call(Iterable<Integer> elements) { Stack<Integer> collection = new Stack<Integer>(); for (Integer element : elements) { collection.push(element); } return collection; } }); assertThat(actual instanceof Stack, is(true)); assertThat(actual, hasOnlyItemsInAnyOrder(expected)); }
@Override public Collection<E> build() { return Collections.unmodifiableList(new ArrayList<E>(elements)); }
CollectionBuilder extends AbstractBuilder<E, CollectionBuilder<E>, Collection<E>> implements AbstractBuilder.WithCustomImplementationSupport<E, Collection, Collection<E>> { @Override public Collection<E> build() { return Collections.unmodifiableList(new ArrayList<E>(elements)); } }
CollectionBuilder extends AbstractBuilder<E, CollectionBuilder<E>, Collection<E>> implements AbstractBuilder.WithCustomImplementationSupport<E, Collection, Collection<E>> { @Override public Collection<E> build() { return Collections.unmodifiableList(new ArrayList<E>(elements)); }  }
CollectionBuilder extends AbstractBuilder<E, CollectionBuilder<E>, Collection<E>> implements AbstractBuilder.WithCustomImplementationSupport<E, Collection, Collection<E>> { @Override public Collection<E> build() { return Collections.unmodifiableList(new ArrayList<E>(elements)); }  static CollectionBuilder<E> collectionBuilder(); static CollectionBuilder<E> collectionBuilder(Class<E> elementClass); @Override Collection<E> build(); @Override Collection<E> build(Class<? extends Collection> implementationClass); @Override T build(UnaryFunction<? super Iterable<E>, ? extends T> builderFunction); }
CollectionBuilder extends AbstractBuilder<E, CollectionBuilder<E>, Collection<E>> implements AbstractBuilder.WithCustomImplementationSupport<E, Collection, Collection<E>> { @Override public Collection<E> build() { return Collections.unmodifiableList(new ArrayList<E>(elements)); }  static CollectionBuilder<E> collectionBuilder(); static CollectionBuilder<E> collectionBuilder(Class<E> elementClass); @Override Collection<E> build(); @Override Collection<E> build(Class<? extends Collection> implementationClass); @Override T build(UnaryFunction<? super Iterable<E>, ? extends T> builderFunction);  }