Package eu.bandm.tools.util.multi
Class AbstractMultiset<A>
java.lang.Object
eu.bandm.tools.util.multi.AbstractMultiset<A>
- Type Parameters:
A
- type of the contained elements
- All Implemented Interfaces:
Multiset<A>
,Serializable
,Iterable<A>
- Direct Known Subclasses:
HashMultiset
,TreeMultiset
Common superclass for sorted and unsorted domains.
- See Also:
-
Field Summary
Fields inherited from interface eu.bandm.tools.util.multi.Multiset
DEFAULT_MULTI_FORMAT_STRING, DEFAULT_SINGLE_FORMAT_STRING
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Add one element once to this set.boolean
Add one element multiple times to this set.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> c) Sum up how many times the elements in the given collection are contained in this set.int
countAllUnchecked
(Collection<?> c) 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.iterator()
map()
Returns the supporting map.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.toString()
Returns a string representation of this instance.protected int
Returns how often the given object is contained in this set, including zero times.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
AbstractMultiset
protected AbstractMultiset()Only constructor
-
-
Method Details
-
map
Returns the supporting map. That map Realizes containment by mapping every contained object to a number greater than zero, how often it is contained in this instance.- Returns:
- the supporting map.
-
isEmpty
public boolean isEmpty()Returns whether this set is empty. -
clear
public void clear()Remove all objects from this instance. -
xget
Returns how often the given object is contained in this set, including zero times.- Parameters:
a
- the object to test- Returns:
- how often the given object is contained in this set, including zero times.
-
add
Add one element once to this set. This means to increase the number of contained elements by one. -
add
Add one element multiple times to this set. This means to increase the number of contained elements by the given mulitplicity. -
contains
Returns whether a particular element is contained at least once in this set. -
containsUnchecked
Returns whether a particular element is contained at least once in this set.- Specified by:
containsUnchecked
in interfaceMultiset<A>
- 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. -
removeUnchecked
Remove the given element once from this set. That means, decrement the number of its containments iff it is greater zero.- Specified by:
removeUnchecked
in interfaceMultiset<A>
- Parameters:
a
- element to remove.- Returns:
- whether this instance has changed.
-
removeDomain
Remove the given element completely from this set.- Specified by:
removeDomain
in interfaceMultiset<A>
- Parameters:
a
- element to remove.- Returns:
- whether this instance has changed.
-
removeDomainUnchecked
Remove the given element completely from this set.- Specified by:
removeDomainUnchecked
in interfaceMultiset<A>
- Parameters:
a
- element to remove.- Returns:
- whether this instance has changed.
-
removeAll
Remove all elements in the given collection completely from this set. -
removeAllUnchecked
Remove all elements in the given collection completely from this set.- Specified by:
removeAllUnchecked
in interfaceMultiset<A>
- 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. -
retainAllUnchecked
Remove all elements not contained in the given collection completely from this set.- Specified by:
retainAllUnchecked
in interfaceMultiset<A>
- Parameters:
c
- collection of all elements not to remove- Returns:
- whether this instance has changed
-
count
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.- Specified by:
countUnchecked
in interfaceMultiset<A>
- Parameters:
o
- 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. -
countAllUnchecked
Sum up how many times the elements in the given collection are contained in this set.- Specified by:
countAllUnchecked
in interfaceMultiset<A>
- Parameters:
c
- the collection of elements to count.- Returns:
- how many times the elements in the given collection are contained in this set.
-
iterator
-
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. -
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.- Specified by:
supportMap
in interfaceMultiset<A>
- Returns:
- a map which assigns each element contained at least once in this instance to how often it is contained.
-
toString
Returns a string representation of this instance. CallsMultiset.toString(java.lang.String, java.lang.String)
with the argumentssMultiset.DEFAULT_MULTI_FORMAT_STRING
andMultiset.DEFAULT_SINGLE_FORMAT_STRING
.
-