Class SuperCollection<E>

java.lang.Object
net.glowstone.util.collection.SuperCollection<E>
All Implemented Interfaces:
Iterable<E>, Collection<E>
Direct Known Subclasses:
SuperList, SuperSet

public abstract class SuperCollection<E> extends Object implements Collection<E>
Generic super collection. This is an abstract collection which delegates (ie redirects operations) to other collections (its children). This class is employed to reduce the overhead of copying objects from several collections to create a new larger one.

This class is a generic collection which serves as a base for other super collections. It handles non-indexed accesses to collections like additions, removals, contains...

Note that because this collection holds references to other collections, modifications to children will be reflected here. Also, modifications to this collection will affect its children.

If you need a collection that has the very same contents but isn't affected by operations to children, you can employ the asClone() method, which returns a new collection with the same contents.

Since there are several children and not all may return the same return value for certain operations, you can control how this class behaves by means of the setResultMode(ResultMode) method. It defaults to ANY, so operations that return booleans will return true as long as at least one children succeeded.

  • Constructor Details

  • Method Details

    • getParents

      public List<? extends Collection<E>> getParents()
      Returns the list of parents.
      Returns:
      Parent list.
    • asClone

      public abstract Collection<E> asClone()
      Returns a new collection with the same contents as the parents.
      Returns:
      New mutable collection.
    • getCollectionClass

      protected abstract Class<? extends Collection> getCollectionClass()
      Returns the class this SuperCollection implements.
      Returns:
      Collection class.
    • resultBoolean

      protected boolean resultBoolean(int modified)
    • add

      public boolean add(E object)
      Specified by:
      add in interface Collection<E>
    • addAll

      public boolean addAll(Collection<? extends E> objects)
      Specified by:
      addAll in interface Collection<E>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<E>
    • contains

      public boolean contains(Object object)
      Specified by:
      contains in interface Collection<E>
    • containsAll

      public boolean containsAll(Collection<?> objects)
      Specified by:
      containsAll in interface Collection<E>
    • equals

      public boolean equals(Object object)
      Specified by:
      equals in interface Collection<E>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Collection<E>
      Overrides:
      hashCode in class Object
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<E>
    • iterator

      public Iterator<E> iterator()
      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
    • remove

      public boolean remove(Object object)
      Specified by:
      remove in interface Collection<E>
    • removeAll

      public boolean removeAll(Collection<?> objects)
      Specified by:
      removeAll in interface Collection<E>
    • retainAll

      public boolean retainAll(Collection<?> objects)
      Specified by:
      retainAll in interface Collection<E>
    • size

      public int size()
      Specified by:
      size in interface Collection<E>
    • toArray

      public Object[] toArray()
      Specified by:
      toArray in interface Collection<E>
    • toArray

      public <T> T[] toArray(T[] array)
      Specified by:
      toArray in interface Collection<E>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getResultMode

      public SuperCollection.ResultMode getResultMode()
      Current result mode.

      If mode is set to ANY, operations will return "true" as long as the parents returned "true" at least once.

      If mode is set to ALL, operations will only return "true" if all parents also returned "true".

      Returns:
      Result mode.
    • setResultMode

      public void setResultMode(SuperCollection.ResultMode resultMode)
      Current result mode.

      If mode is set to ANY, operations will return "true" as long as the parents returned "true" at least once.

      If mode is set to ALL, operations will only return "true" if all parents also returned "true".

      Parameters:
      resultMode - Result mode.
    • getAdditionMode

      public SuperCollection.AdditionMode getAdditionMode()
      Determines how this collection will behave to additions.

      If mode is set to ALL, the addition will be performed on every parent. Default for sets.

      If mode is set to LAST, the operation will be performed on the last parent only. Default for lists.

      Returns:
      Addition mode.
    • setAdditionMode

      public void setAdditionMode(SuperCollection.AdditionMode additionMode)
      Determines how this collection will behave to additions.

      If mode is set to ALL, the addition will be performed on every parent. Default for sets.

      If mode is set to LAST, the operation will be performed on the last parent only. Default for lists.

      Parameters:
      additionMode - Addition mode.