edu.rice.cs.plt.collect
Interface Multiset<T>

All Superinterfaces:
Collection<T>, Iterable<T>, SizedIterable<T>
All Known Implementing Classes:
HashMultiset

public interface Multiset<T>
extends Collection<T>, SizedIterable<T>

A set-like collection that allows multiple instances of a value to be represented in the collection.


Method Summary
 boolean add(T val)
          Add a single instance of val to the multiset.
 boolean add(T val, int instances)
          Add the given number of instances of val to the multiset.
 boolean addAll(Collection<? extends T> coll)
          Add all the elements of coll to this multiset.
 PredicateSet<T> asSet()
          Produce a set view of the multiset (with only one entry for each unique instance).
 void clear()
          Remove all elements from the multiset
 boolean contains(Object obj)
          Whether the multiset contains at least one instance of obj.
 boolean containsAll(Collection<?> c)
          Whether each element of the collection appears at least once in this multiset.
 int count(Object value)
          The number of times value appears in the multiset (if it does not appear, the result is 0).
 boolean equals(Object obj)
          Compares two multisets.
 boolean hasFixedSize()
          Whether the multiset can change size.
 int hashCode()
          A hash code for the multiset, computed by summing the hash codes of each element in the iterator.
 boolean isEmpty()
          Whether the multiset is empty.
 boolean isInfinite()
          Whether the iterator has an infinite number of elements.
 boolean isStatic()
          Whether the multiset will always contain the same values.
 boolean isSupersetOf(Multiset<?> s)
          Whether each element (elt) of s appears at least s.count(elt) times in this multiset.
 Iterator<T> iterator()
          An iterator for the multiset.
 boolean remove(Object obj)
          Remove a single instance of obj from the multiset, if one exists.
 boolean remove(Object obj, int instances)
          Remove the given number of instances of obj from the multiset.
 boolean removeAll(Collection<?> coll)
          Remove all the elements of coll from this multiset.
 boolean removeAllInstances(Object obj)
          Remove all instances of obj from the multiset
 boolean retainAll(Collection<?> coll)
          Remove all the elements of this multiset except those contained in coll.
 int size()
          The size of the multiset.
 int size(int bound)
          The size of the multiset bounded by the given value.
 Object[] toArray()
          Fill an array with the contents of the multiset.
<S> S[]
toArray(S[] fill)
          Fill an array with the contents of the multiset.
 

Method Detail

size

int size()
The size of the multiset.

Specified by:
size in interface Collection<T>
Specified by:
size in interface SizedIterable<T>

size

int size(int bound)
The size of the multiset bounded by the given value.

Specified by:
size in interface SizedIterable<T>
Parameters:
bound - Maximum result. Assumed to be nonnegative.

isInfinite

boolean isInfinite()
Whether the iterator has an infinite number of elements.

Specified by:
isInfinite in interface SizedIterable<T>

hasFixedSize

boolean hasFixedSize()
Whether the multiset can change size.

Specified by:
hasFixedSize in interface SizedIterable<T>

isStatic

boolean isStatic()
Whether the multiset will always contain the same values.

Specified by:
isStatic in interface SizedIterable<T>

isEmpty

boolean isEmpty()
Whether the multiset is empty.

Specified by:
isEmpty in interface Collection<T>
Specified by:
isEmpty in interface SizedIterable<T>

contains

boolean contains(Object obj)
Whether the multiset contains at least one instance of obj.

Specified by:
contains in interface Collection<T>

count

int count(Object value)
The number of times value appears in the multiset (if it does not appear, the result is 0). If the number is too large, Integer.MAX_VALUE may be returned.


asSet

PredicateSet<T> asSet()
Produce a set view of the multiset (with only one entry for each unique instance). The set will change as subsequent modifications are made to the multiset; implementations may choose to allow external modifications to the set as well.


iterator

Iterator<T> iterator()
An iterator for the multiset. If the set contains n instances of a value, that value will appear n times during iteration. Invoking remove on the iterator removes one instance.

Specified by:
iterator in interface Collection<T>
Specified by:
iterator in interface Iterable<T>

toArray

Object[] toArray()
Fill an array with the contents of the multiset.

Specified by:
toArray in interface Collection<T>

toArray

<S> S[] toArray(S[] fill)
Fill an array with the contents of the multiset.

Specified by:
toArray in interface Collection<T>

add

boolean add(T val)
Add a single instance of val to the multiset.

Specified by:
add in interface Collection<T>
Returns:
true (indicating that the multiset was modified)

add

boolean add(T val,
            int instances)
Add the given number of instances of val to the multiset.

Returns:
true (indicating that the multiset was modified)

remove

boolean remove(Object obj)
Remove a single instance of obj from the multiset, if one exists.

Specified by:
remove in interface Collection<T>
Returns:
true iff the multiset was modified

remove

boolean remove(Object obj,
               int instances)
Remove the given number of instances of obj from the multiset. If count(obj) <= instances, removes all instances of the given value.

Returns:
true iff the multiset was modified

removeAllInstances

boolean removeAllInstances(Object obj)
Remove all instances of obj from the multiset

Returns:
true iff the multiset was modified

containsAll

boolean containsAll(Collection<?> c)
Whether each element of the collection appears at least once in this multiset.

Specified by:
containsAll in interface Collection<T>

isSupersetOf

boolean isSupersetOf(Multiset<?> s)
Whether each element (elt) of s appears at least s.count(elt) times in this multiset.


addAll

boolean addAll(Collection<? extends T> coll)
Add all the elements of coll to this multiset. If the same value appears multiple times in coll, it will appear multiple times in this multiset.

Specified by:
addAll in interface Collection<T>
Returns:
true iff the multiset was successfully modified

removeAll

boolean removeAll(Collection<?> coll)
Remove all the elements of coll from this multiset. If the same value appears multiple times in coll, the same number of instances will be removed from this multiset.

Specified by:
removeAll in interface Collection<T>
Returns:
true iff the multiset was modified

retainAll

boolean retainAll(Collection<?> coll)
Remove all the elements of this multiset except those contained in coll. If the same value appears multiple times in coll, at most that number of instances will not be removed from this multiset.

Specified by:
retainAll in interface Collection<T>
Returns:
true iff the multiset was modified

clear

void clear()
Remove all elements from the multiset

Specified by:
clear in interface Collection<T>

equals

boolean equals(Object obj)
Compares two multisets. Two multisets are equal if they contain all the same values and the same number of instances of those values.

Specified by:
equals in interface Collection<T>
Overrides:
equals in class Object
Returns:
true iff obj is a multiset with the same elements as this

hashCode

int hashCode()
A hash code for the multiset, computed by summing the hash codes of each element in the iterator. (An empty multiset has hash code 0; each null element has hash code 1.)

Specified by:
hashCode in interface Collection<T>
Overrides:
hashCode in class Object