Class CollectionUtil.FluentList
java.lang.Object
com.ssgllc.fish.service.util.registered.CollectionUtil.FluentList
- Enclosing class:
CollectionUtil
A list that returns itself from every mutation, so it can be built inside a single expression.
The ordered, duplicate-keeping counterpart to CollectionUtil.FluentSet. Start one with
CollectionUtil.createEmptyFluentList() or CollectionUtil.createFluentList(Object)
and finish with getList().
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAppends a value and returns this list, so the call can be chained.addAll(Collection<Object> values) Appends every element of a collection and returns this list.addAllIfNotNull(Collection<Object> values) Appends every non-null element of a collection, and returns this list.addIfNotNull(Object value) Appends a value unless it is null, and returns this list.get(int index) The element at an index.getList()The underlying list - the last call in a chain, once everything has been added.voidReplaces the underlying list.
-
Constructor Details
-
FluentList
-
-
Method Details
-
getList
The underlying list - the last call in a chain, once everything has been added.- Returns:
- the list built so far
Groovy example:
return collectionUtil.createEmptyFluentList().add('A').add('B').getList()
Returns:
["A", "B"]
-
setList
Replaces the underlying list. Returns nothing, so it cannot appear mid-chain; the factories onCollectionUtilare the normal way in.- Parameters:
list- the list to wrap
-
add
Appends a value and returns this list, so the call can be chained. Appends nulls; useaddIfNotNull(Object)to skip them.- Parameters:
value- the value to append- Returns:
- this list, for chaining
SpEL example:
#createEmptyFluentList().add(#firstName).add(#lastName).getList()
-
addAll
Appends every element of a collection and returns this list. Throws on a null collection; useaddAllIfNotNull(Collection)to skip null elements, though that does not tolerate a null collection either.- Parameters:
values- the values to append- Returns:
- this list, for chaining
-
get
The element at an index. Throws if the index is out of range - this is a plain list read, with no bounds forgiveness.- Parameters:
index- zero-based position- Returns:
- the element at that position
-
addIfNotNull
Appends a value unless it is null, and returns this list. The usual choice when the value comes from an optional field.- Parameters:
value- the value to append if present- Returns:
- this list, for chaining
SpEL example:
#createEmptyFluentList().addIfNotNull(#line1).addIfNotNull(#line2).getList()
-
addAllIfNotNull
Appends every non-null element of a collection, and returns this list. Throws on a null collection - only the elements are guarded, unlikeCollectionUtil.FluentSet.addValuesIfNotNull(Collection), which tolerates a null collection too.- Parameters:
values- the values to append; must not be null- Returns:
- this list, for chaining
-