Class SetBuilder<E>

java.lang.Object
org.apache.juneau.internal.SetBuilder<E>
Type Parameters:
E - Element type.

public final class SetBuilder<E> extends Object
Builder for sets.
See Also:
  • Constructor Details

    • SetBuilder

      public SetBuilder(Class<E> elementType, Type... elementTypeArgs)
      Constructor.
      Parameters:
      elementType - The element type.
      elementTypeArgs - The element type generic arguments if there are any.
    • SetBuilder

      public SetBuilder(Set<E> addTo)
      Constructor.
      Parameters:
      addTo - The set to add to.
  • Method Details

    • build

      public Set<E> build()
      Builds the set.
      Returns:
      A set conforming to the settings on this builder.
    • sparse

      public SetBuilder<E> sparse()
      When specified, the build() method will return null if the set is empty.

      Otherwise build() will never return null.

      Returns:
      This object.
    • unmodifiable

      When specified, build() will return an unmodifiable set.
      Returns:
      This object.
    • copy

      public SetBuilder<E> copy()
      Forces the existing set to be copied instead of appended to.
      Returns:
      This object.
    • sorted

      public SetBuilder<E> sorted()
      Converts the set into a SortedSet.
      Returns:
      This object.
    • sorted

      public SetBuilder<E> sorted(Comparator<E> comparator)
      Converts the set into a SortedSet using the specified comparator.
      Parameters:
      comparator - The comparator to use for sorting.
      Returns:
      This object.
    • addAll

      public SetBuilder<E> addAll(Collection<E> value)
      Appends the contents of the specified collection into this set.

      This is a no-op if the value is null.

      Parameters:
      value - The collection to add to this set.
      Returns:
      This object.
    • add

      public SetBuilder<E> add(E value)
      Adds a single value to this set.
      Parameters:
      value - The value to add to this set.
      Returns:
      This object.
    • add

      public SetBuilder<E> add(E... values)
      Adds multiple values to this set.
      Parameters:
      values - The values to add to this set.
      Returns:
      This object.
    • addJson

      public SetBuilder<E> addJson(String... values)
      Adds entries to this set via JSON array strings.
      Parameters:
      values - The JSON array strings to parse and add to this set.
      Returns:
      This object.
    • addAny

      public SetBuilder<E> addAny(Object... values)
      Adds arbitrary values to this set.

      Objects can be any of the following:

      • The same type or convertible to the element type of this set.
      • Collections or arrays of anything on this set.
      • JSON array strings parsed and convertible to the element type of this set.
      Parameters:
      values - The values to add.
      Returns:
      This object.
    • addIf

      public SetBuilder<E> addIf(boolean flag, E value)
      Adds a value to this set if the specified flag is true.
      Parameters:
      flag - The flag.
      value - The value.
      Returns:
      This object.