Top Description Fields Constructors Methods
org.pcollections

public final Class MapPBag<E>

extends AbstractUnmodifiableCollection<E>
implements PBag<E>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.pcollections.PBag, org.pcollections.PCollection, java.util.Collection, java.lang.Iterable
Imports
java.io.Serializable, java.util.Collection, .Iterator, .Map.Entry

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.

Author
harold

Field Summary

Modifier and TypeField and Description
private final PMap<E, Integer>
private static final long
private final int

Constructor Summary

AccessConstructor and Description
private
MapPBag(final PMap<E, Integer> map, final int size)

Method Summary

Modifier and TypeMethod and Description
public boolean
contains(final Object
element whose presence in this collection is to be tested
e
)

Overrides java.util.AbstractCollection.contains.

Implements java.util.Collection.contains.

Returns true if this collection contains the specified element.

private int
count(final Object o)

public static <E> MapPBag<E>

Returns:

a PBag backed by an empty version of map, i.e. by map.minusAll(map.keySet())
empty
(final PMap<E, Integer> map)

public boolean
equals(Object
object to be compared for equality with this collection
that
)

Overrides java.lang.Object.equals.

Implements java.util.Collection.equals.

Compares the specified object with this collection for equality.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Collection.hashCode.

Returns the hash code value for this collection.

public Iterator<E>
iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Collection.iterator.

Returns an iterator over the elements in this collection.

public MapPBag<E>
public MapPBag<E>
public MapPBag<E>
plus(final E e)

Implements org.pcollections.PBag.plus.

public MapPBag<E>
plusAll(final Collection<? extends E> list)

Implements org.pcollections.PBag.plusAll.

public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Collection.size.

Returns the number of elements in this collection.

private static int
size(final PMap<?, Integer> map)

Inherited from org.pcollections.AbstractUnmodifiableCollection:
addaddAllclearremoveremoveAllremoveIfretainAll

Field Detail

mapback to summary
private final PMap<E, Integer> map
serialVersionUIDback to summary
private static final long serialVersionUID
sizeback to summary
private final int size

Constructor Detail

MapPBagback to summary
private MapPBag(final PMap<E, Integer> map, final int size)

Method Detail

containsback to summary
public boolean contains(final Object e)

Overrides java.util.AbstractCollection.contains.

Implements java.util.Collection.contains.

Doc from java.util.Collection.contains.

Returns true if this collection contains the specified element. More formally, returns true if and only if this collection contains at least one element e such that Objects.equals(o, e).

Parameters
e:Object

element whose presence in this collection is to be tested

Returns:boolean

true if this collection contains the specified element

Annotations
@Override
countback to summary
private int count(final Object o)
Annotations
@SuppressWarnings:unchecked
emptyback to summary
public static <E> MapPBag<E> empty(final PMap<E, Integer> map)
Returns:MapPBag<E>

a PBag backed by an empty version of map, i.e. by map.minusAll(map.keySet())

equalsback to summary
public boolean equals(Object that)

Overrides java.lang.Object.equals.

Implements java.util.Collection.equals.

Doc from java.util.Collection.equals.

Compares the specified object with this collection for equality.

While the Collection interface adds no stipulations to the general contract for the Object.equals, programmers who implement the Collection interface "directly" (in other words, create a class that is a Collection but is not a Set or a List) must exercise care if they choose to override the Object.equals. It is not necessary to do so, and the simplest course of action is to rely on Object's implementation, but the implementor may wish to implement a "value comparison" in place of the default "reference comparison." (The List and Set interfaces mandate such value comparisons.)

The general contract for the Object.equals method states that equals must be symmetric (in other words, a.equals(b) if and only if b.equals(a)). The contracts for List.equals and Set.equals state that lists are only equal to other lists, and sets to other sets. Thus, a custom equals method for a collection class that implements neither the List nor Set interface must return false when this collection is compared to any list or set. (By the same logic, it is not possible to write a class that correctly implements both the Set and List interfaces.)

Parameters
that:Object

object to be compared for equality with this collection

Returns:boolean

true if the specified object is equal to this collection

Annotations
@SuppressWarnings:unchecked
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Collection.hashCode.

Doc from java.util.Collection.hashCode.

Returns the hash code value for this collection. While the Collection interface adds no stipulations to the general contract for the Object.hashCode method, programmers should take note that any class that overrides the Object.equals method must also override the Object.hashCode method in order to satisfy the general contract for the Object.hashCode method. In particular, c1.equals(c2) implies that c1.hashCode()==c2.hashCode().

Returns:int

the hash code value for this collection

Annotations
@Override
iteratorback to summary
public Iterator<E> iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Collection.iterator.

Doc from java.util.Collection.iterator.

Returns an iterator over the elements in this collection. There are no guarantees concerning the order in which the elements are returned (unless this collection is an instance of some class that provides a guarantee).

Returns:Iterator<E>

an Iterator over the elements in this collection

Annotations
@Override
minusback to summary
public MapPBag<E> minus(final Object e)

Implements org.pcollections.PBag.minus.

Returns:MapPBag<E>

Doc from org.pcollections.PCollection.minus.

this with a single instance of e removed, if e is in this

Annotations
@SuppressWarnings:unchecked
minusAllback to summary
public MapPBag<E> minusAll(final Collection<?> list)

Implements org.pcollections.PBag.minusAll.

Returns:MapPBag<E>

Doc from org.pcollections.PCollection.minusAll.

this with all elements of list completely removed

plusback to summary
public MapPBag<E> plus(final E e)

Implements org.pcollections.PBag.plus.

Returns:MapPBag<E>

Doc from org.pcollections.PCollection.plus.

a collection which contains e and all of the elements of this

plusAllback to summary
public MapPBag<E> plusAll(final Collection<? extends E> list)

Implements org.pcollections.PBag.plusAll.

Returns:MapPBag<E>

Doc from org.pcollections.PCollection.plusAll.

a collection which contains all of the elements of list and this

sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Collection.size.

Doc from java.util.Collection.size.

Returns the number of elements in this collection. If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this collection

Annotations
@Override
sizeback to summary
private static int size(final PMap<?, Integer> map)