Class ImmutableSet.SetBuilderImpl<E>

java.lang.Object
com.google.common.collect.ImmutableSet.SetBuilderImpl<E>
Direct Known Subclasses:
ImmutableSet.EmptySetBuilderImpl, ImmutableSet.JdkBackedSetBuilderImpl, ImmutableSet.RegularSetBuilderImpl
Enclosing class:
ImmutableSet<E>

private abstract static class ImmutableSet.SetBuilderImpl<E> extends Object
Swappable internal implementation of an ImmutableSet.Builder.
  • Field Details

    • dedupedElements

      E[] dedupedElements
    • distinct

      int distinct
  • Constructor Details

    • SetBuilderImpl

      SetBuilderImpl(int expectedCapacity)
    • SetBuilderImpl

      SetBuilderImpl(ImmutableSet.SetBuilderImpl<E> toCopy)
      Initializes this SetBuilderImpl with a copy of the deduped elements array from toCopy.
  • Method Details

    • ensureCapacity

      private void ensureCapacity(int minCapacity)
      Resizes internal data structures if necessary to store the specified number of distinct elements.
    • addDedupedElement

      final void addDedupedElement(E e)
      Adds e to the insertion-order array of deduplicated elements. Calls ensureCapacity.
    • add

      abstract ImmutableSet.SetBuilderImpl<E> add(E e)
      Adds e to this SetBuilderImpl, returning the updated result. Only use the returned SetBuilderImpl, since we may switch implementations if e.g. hash flooding is detected.
    • combine

      Adds all the elements from the specified SetBuilderImpl to this SetBuilderImpl.
    • copy

      abstract ImmutableSet.SetBuilderImpl<E> copy()
      Creates a new copy of this SetBuilderImpl. Modifications to that SetBuilderImpl will not affect this SetBuilderImpl or sets constructed from this SetBuilderImpl via build().
    • review

      Call this before build(). Does a final check on the internal data structures, e.g. shrinking unnecessarily large structures or detecting previously unnoticed hash flooding.
    • build

      abstract ImmutableSet<E> build()