|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.staccatocommons.lang.CollectionBuilder<A,B>
public class CollectionBuilder<A,B extends Collection<A>>
a Builder for Collections. With the exception of
from(Collection, Applicable), all its factory methods grant to
return CollectionBuilder that build Unmodifiable collections
| Constructor Summary | |
|---|---|
CollectionBuilder(B list,
net.sf.staccatocommons.defs.Applicable<B,B> wrapperFunction)
Creates a new CollectionBuilder |
|
| Method Summary | ||
|---|---|---|
B |
build()
Returns the built object. |
|
static
|
from(Collection<A> collection)
Answers a new CollectionBuilder that configures a
Collection |
|
static
|
listWith(A element)
Answers a new CollectionBuilder that configures a List,
with the given element already added. |
|
static
|
setWith(A element)
Answers a new CollectionBuilder that configures a Set, with
the given element already added |
|
static
|
sortedSetWith(A element)
Answers a new CollectionBuilder that configures a SortedSet
, with the given element already added |
|
static
|
toUnmodifiableCollection()
Answers a constant function that returns an Unmodifiable view of
its collection argument |
|
static
|
toUnmodifiableList()
Answers a constant function that returns an Unmodifiable view of
its list argument |
|
static
|
toUnmodifiableSet()
Answers a constant function that returns an Unmodifiable view of
its SortedSet argument |
|
static
|
toUnmodifiableSortedSet()
Answers a constant function that returns an Unmodifiable view of
its SortedSet argument |
|
CollectionBuilder<A,B> |
unwrap()
Disables wrapping, which means that a built collection will be returned just as it was created. |
|
CollectionBuilder<A,B> |
with(A element)
Adds an element to the list |
|
CollectionBuilder<A,B> |
withIf(A element,
net.sf.staccatocommons.defs.Evaluable<? super A> evaluable)
Adds an element to the list if it satisfies the given condition |
|
CollectionBuilder<A,B> |
withWrapper(net.sf.staccatocommons.defs.Applicable<B,B> wrapperFunction)
Sets the wrapper function, that is, the Applicable to apply to the
resulting collection before returning it through build(). |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CollectionBuilder(@NonNull
B list,
net.sf.staccatocommons.defs.Applicable<B,B> wrapperFunction)
CollectionBuilder
list - the list to be configured by this builderwrapperFunction - | Method Detail |
|---|
@NonNull public CollectionBuilder<A,B> with(A element)
element -
@NonNull
public CollectionBuilder<A,B> withIf(A element,
@NonNull
net.sf.staccatocommons.defs.Evaluable<? super A> evaluable)
element - evaluable -
@NonNull
public CollectionBuilder<A,B> withWrapper(@NonNull
net.sf.staccatocommons.defs.Applicable<B,B> wrapperFunction)
Applicable to apply to the
resulting collection before returning it through build().
By default, collections are wrapped with unmodifiable wrappers, but this
behavior can be changed through this method.
wrapperFunction -
@NonNull public CollectionBuilder<A,B> unwrap()
build() will be
modifiable.
@NonNull
public B build()
throws BuilderAlreadyUsedException
Builder
Builders are not meant to be used more than once. So this method can only
be invoked successfully one time. Subsequent invocations after a successful
return will throw an BuilderAlreadyUsedException. However,
implementors may relax this, and be reusable, that is being able to be used
more than once; such implementors should document that feature.
Builders may impose restriction to the state of the object under
construction. If such constraints are not met while invoking this method, a
ObjectUnderConstructionException exception must be thrown.
build in interface Builder<B extends Collection<A>>BuilderAlreadyUsedException - If the building process has finished, but this method has already
being invoked without throwing an exception.
@NonNull
public static <A> CollectionBuilder<A,Collection<A>> from(@NonNull
Collection<A> collection)
CollectionBuilder that configures a
Collection
A -
CollectionBuilder that builds a Collection@NonNull public static <A> CollectionBuilder<A,SortedSet<A>> sortedSetWith(A element)
CollectionBuilder that configures a SortedSet
, with the given element already added
A -
CollectionBuilder that builds a SortedSet@NonNull public static <A> CollectionBuilder<A,Set<A>> setWith(A element)
CollectionBuilder that configures a Set, with
the given element already added
A -
CollectionBuilder that builds a set@NonNull public static <A> CollectionBuilder<A,List<A>> listWith(A element)
CollectionBuilder that configures a List,
with the given element already added. The list built this builder grants to
be Unmodifiable
A -
CollectionBuilder that builds lists@Constant public static <A> net.sf.staccatocommons.defs.Applicable<Set<A>,Set<A>> toUnmodifiableSet()
Unmodifiable view of
its SortedSet argument
A -
@Constant public static <A> net.sf.staccatocommons.defs.Applicable<SortedSet<A>,SortedSet<A>> toUnmodifiableSortedSet()
Unmodifiable view of
its SortedSet argument
A -
@Constant public static <A> net.sf.staccatocommons.defs.Applicable<List<A>,List<A>> toUnmodifiableList()
Unmodifiable view of
its list argument
A -
@Constant public static <A> net.sf.staccatocommons.defs.Applicable<Collection<A>,Collection<A>> toUnmodifiableCollection()
Unmodifiable view of
its collection argument
A -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||