Class MapPSet<E>

  • Type Parameters:
    E -
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>, PCollection<E>, PSet<E>

    public final class MapPSet<E>
    extends AbstractUnmodifiableSet<E>
    implements PSet<E>, java.io.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:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  MapPSet.In  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private PMap<E,​java.lang.Object> map  
      private static long serialVersionUID  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private MapPSet​(PMap<E,​java.lang.Object> map)  
    • Field Detail

      • map

        private final PMap<E,​java.lang.Object> map
    • Constructor Detail

      • MapPSet

        private MapPSet​(PMap<E,​java.lang.Object> map)
    • Method Detail

      • 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,
                                          java.util.Collection<? extends E> list)
        Type Parameters:
        E -
        Parameters:
        map -
        list -
        Returns:
        from(map).plusAll(list)
      • iterator

        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in interface java.util.Set<E>
        Specified by:
        iterator in class java.util.AbstractCollection<E>
      • size

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

        public boolean contains​(java.lang.Object e)
        Specified by:
        contains in interface java.util.Collection<E>
        Specified by:
        contains in interface java.util.Set<E>
        Overrides:
        contains in class java.util.AbstractCollection<E>
      • plus

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

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

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

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

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