Class MapBackedSet<E,V>

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


    public final class MapBackedSet<E,V>
    extends Object
    implements Set<E>, Serializable
    Decorates a Map to obtain Set behaviour.

    This class is used to create a Set with the same properties as the key set of any map. Thus, a ReferenceSet can be created by wrapping a ReferenceMap in an instance of this class.

    Most map implementation can be used to create a set by passing in dummy values. Exceptions include BidiMap implementations, as they require unique values.

    Since:
    3.1
    See Also:
    Serialized Form
    • Method Detail

      • mapBackedSet

        public static <E,V> MapBackedSet<E,V> mapBackedSet(Map<E,? super V> map)
        Factory method to create a set from a map.
        Type Parameters:
        E - the element type
        V - the dummy value type in the map
        Parameters:
        map - the map to decorate, must not be null
        Returns:
        a new map backed set
        Throws:
        NullPointerException - if map is null
        Since:
        4.0
      • mapBackedSet

        public static <E,V> MapBackedSet<E,V> mapBackedSet(Map<E,? super V> map,
                                                           V dummyValue)
        Factory method to create a set from a map.
        Type Parameters:
        E - the element type
        V - the dummy value type in the map
        Parameters:
        map - the map to decorate, must not be null
        dummyValue - the dummy value to use
        Returns:
        a new map backed set
        Throws:
        NullPointerException - if map is null
        Since:
        4.0
      • size

        public int size()
      • isEmpty

        public boolean isEmpty()
      • contains

        public boolean contains(Object obj)
      • containsAll

        public boolean containsAll(Collection<?> coll)
      • add

        public boolean add(E obj)
      • addAll

        public boolean addAll(Collection<? extends E> coll)
      • remove

        public boolean remove(Object obj)
      • removeAll

        public boolean removeAll(Collection<?> coll)
      • retainAll

        public boolean retainAll(Collection<?> coll)
      • clear

        public void clear()
      • toArray

        public Object[] toArray()
      • toArray

        public <T> T[] toArray(T[] array)
      • equals

        public boolean equals(Object obj)
      • hashCode

        public int hashCode()