Class RefList.Builder<T extends Ref>

  • Type Parameters:
    T - type of reference being stored.
    Enclosing class:
    RefList<T extends Ref>

    public static class RefList.Builder<T extends Ref>
    extends java.lang.Object
    Builder to facilitate fast construction of an immutable RefList.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Ref[] list  
      private int size  
    • Constructor Summary

      Constructors 
      Constructor Description
      Builder()
      Create an empty list ready for items to be added.
      Builder​(int capacity)
      Create an empty list with at least the specified capacity.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(T ref)
      Add the reference to the end of the array.
      void addAll​(Ref[] src, int off, int cnt)
      Add all items from a source array.
      void addAll​(RefList.Builder other)
      Add all items from another builder.
      (package private) void dedupe​(java.util.function.BinaryOperator<T> mergeFunction)
      Dedupe the refs in place.
      T get​(int idx)
      Get the reference at a particular index.
      void remove​(int idx)
      Remove an item at a specific index.
      void set​(int idx, T ref)
      Replace a single existing element.
      int size()  
      void sort()
      Sort the list's backing array in-place.
      RefList<T> toRefList()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • list

        private Ref[] list
      • size

        private int size
    • Constructor Detail

      • Builder

        public Builder()
        Create an empty list ready for items to be added.
      • Builder

        public Builder​(int capacity)
        Create an empty list with at least the specified capacity.
        Parameters:
        capacity - the new capacity; if zero or negative, behavior is the same as Builder().
    • Method Detail

      • size

        public int size()
        Returns:
        number of items in this builder's internal collection.
      • get

        public T get​(int idx)
        Get the reference at a particular index.
        Parameters:
        idx - the index to obtain. Must be 0 <= idx < size().
        Returns:
        the reference value, never null.
      • remove

        public void remove​(int idx)
        Remove an item at a specific index.
        Parameters:
        idx - position to remove the item from.
      • add

        public void add​(T ref)
        Add the reference to the end of the array.

        References must be added in sort order, or the array must be sorted after additions are complete using sort().

        Parameters:
        ref -
      • addAll

        public void addAll​(RefList.Builder other)
        Add all items from another builder.
        Parameters:
        other -
        Since:
        5.4
      • addAll

        public void addAll​(Ref[] src,
                           int off,
                           int cnt)
        Add all items from a source array.

        References must be added in sort order, or the array must be sorted after additions are complete using sort().

        Parameters:
        src - the source array.
        off - position within src to start copying from.
        cnt - number of items to copy from src.
      • set

        public void set​(int idx,
                        T ref)
        Replace a single existing element.
        Parameters:
        idx - index, must have already been added previously.
        ref - the new reference.
      • sort

        public void sort()
        Sort the list's backing array in-place.
      • dedupe

        void dedupe​(java.util.function.BinaryOperator<T> mergeFunction)
        Dedupe the refs in place. Must be called after sort().
        Parameters:
        mergeFunction -
      • toRefList

        public RefList<T> toRefList()
        Returns:
        an unmodifiable list using this collection's backing array.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object