Class KeyCollectionImpl.KeyMap<E,K>
- java.lang.Object
-
- org.magicwerk.brownies.collections.KeyCollectionImpl.KeyMap<E,K>
-
- All Implemented Interfaces:
java.io.Serializable
- Enclosing class:
- KeyCollectionImpl<E>
static class KeyCollectionImpl.KeyMap<E,K> extends java.lang.Object implements java.io.Serializable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classKeyCollectionImpl.KeyMap.KeyMapCountIter<E,K>(package private) static classKeyCollectionImpl.KeyMap.KeyMapIter<E,K>
-
Field Summary
Fields Modifier and Type Field Description (package private) booleanallowDuplicatesTrue to allow duplicate values if they are not null(package private) booleanallowDuplicatesNullTrue to allow duplicate null values(package private) booleanallowNullTrue to allow null keys(package private) java.util.Comparator<K>comparatorComparator to use for sorting (if null, elements are not sorted)(package private) booleancountTrue to count only number of occurrences of equal elements (can only be set on keyMap[0] storing the elements)(package private) IList<K>keysListKey storage if this is a KeyListImpl sorted by this key map, otherwise null.(package private) java.util.Map<K,java.lang.Object>keysMapKey storage if not sorted.(package private) java.util.function.Function<E,K>mapperA mapper to extract keys out of element.
-
Constructor Summary
Constructors Constructor Description KeyMap()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) java.lang.Objectadd(K key, E elem)Add element to key map.(package private) voidaddThrow(K key, E elem)(package private) booleancontainsKey(java.lang.Object key)(package private) booleancontainsValue(java.lang.Object value)(package private) booleancontainsValue(java.lang.Object key, java.lang.Object value)(package private) KeyCollectionImpl.KeyMap<E,K>copy()(package private) KeyCollectionImpl.KeyMap<E,K>crop()private voiddoRemoveAllByKey(K key, KeyCollectionImpl<E> keyColl, java.util.Collection<E> coll)Removes element by key.(package private) Option<E>getContainedKey(java.lang.Object key)(package private) Option<E>getContainedValue(java.lang.Object value)(package private) java.util.Set<K>getDistinctKeys()(package private) KgetKey(E elem)(package private) booleanisPrimaryMap()(package private) java.util.Iterator<E>iteratorValues(KeyCollectionImpl<E> keyColl)(package private) Option<E>remove(java.lang.Object key, boolean matchValue, java.lang.Object value, KeyCollectionImpl keyColl)Remove element from key map.java.lang.StringtoString()
-
-
-
Field Detail
-
mapper
java.util.function.Function<E,K> mapper
A mapper to extract keys out of element. For the element itself, this is always an IdentMapper.
-
allowNull
boolean allowNull
True to allow null keys
-
allowDuplicates
boolean allowDuplicates
True to allow duplicate values if they are not null
-
allowDuplicatesNull
boolean allowDuplicatesNull
True to allow duplicate null values
-
comparator
java.util.Comparator<K> comparator
Comparator to use for sorting (if null, elements are not sorted)
-
keysMap
java.util.Map<K,java.lang.Object> keysMap
Key storage if not sorted. The values are single elements or a list of elements. Note that we cannot use TreeMap as K may not be comparable. One of keysMap or keysList is used.
-
keysList
IList<K> keysList
Key storage if this is a KeyListImpl sorted by this key map, otherwise null. One of keysMap or keysList is used.
-
count
boolean count
True to count only number of occurrences of equal elements (can only be set on keyMap[0] storing the elements)
-
-
Method Detail
-
copy
KeyCollectionImpl.KeyMap<E,K> copy()
-
crop
KeyCollectionImpl.KeyMap<E,K> crop()
-
isPrimaryMap
boolean isPrimaryMap()
-
containsKey
boolean containsKey(java.lang.Object key)
-
containsValue
boolean containsValue(java.lang.Object key, java.lang.Object value)
-
containsValue
boolean containsValue(java.lang.Object value)
-
iteratorValues
java.util.Iterator<E> iteratorValues(KeyCollectionImpl<E> keyColl)
-
add
java.lang.Object add(K key, E elem)
Add element to key map.- Parameters:
key- key of elementelem- element- Returns:
- SYMBOL_ADDED if element has successfully been added, SYMBOL_ERROR_NULL_KEY if a null key is not allowed, otherwise the key which is rejected because of a duplicate exception
-
remove
Option<E> remove(java.lang.Object key, boolean matchValue, java.lang.Object value, KeyCollectionImpl keyColl)
Remove element from key map.- Parameters:
key- key of object to removematchValue- true if value must match to remove entryvalue- value of object to removekeyColl- key collection which stores object- Returns:
- removed object
-
doRemoveAllByKey
private void doRemoveAllByKey(K key, KeyCollectionImpl<E> keyColl, java.util.Collection<E> coll)
Removes element by key. If there are duplicates, all elements are removed.- Parameters:
keyMap- key mapkey- key of element to removecoll- collection to store all removed elements, null to not store them
-
getDistinctKeys
java.util.Set<K> getDistinctKeys()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-