mathCollection
Interface Multiset

All Superinterfaces:
java.util.Collection
All Known Implementing Classes:
AbstractMultiset, HashMultiset, MathCollections.SynchronizedMultiset

public interface Multiset
extends java.util.Collection

An extension of java.util.Collection for representing mathematical multisets.

See Also:
Collection, AbstractMultiset, HashMultiset

Method Summary
 boolean add(java.lang.Object o, int quantity)
          Adds the specified element quantity of times to this multiset.
 Multiset difference(java.util.Collection c)
          Returns the asymmetric difference between this multiset and the specified collection.
 int getQuantity(java.lang.Object o)
          Returns the number of times the specified element is present in this multiset.
 Multiset intersection(java.util.Collection c)
          Returns the intersection with the specified collection.
 boolean isDisjoint(java.util.Collection c)
          Returns true if the specified collection has no common elements with this multiset.
 boolean isSubset(java.util.Collection c)
          Returns true if this multiset is a subset of the specified collection.
 boolean isSuperset(java.util.Collection c)
          Returns true if this multiset is a superset of the specified collection.
 boolean remove(java.lang.Object o, int quantity)
          Removes the specified element quantity of times from this multiset if possible.
 boolean setQuantity(java.lang.Object o, int quantity)
          Adjusts the number of times the specified element is present in this multiset to be the specified value.
 int setSize()
          Returns the size of a 'flattened' version of this multiset in which every element of this multiset is present exactly once.
 Multiset sum(java.util.Collection c)
          Returns the sum with the specified collection.
 Multiset symmetricDifference(java.util.Collection c)
          Returns the symmetric difference between this multiset and the specified collection.
 java.util.Set toSet()
          Returns a 'flattened' version of this multiset in which every element of this multiset is present exactly once.
 Multiset union(java.util.Collection c)
          Returns the union with the specified collection.
 
Methods inherited from interface java.util.Collection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Method Detail

add

public boolean add(java.lang.Object o,
                   int quantity)
Adds the specified element quantity of times to this multiset. If quantity is negative or 0, false is returned.

Parameters:
o - element to be added to this set.
quantity - quantity of elements to add.
Returns:
true if quantity is greater than 0, false otherwise

remove

public boolean remove(java.lang.Object o,
                      int quantity)
Removes the specified element quantity of times from this multiset if possible. If quantity is negative or 0, false is returned.

Parameters:
o - object to be removed from this multiset.
quantity - quantity of elements to remove.
Returns:
true if the multiset got altered, false otherwise.

toSet

public java.util.Set toSet()
Returns a 'flattened' version of this multiset in which every element of this multiset is present exactly once.

Returns:
the 'flattened' version of this multiset.

setSize

public int setSize()
Returns the size of a 'flattened' version of this multiset in which every element of this multiset is present exactly once.

Returns:
the size of the 'flattened' version of this multiset.

getQuantity

public int getQuantity(java.lang.Object o)
Returns the number of times the specified element is present in this multiset.

Parameters:
o - element whose quantity is returned.
Returns:
quantity of the specified element, 0 if it is not present.
See Also:
setQuantity(java.lang.Object, int)

setQuantity

public boolean setQuantity(java.lang.Object o,
                           int quantity)
Adjusts the number of times the specified element is present in this multiset to be the specified value.

Parameters:
o - element whose quantity gets set.
quantity - quantity of the specified element to be set.
Returns:
true if this multiset has been modified, false otherwise.
See Also:
getQuantity(java.lang.Object)

isSuperset

public boolean isSuperset(java.util.Collection c)
Returns true if this multiset is a superset of the specified collection. That is, if all elements of the specified collection are also present in this multiset at least the same number of times.

Parameters:
c - collection for which is checked whether this multiset is a superset of or not.
Returns:
true if this multiset is a superset, false otherwise.

isSubset

public boolean isSubset(java.util.Collection c)
Returns true if this multiset is a subset of the specified collection. That is, if all elements of this multiset are also present in the specified collection at least the same number of times.

Parameters:
c - collection for which is checked whether this multiset is a subset of or not.
Returns:
true if this multiset is a subset, false otherwise.

isDisjoint

public boolean isDisjoint(java.util.Collection c)
Returns true if the specified collection has no common elements with this multiset.

Parameters:
c - collection to be checked for common elements.
Returns:
true if there are no common elements, false otherwise.

sum

public Multiset sum(java.util.Collection c)
Returns the sum with the specified collection. This is a new Multiset containing all elements that are present in this multiset or in the specified collection. The quantities of equal elements get added up.

Parameters:
c - collection to be united with.
Returns:
the union with the specified collection.

union

public Multiset union(java.util.Collection c)
Returns the union with the specified collection. This is a new Multiset containing all elements that are present in this multiset or in the specified collection. For equal elements, the resulting quantity is the maximum of the two given quantities.

Parameters:
c - collection to be united with.
Returns:
the union with the specified collection.

intersection

public Multiset intersection(java.util.Collection c)
Returns the intersection with the specified collection. This is a new Multiset containing all elements that are present in this multiset as well as in the specified collection. For equal elements, the resulting quantity is the minimum of the two given quantities.

Parameters:
c - collection to be intersected with.
Returns:
the intersection with the specified collection.

difference

public Multiset difference(java.util.Collection c)
Returns the asymmetric difference between this multiset and the specified collection. This is a new Multiset containing all elements that are present in this multiset but not in the specified collection. The quantities of equal elements get subtracted.

Parameters:
c - collection from which the difference is calculated.
Returns:
the difference with the specified collection.

symmetricDifference

public Multiset symmetricDifference(java.util.Collection c)
Returns the symmetric difference between this multiset and the specified collection. This is a new Multiset containing all elements that are present either in this multiset or in the specified collection but not in both. The quantities of equal elements get subtracted from each other (maximum minus minimum).

Parameters:
c - collection from which the symmetric difference is calculated
Returns:
the symmetric difference with the specified collection.