public class JavaBagMemory<T> extends java.util.HashMap<T,java.lang.Integer> implements IMultiset<T>
Inherits from java.util.HashMap to realize a Object-to-Int map and counts the number of occurrences of each value. Element is deleted if # of occurences drops to 0.
Constructor and Description |
---|
JavaBagMemory() |
Modifier and Type | Method and Description |
---|---|
boolean |
addOne(T value)
Adds one value occurrence to the memory.
|
boolean |
addPositive(T value,
int count)
Adds the given number of occurrences to the memory.
|
boolean |
addSigned(T value,
int count)
Adds the given number of occurrences to the memory.
|
void |
clearAllOf(T value)
Removes all occurrences of the given value from the memory.
|
boolean |
containsNonZero(T value) |
int |
getCount(T value)
Returns the number of occurrences of the given value.
|
java.util.Iterator<T> |
iterator() |
boolean |
removeOne(T value)
Removes one occurrence of the given value from the memory.
|
java.lang.String |
toString() |
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
finalize, getClass, notify, notifyAll, wait, wait, wait
public int getCount(T value)
IMemory
public boolean containsNonZero(T value)
containsNonZero
in interface IMemory<T>
public boolean addOne(T value)
IMemory
public boolean addPositive(T value, int count)
IMultiset
addPositive
in interface IMultiset<T>
count
- the number of occurrencespublic boolean addSigned(T value, int count)
IMemory
Precondition if IMultiset
: at least the given amount of occurrences exist, if count is negative.
public boolean removeOne(T value)
IMemory
Precondition if IMultiset
: the value must have a positive amount of occurrences in the memory.
public void clearAllOf(T value)
IMemory
clearAllOf
in interface IMemory<T>
public java.util.Iterator<T> iterator()
iterator
in interface java.lang.Iterable<T>
public java.lang.String toString()
toString
in class java.util.AbstractMap<T,java.lang.Integer>