Class SubSet<E>

  • All Implemented Interfaces:
    Cloneable, Iterable<E>, Collection<E>, Set<E>

    public class SubSet<E>
    extends AbstractSet<E>
    implements Cloneable
    Implements a set which is based on another set, which is assumed to be immutable. The SubSet is assumed to be a subset of the underlying set, and optimizes for both remove and retain operations. If the underlying (original) set is sorted, the SubSet's iterator() will iterate items in the ascending order.

    This implementation is not thread-safe.

    cp 2003.01.29
    • Field Detail


        protected static final Object[] EMPTY_ARRAY
        An empty immutable array.
      • m_setOrig

        protected Set<E> m_setOrig
        The underlying set (assumed immutable).
      • m_setMod

        protected Set<E> m_setMod
        The removed or retained items.
      • m_fRetained

        protected boolean m_fRetained
        Toggles between whether the modifications are removed or retained.
    • Constructor Detail

      • SubSet

        public SubSet​(Set<? extends E> set)
        Construct this set based on an existing set.
        set - the set to base this subset on
    • Method Detail

      • getOriginal

        public Set<? extends E> getOriginal()
        Determine what items were in the original set.
        the set used to construct this SubSet
      • isModified

        public boolean isModified()
        Determine if the set has been modified.
        true if any items have been removed
      • isTrackingRetained

        public boolean isTrackingRetained()
        Determine if the SubSet is tracking retained items versus removed items.
        true if the SubSet is tracking just the retained items, false if the SubSet is tracking just the removed items
      • getRetained

        public Set<E> getRetained()
        Determine what items were added to the subset. Do not modify the returned set.
        a set of retained items
      • getRemoved

        public Set<E> getRemoved()
        Determine what items were removed from the subset.
        an immutable set of removed items
      • instantiateModificationSet

        protected Set<E> instantiateModificationSet​(int cSize)
        Instantiate a new modification set containing either removed or retained items.
        cSize - an initial size of the modification set
      • ensureRetained

        protected Set<E> ensureRetained()
        Get a mutable set of items that are retained in the subset.
        a mutable set of retained items
      • ensureRemoved

        protected Set<E> ensureRemoved()
        Get a mutable set of items that are removed in the subset.
        a mutable set of removed items
      • resolve

        public void resolve()
        Apply the changes to the underlying set ("commit").
      • reset

        public void reset()
        Discard the changes to the set ("rollback").
      • resetState

        protected void resetState​(Set setOrig,
                                  Set setMod,
                                  boolean fRetained)
        Reset the state of the subset according to the specified parameters.
        setOrig - the new original set
        setMod - the set of removed or retained entries, depending on the fRetained flag
        fRetained - if true setMod contains the retained entries; otherwise the removed entries
      • clone

        public Object clone()
        Clone the subset.
        clone in class Object
        a clone of this subset
      • retainAllInternal

        protected void retainAllInternal​(Collection colOuter,
                                         Collection colMatch,
                                         Set setExclude)
        Instantiate a new retained set with all elements in the specified collection that also exist in the provided colMatch collection and are not excluded.
        colOuter - collection to iterate
        colMatch - each element in colOuter should be present in this collection such that (colOuter ∩ colMatch)
        setExclude - optional set of excluded elements