Class MapPSet<E>

Type Parameters:
E -
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, Set<E>, PCollection<E>, PSet<E>

public final class MapPSet<E> extends AbstractUnmodifiableSet<E> implements PSet<E>, Serializable
A map-backed persistent set.

If the backing map is thread-safe, then this implementation is thread-safe (assuming Java's AbstractSet is thread-safe), although its iterators may not be.

See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • map

      private final PMap<E,Object> map
      / PRIVATE CONSTRUCTORS ////
  • Constructor Details

  • Method Details

    • from

      public static <E> MapPSet<E> from(PMap<E,?> map)
      Type Parameters:
      E -
      Parameters:
      map -
      Returns:
      a PSet with the elements of map.keySet(), backed by map
    • from

      public static <E> MapPSet<E> from(PMap<E,?> map, E e)
      Type Parameters:
      E -
      Parameters:
      map -
      e -
      Returns:
      from(map).plus(e)
    • from

      public static <E> MapPSet<E> from(PMap<E,?> map, Collection<? extends E> list)
      Type Parameters:
      E -
      Parameters:
      map -
      list -
      Returns:
      from(map).plusAll(list)
    • iterator

      public Iterator<E> iterator()
      / REQUIRED METHODS FROM AbstractSet ////
      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
      Specified by:
      iterator in interface Set<E>
      Specified by:
      iterator in class AbstractCollection<E>
    • size

      public int size()
      Specified by:
      size in interface Collection<E>
      Specified by:
      size in interface Set<E>
      Specified by:
      size in class AbstractCollection<E>
    • contains

      public boolean contains(Object e)
      / OVERRIDDEN METHODS OF AbstractSet ////
      Specified by:
      contains in interface Collection<E>
      Specified by:
      contains in interface Set<E>
      Overrides:
      contains in class AbstractCollection<E>
    • plus

      public MapPSet<E> plus(E e)
      Specified by:
      plus in interface PCollection<E>
      Specified by:
      plus in interface PSet<E>
      Parameters:
      e -
      Returns:
      a collection which contains e and all of the elements of this
    • minus

      public MapPSet<E> minus(Object e)
      Specified by:
      minus in interface PCollection<E>
      Specified by:
      minus in interface PSet<E>
      Parameters:
      e -
      Returns:
      this with a single instance of e removed, if e is in this
    • plusAll

      public MapPSet<E> plusAll(Collection<? extends E> list)
      Specified by:
      plusAll in interface PCollection<E>
      Specified by:
      plusAll in interface PSet<E>
      Parameters:
      list -
      Returns:
      a collection which contains all of the elements of list and this
    • minusAll

      public MapPSet<E> minusAll(Collection<?> list)
      Specified by:
      minusAll in interface PCollection<E>
      Specified by:
      minusAll in interface PSet<E>
      Parameters:
      list -
      Returns:
      this with all elements of list completely removed
    • intersect

      public MapPSet<E> intersect(Collection<? extends E> list)
      Specified by:
      intersect in interface PSet<E>
      Returns:
      the equivalent of this.minusAll(this.minusAll(list)).