Class CollectionUtil.FluentSet
java.lang.Object
com.ssgllc.fish.service.util.registered.CollectionUtil.FluentSet
- Enclosing class:
CollectionUtil
A set that returns itself from every mutation, so it can be built inside a single expression.
A SpEL expression has no statements, so there is nowhere to put a loop or a temporary
variable - each call has to hand back something the next call can be written onto. Start one
with CollectionUtil.createEmptyFluentSet() and finish with getSet().
Duplicates collapse, as in any set. Use CollectionUtil.FluentList to keep order and duplicates.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a value and returns this set, so the call can be chained.addIfNotNull(Object value) Adds a value unless it is null, and returns this set.addValuesIfNotNull(Collection<Object> values) Adds every non-null element of a collection, and returns this set.getSet()The underlying set - the last call in a chain, once everything has been added.voidReplaces the underlying set.
-
Constructor Details
-
FluentSet
-
-
Method Details
-
getSet
The underlying set - the last call in a chain, once everything has been added.- Returns:
- the set built so far
Groovy example:
return collectionUtil.createEmptyFluentSet().add('A').add('B').add('A').getSet()
Returns:
["A", "B"]
-
setSet
Replaces the underlying set. Returns nothing, so it cannot appear mid-chain; the factories onCollectionUtilare the normal way in.- Parameters:
set- the set to wrap
-
add
Adds a value and returns this set, so the call can be chained. Adds nulls; useaddIfNotNull(Object)to skip them.- Parameters:
value- the value to add- Returns:
- this set, for chaining
SpEL example:
#createEmptyFluentSet().add(#statusId).add(#priorStatusId).getSet()
-
addIfNotNull
Adds a value unless it is null, and returns this set. The usual choice when the value comes from an optional field, since it keeps the chain unbroken without admitting a null.- Parameters:
value- the value to add if present- Returns:
- this set, for chaining
SpEL example:
#createEmptyFluentSet().addIfNotNull(#primaryPhone).addIfNotNull(#mobilePhone).getSet()
-
addValuesIfNotNull
Adds every non-null element of a collection, and returns this set. Tolerates a null collection - unlikeCollectionUtil.FluentList.addAllIfNotNull(Collection), which only guards the elements.- Parameters:
values- the values to add; null is ignored- Returns:
- this set, for chaining
Groovy example:
return collectionUtil.createEmptyFluentSet().addValuesIfNotNull(person.phones).getSet()
-