Package org.apache.commons.collections4.set

# Class MapBackedSet<E,V>

java.lang.Object
org.apache.commons.collections4.set.MapBackedSet<E,V>

Type Parameters:
  `E` - the type of the elements in this set
  `V` - the dummy value type in this map

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` behavior.

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 Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `add(E obj)`
  `boolean`
  `addAll(Collection<? extends E> coll)`
  `void`
  `clear()`
  `boolean`
  `contains(Object obj)`
  `boolean`
  `containsAll(Collection<?> coll)`
  `boolean`
  `equals(Object obj)`
  `int`
  `hashCode()`
  `boolean`
  `isEmpty()`
  `Iterator<E>`
  `iterator()`
  `static <E, V> MapBackedSet<E,V>`
  `mapBackedSet(Map<E,? super V> map)`
  Factory method to create a set from a map.
  `static <E, V> MapBackedSet<E,V>`
  `mapBackedSet(Map<E,? super V> map, V dummyValue)`
  Factory method to create a set from a map.
  `boolean`
  `remove(Object obj)`
  `boolean`
  `removeAll(Collection<?> coll)`
  `boolean`
  `removeIf(Predicate<? super E> filter)`
  `boolean`
  `retainAll(Collection<?> coll)`
  `int`
  `size()`
  `Object[]`
  `toArray()`
  `<T> T[]`
  `toArray(T[] array)`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface java.util.Collection

  `parallelStream, stream`

  ### Methods inherited from interface java.lang.Iterable

  `forEach`

  ### Methods inherited from interface java.util.Set

  `spliterator`

- ## Method Details

  - ### 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

  - ### add

    public boolean add(E obj)
    Specified by:
      `add` in interface `Collection<E>`
    Specified by:
      `add` in interface `Set<E>`

  - ### addAll

    public boolean addAll(Collection<? extends E> coll)
    Specified by:
      `addAll` in interface `Collection<E>`
    Specified by:
      `addAll` in interface `Set<E>`

  - ### clear

    public void clear()
    Specified by:
      `clear` in interface `Collection<E>`
    Specified by:
      `clear` in interface `Set<E>`

  - ### contains

    public boolean contains(Object obj)
    Specified by:
      `contains` in interface `Collection<E>`
    Specified by:
      `contains` in interface `Set<E>`

  - ### containsAll

    public boolean containsAll(Collection<?> coll)
    Specified by:
      `containsAll` in interface `Collection<E>`
    Specified by:
      `containsAll` in interface `Set<E>`

  - ### equals

    public boolean equals(Object obj)
    Specified by:
      `equals` in interface `Collection<E>`
    Specified by:
      `equals` in interface `Set<E>`
    Overrides:
      `equals` in class `Object`

  - ### hashCode

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

  - ### isEmpty

    public boolean isEmpty()
    Specified by:
      `isEmpty` in interface `Collection<E>`
    Specified by:
      `isEmpty` in interface `Set<E>`

  - ### iterator

    public Iterator<E> iterator()
    Specified by:
      `iterator` in interface `Collection<E>`
    Specified by:
      `iterator` in interface `Iterable<E>`
    Specified by:
      `iterator` in interface `Set<E>`

  - ### remove

    public boolean remove(Object obj)
    Specified by:
      `remove` in interface `Collection<E>`
    Specified by:
      `remove` in interface `Set<E>`

  - ### removeAll

    public boolean removeAll(Collection<?> coll)
    Specified by:
      `removeAll` in interface `Collection<E>`
    Specified by:
      `removeAll` in interface `Set<E>`

  - ### removeIf

    public boolean removeIf(Predicate<? super E> filter)
    Specified by:
      `removeIf` in interface `Collection<E>`
    Since:
      4.4

  - ### retainAll

    public boolean retainAll(Collection<?> coll)
    Specified by:
      `retainAll` in interface `Collection<E>`
    Specified by:
      `retainAll` in interface `Set<E>`

  - ### size

    public int size()
    Specified by:
      `size` in interface `Collection<E>`
    Specified by:
      `size` in interface `Set<E>`

  - ### toArray

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

  - ### toArray

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