Package bm.util
Class Lister<E>
java.lang.Object
bm.util.Lister<E>
- Type Parameters:
E- is the type of elements in the list
- Direct Known Subclasses:
StringLister
Fluent api to build up a List of some type from various ingredients. The list is
constructed in place, using an ArrayList internally.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds all given elements.add(Collection<E> args) Adds all given elements.add(Function<T, E> mapper, Collection<T> args) Adds elements of a collection after mapping them.Adds all given elements if the predicate applied on the elements is true.Map all elements of args through themapper.get()Provides the list.static <T> Lister<T> of(Collection<T> elements) Creates an initial object.
-
Constructor Details
-
Lister
public Lister()Creates an empty one. -
Lister
Creates the object from initial elements.- Parameters:
first- a required element also used to allow to start with a single element while at the same time be able to differentiate this call from the one starting with a collectionelements- to initialise with
-
Lister
Creates the object from initial elements.- Parameters:
elements- to initialise with
-
-
Method Details
-
of
Creates an initial object.- Type Parameters:
T- the type of elements in the list- Parameters:
elements- to start the list with- Returns:
this
-
add
Adds all given elements.- Parameters:
elements- to add- Returns:
this
-
addIf
Adds all given elements if the predicate applied on the elements is true.- Parameters:
test- to run on each element, to add it only if the test returns trueelements- to add- Returns:
this
-
add
Adds all given elements.- Parameters:
args- elements to add- Returns:
this
-
add
Adds elements of a collection after mapping them.- Type Parameters:
T- the type of elements in the collection- Parameters:
mapper- to map elements of the collection to elements compatible with this object's elementsargs- the collection to map and add- Returns:
this
-
addJoined
public <T,S> Lister<E> addJoined(Function<T, S> mapper, Function<List<S>, E> joiner, Collection<T> args) Map all elements of args through themapper. The resulting list is then passed through the joiner to create the element to add to thisLister. -
get
Provides the list.- Returns:
- the internal list, leaking the representation. If the returned result is changed, this
will also chang the contents of this
Lister.
-