Class DerivedSet<B,​E>

  • Type Parameters:
    B - The type of elements in the backing set.
    E - The type of elements in this set.
    All Implemented Interfaces:
    Serializable, Iterable<E>, Collection<E>, Set<E>, CheckedCollection<E>

    public abstract class DerivedSet<B,​E>
    extends AbstractSet<E>
    implements CheckedCollection<E>, Serializable
    A set whose values are derived from an other set. The values are derived only when requested, which make it possible to backup potentially large sets. Implementations need only to overrides baseToDerived(B) and derivedToBase(E) methods. This set do not supports null value, since null is used when no mapping from base to this exists. This class is serializable if the underlying base set is serializable too.

    This class is not thread-safe. Synchronizations (if wanted) are user's reponsability.

    Since:
    2.0
    Author:
    Martin Desruisseaux (IRD)
    See Also:
    Serialized Form
    • Constructor Detail

      • DerivedSet

        public DerivedSet​(Set<B> base,
                          Class<E> derivedType)
        Creates a new derived set from the specified base set.
        Parameters:
        base - The base set.
        derivedType - The type of elements in this derived set.
        Since:
        2.5
    • Method Detail

      • baseToDerived

        protected abstract E baseToDerived​(B element)
        Transforms a value in the base set to a value in this set. If there is no mapping in the derived set for the specified element, then this method returns null.
        Parameters:
        element - A value in the base set.
        Returns:
        The value that this view should contains instead of element, or null.
      • derivedToBase

        protected abstract B derivedToBase​(E element)
        Transforms a value in this set to a value in the base set.
        Parameters:
        element - A value in this set.
        Returns:
        The value stored in the base set.
      • size

        public int size()
        Returns the number of elements in this set. The default implementation counts the number of elements returned by the iterator.
        Specified by:
        size in interface Collection<B>
        Specified by:
        size in interface Set<B>
        Specified by:
        size in class AbstractCollection<E>
        Returns:
        the number of elements in this set.
      • isEmpty

        public boolean isEmpty()
        Returns true if this set contains no elements.
        Specified by:
        isEmpty in interface Collection<B>
        Specified by:
        isEmpty in interface Set<B>
        Overrides:
        isEmpty in class AbstractCollection<E>
        Returns:
        true if this set contains no elements.
      • contains

        public boolean contains​(Object element)
        Returns true if this set contains the specified element. The default implementation invokes base.contains(derivedToBase(element)) .
        Specified by:
        contains in interface Collection<B>
        Specified by:
        contains in interface Set<B>
        Overrides:
        contains in class AbstractCollection<E>
        Parameters:
        element - object to be checked for containment in this set.
        Returns:
        true if this set contains the specified element.