Package eu.bandm.tools.util.multi
Interface Multiset<A>
- Type Parameters:
A
- type of the contained elements
- All Superinterfaces:
Iterable<A>
,Serializable
- All Known Subinterfaces:
SortedMultiset<A>
- All Known Implementing Classes:
AbstractMultiset
,HashMultiset
,TreeMultiset
,UnmodifiableMultiset
Structure similar to a set, but every element can be contained more
than once.
Therefore an iterator can deliver the same element multiple times,
as often that element is contained.
Corresponds to a map from the domain type into natural numbers
(including 0).
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Add one element once to this set.boolean
Add one element multiple times to this set.default boolean
Add all elements contained in the argument to this multiset.void
clear()
Remove all objects from this instance.boolean
Returns whether a particular element is contained at least once in this set.boolean
Returns whether a particular element is contained at least once in this set.int
Returns how many times the given element is contained in this set.int
countAll
(Collection<? extends A> a) Sum up how many times the elements in the given collection are contained in this set.int
countAllUnchecked
(Collection<?> a) Sum up how many times the elements in the given collection are contained in this set.int
Returns how many times the given element is contained in this set.domain()
Returns the set of all elements contained at least once in this set.boolean
isEmpty()
Returns whether this set is empty.boolean
Remove the given element once from this set.boolean
removeAll
(Collection<? extends A> c) Remove all elements in the given collection completely from this set.boolean
removeAllUnchecked
(Collection<?> c) Remove all elements in the given collection completely from this set.boolean
removeDomain
(A a) Remove the given element completely from this set.boolean
Remove the given element completely from this set.boolean
Remove the given element once from this set.boolean
retainAll
(Collection<? extends A> c) Remove all elements not contained in the given collection completely from this set.boolean
retainAllUnchecked
(Collection<?> c) Remove all elements not contained in the given collection completely from this set.Returns a map which assigns each element contained at least once in this set to how often it is contained.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
isEmpty
boolean isEmpty()Returns whether this set is empty.- Returns:
- whether this set is empty.
-
clear
void clear()Remove all objects from this instance. -
add
Add one element once to this set. This means to increase the number of contained elements by one.- Parameters:
a
- element to add.- Returns:
- whether the Multiset has been changed.
Is defined only for a better analogy to the philosophy of
java.util.Collection,
but indeed returns always
true
.
-
addAll
Add all elements contained in the argument to this multiset.- Parameters:
other
- the other mulitset to add- Returns:
- whether the Multiset has been changed. This is the case when the argumentis not empty.
-
add
Add one element multiple times to this set. This means to increase the number of contained elements by the given mulitplicity.- Parameters:
a
- element to add.i
- number of additions. Must be greater or equal to zero.- Returns:
- whether the Multiset has been changed. This is the case when i is greater zero.
- Throws:
IllegalArgumentException
- if i is less than zero.
-
contains
Returns whether a particular element is contained at least once in this set.- Parameters:
a
- element to test.- Returns:
- whether a the given element is contained at least once in this set.
-
containsUnchecked
Returns whether a particular element is contained at least once in this set.- Parameters:
a
- element to test.- Returns:
- whether a the given element is contained at least once in this set.
-
remove
Remove the given element once from this set. That means, decrement the number of its containments if and only if it is greater than zero.- Parameters:
a
- element to remove.- Returns:
- whether this instance has changed.
-
removeUnchecked
Remove the given element once from this set. That means, decrement the number of its containments iff it is greater zero.- Parameters:
a
- element to remove.- Returns:
- whether this instance has changed.
-
removeDomain
Remove the given element completely from this set.- Parameters:
a
- element to remove.- Returns:
- whether this instance has changed.
-
removeDomainUnchecked
Remove the given element completely from this set.- Parameters:
a
- element to remove.- Returns:
- whether this instance has changed.
-
removeAll
Remove all elements in the given collection completely from this set.- Parameters:
c
- collection of all elements to remove- Returns:
- whether this instance has changed
-
removeAllUnchecked
Remove all elements in the given collection completely from this set.- Parameters:
c
- collection of all elements to remove- Returns:
- whether this instance has changed
-
retainAll
Remove all elements not contained in the given collection completely from this set.- Parameters:
c
- collection of all elements not to remove- Returns:
- whether this instance has changed
-
retainAllUnchecked
Remove all elements not contained in the given collection completely from this set.- Parameters:
c
- collection of all elements not to remove- Returns:
- whether this instance has changed
-
domain
Returns the set of all elements contained at least once in this set. It holds thatdomain().equals(supportMap().keySet())
. The result is backed by the argument. Changes to one collection are reflected by the other. When visiting this view, the ordering corresponds to that of the multiset.- Returns:
- the set of all elements contained at least once in this instance.
-
supportMap
Returns a map which assigns each element contained at least once in this set to how often it is contained. It holds that no zero is contained in the range of this map. The result is backed by the argument. Changes to one collection are reflected by the other. When visiting this view, the ordering corresponds to that of the multiset.- Returns:
- a map which assigns each element contained at least once in this instance to how often it is contained.
-
count
Returns how many times the given element is contained in this set.- Parameters:
a
- the element to test.- Returns:
- how many times the given element is contained in this set.
-
countUnchecked
Returns how many times the given element is contained in this set.- Parameters:
a
- the element to test.- Returns:
- how many times the given element is contained in this set.
-
countAll
Sum up how many times the elements in the given collection are contained in this set.- Parameters:
a
- the collection of elements to count.- Returns:
- how many times the elements in the given collection are contained in this set.
-
countAllUnchecked
Sum up how many times the elements in the given collection are contained in this set.- Parameters:
a
- the collection of elements to count.- Returns:
- how many times the elements in the given collection are contained in this set.
-