Class MapPBag<E>

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

    public final class MapPBag<E>
    extends AbstractUnmodifiableCollection<E>
    implements PBag<E>, java.io.Serializable
    A map-backed persistent bag.

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

    See Also:
    Serialized Form
    • Field Detail

      • map

        private final PMap<E,​java.lang.Integer> map
      • size

        private final int size
    • Constructor Detail

      • MapPBag

        private MapPBag​(PMap<E,​java.lang.Integer> map,
                        int size)
    • Method Detail

      • empty

        public static <E> MapPBag<E> empty​(PMap<E,​java.lang.Integer> map)
        Type Parameters:
        E -
        Parameters:
        map -
        Returns:
        a PBag backed by an empty version of map, i.e. by map.minusAll(map.keySet())
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in class java.util.AbstractCollection<E>
      • 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 class java.util.AbstractCollection<E>
      • contains

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

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Collection<E>
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object that)
        Specified by:
        equals in interface java.util.Collection<E>
        Overrides:
        equals in class java.lang.Object
      • plus

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

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

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

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

        private int count​(java.lang.Object o)
      • size

        private static int size​(PMap<?,​java.lang.Integer> map)