Class CollectionUtil.FluentList

java.lang.Object
com.ssgllc.fish.service.util.registered.CollectionUtil.FluentList
Enclosing class:
CollectionUtil

public static class CollectionUtil.FluentList extends Object
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 Details

    • FluentList

      public FluentList(List<Object> list)
  • Method Details

    • getList

      public List<Object> 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

      public void setList(List<Object> list)
      Replaces the underlying list. Returns nothing, so it cannot appear mid-chain; the factories on CollectionUtil are the normal way in.
      Parameters:
      list - the list to wrap
    • add

      public CollectionUtil.FluentList add(Object value)
      Appends a value and returns this list, so the call can be chained. Appends nulls; use addIfNotNull(Object) to skip them.
      Parameters:
      value - the value to append
      Returns:
      this list, for chaining

      SpEL example:
      #createEmptyFluentList().add(#firstName).add(#lastName).getList()
    • addAll

      public CollectionUtil.FluentList addAll(Collection<Object> values)
      Appends every element of a collection and returns this list. Throws on a null collection; use addAllIfNotNull(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

      public Object get(int index)
      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

      public CollectionUtil.FluentList addIfNotNull(Object value)
      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

      public CollectionUtil.FluentList addAllIfNotNull(Collection<Object> values)
      Appends every non-null element of a collection, and returns this list. Throws on a null collection - only the elements are guarded, unlike CollectionUtil.FluentSet.addValuesIfNotNull(Collection), which tolerates a null collection too.
      Parameters:
      values - the values to append; must not be null
      Returns:
      this list, for chaining