Class KeyCollectionImpl<E>
- java.lang.Object
-
- org.magicwerk.brownies.collections.KeyCollectionImpl<E>
-
- Type Parameters:
E- type of elements stored in the list
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<E>,java.util.Collection<E>,ICollection<E>
- Direct Known Subclasses:
Key1Collection,Key2Collection,KeyCollection
public class KeyCollectionImpl<E> extends java.lang.Object implements ICollection<E>, java.io.Serializable, java.lang.Cloneable
Add: - validation fails: null / constraint - duplicate not allowed (mode replace) Triggers: - triggers are called after the add/remove operation has finished - if an exception is thrown in the trigger, the change already made to the collection is not undone- See Also:
GapList, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classKeyCollectionImpl.BuilderImpl<E>Implementation of builder.(package private) static classKeyCollectionImpl.KeyMap<E,K>(package private) static classKeyCollectionImpl.KeyMapList<E>List type used to store multiple elements.
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.function.Consumer<E>afterDeleteTrigger(package private) java.util.function.Consumer<E>afterInsertTrigger(package private) booleanallowNullElemTrue to allow null elements, false to reject them.(package private) java.util.function.Consumer<E>beforeDeleteTrigger(package private) java.util.function.Consumer<E>beforeInsertTrigger(package private) java.util.function.Predicate<E>constraintAll elements in the list must fulfill this predicate, if null, all elements are allowedprivate static booleanDEBUG_CHECKIf true the invariants are checked for debugging(package private) KeyListImpl<E>keyListBack pointer to KeyListImpl if this object is used to implement a KeyList, Key1List, Key2List.(package private) KeyCollectionImpl.KeyMap<E,java.lang.Object>[]keyMapsMaps for element and all defined keys.(package private) intmaxSizeMaximum absolute or windows size, 0 if this list has no size restriction(package private) booleanmovingWindowIf maxSize is greater than 0, this boolean indicates whether the size is for window (true) or absolute (false)(package private) intorderByKeyIndex of key map which defines order (-1 for no order, only possible for KeyList).(package private) booleansetBehaviortrue if collections implementsSet, false for @{link Collection} (behavior ofadd(E)changes)(package private) intsizeSize of collection.(package private) static java.lang.ObjectSYMBOL_ADDED(package private) static java.lang.ObjectSYMBOL_ERROR_NULL_KEY(package private) static java.lang.ObjectSYMBOL_NOT_ADDED
-
Constructor Summary
Constructors Constructor Description KeyCollectionImpl()Private constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E elem)booleanaddAll(java.util.Collection<? extends E> c)(package private) voidaddSorted(int index, E elem)Called from KeyListImpl.doAdd() to add element to sorted list.(package private) voidaddUnsorted(E elem)Called from KeyListImpl.doAdd() to add element to sorted list.private voidafterDelete(E elem)This method is called after an existing element has been removed.private voidafterInsert(E elem)This method is called after a new element has been added.java.util.Set<E>asSet()Returns a Set view of the element set.private voidbeforeDelete(E elem)This method is called before an existing element is removed.private voidbeforeInsert(E elem)This method is called before a new element is added.(package private) intbinarySearchSorted(E elem)(package private) voidcheckAddElem(E elem)(package private) voidcheckAsMap(int keyIndex)Check whether the key map can be viewed as Map.(package private) voidcheckAsSet()Check whether the element set can be viewed as Set.(package private) voidcheckElemAllowed(E elem)Checks whether element is allowed in collection (null/constraint).(package private) voidcheckIndex(int loIndex, int hiIndex, E elem)Check whether index is valid for the sorted list.(package private) voidcheckKeyMap(int keyIndex)Check whether there is a KeyMap (can also be the elements set) with specified index.voidclear()protected java.lang.Objectclone()booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection<?> c)protected <K> booleancontainsKey(int keyIndex, K key)Checks whether the specified key exists in this list.KeyCollectionImplcopy()Returns a copy of this collection with all its elements.KeyCollectionImplcrop()Returns a copy of this collection but without elements.(package private) voiddebugCheck()Private method to check invariant of KeyCollectionImpl.protected booleandoAdd(E elem)Helper method for adding an element to the collection.(package private) java.lang.ObjectdoAdd(E elem, KeyCollectionImpl.KeyMap<?,?> ignore)Add element.(package private) booleandoAddThrow(E elem, KeyCollectionImpl.KeyMap<?,?> ignore)private voiddoClear(KeyCollectionImpl.KeyMap<E,?> keyMap)private voiddoDebugCheck(KeyCollectionImpl.KeyMap keyMap)private <K> voiddoGetAllByKey(KeyCollectionImpl.KeyMap<E,K> keyMap, K key, java.util.Collection<E> coll)(package private) EdoInvalidateKey(int keyIndex, java.lang.Object oldKey, java.lang.Object newKey, E elem)(package private) Option<E>doRemove(java.lang.Object elem, KeyCollectionImpl.KeyMap ignore)Remove element.protected Option<E>doRemoveByKey(int keyIndex, java.lang.Object key)Removes element by key.booleanequals(java.lang.Object o)(package private) static voiderrorConstraintElement()(package private) static voiderrorDuplicateKey(java.lang.Object key)(package private) static voiderrorInvalidateNotSupported()(package private) static voiderrorInvalidData()(package private) static voiderrorInvalidIndex()(package private) static voiderrorInvalidSetBehavior()(package private) static voiderrorInvaliDuplicates()(package private) static voiderrorMaxSize()(package private) static voiderrorNullElement()(package private) static voiderrorNullKey()KeyCollectionImplfilter(java.util.function.Predicate<? super E> predicate)Create a new collection by applying the specified filter to all elements.<R> IList<R>filterMap(java.util.function.Predicate<E> filter, java.util.function.Function<E,R> func)Create a new list by applying the specified filter first and then the mapping function to all elements selected.<R,C extends java.util.Collection<R>>
IList<R>flatMap(java.util.function.Function<E,C> func)Create a new list by applying the specified mapping function to all elements.java.util.Collection<E>getAll(E elem)Returns all equal elements.protected java.util.Collection<E>getAllByKey(int keyIndex, java.lang.Object key)Returns a collection with all elements with the specified key.protected voidgetAllByKey(int keyIndex, java.lang.Object key, java.util.Collection<E> coll)Fill the collection with all elements with the specified key.protected IList<?>getAllKeys(int keyIndex)Returns list containing all keys in element order.protected EgetByKey(int keyIndex, java.lang.Object key)Returns value for specified key.private <K> EgetByKey(KeyCollectionImpl.KeyMap<E,K> keyMap, K key)intgetCount(E elem)Returns the number of equal elements.protected intgetCountByKey(int keyIndex, java.lang.Object key)Returns number of elements with specified key.private <K> intgetCountByKey(KeyCollectionImpl.KeyMap<E,K> keyMap, K key)java.util.Set<E>getDistinct()Returns all distinct elements in the same order as in the collection.protected java.util.Set<?>getDistinctKeys(int keyIndex)Returns set containing all distinct keys.(package private) java.util.Comparator<java.lang.Object>getElemSortComparator()(package private) java.lang.ObjectgetKey(int keyIndex, E elem)(package private) KeyCollectionImpl.KeyMap<E,java.lang.Object>getKeyMap(int keyIndex)protected java.util.function.Function<E,java.lang.Object>getKeyMapper(int keyIndex)Returns mapper for specified key map.(package private) booleanhasElemSet()inthashCode()(package private) intindexOfSorted(E elem)protected voidinitClone(java.lang.Object that)Initialize this object after the bitwise copy has been made by Object.clone().(package private) voidinitCopy(KeyCollectionImpl<E> that)Initialize object for copy() operation.(package private) voidinitCrop(KeyCollectionImpl<E> that)Initialize object for crop() operation.protected voidinvalidate(E elem)Invalidate element, i.e.private Option<java.lang.Object>invalidate(KeyCollectionImpl.KeyMap keyMap, java.lang.Object elem)protected voidinvalidateKey(int keyIndex, java.lang.Object oldKey, java.lang.Object newKey, E elem)Invalidate key value of element.(package private) booleanisContainsFast()Determines whether calling contains() will be fast, i.e.booleanisEmpty()booleanisSorted()Determines whether this list is sorted or not.(package private) booleanisSortedByElem()java.util.Iterator<E>iterator()<R> IList<R>map(java.util.function.Function<E,R> func)Create a new list by applying the specified mapping function to all elements.<R> IList<R>mapFilter(java.util.function.Function<E,R> func, java.util.function.Predicate<R> filter)Create a new list by applying the specified mapping function to all elements and then filtering it.protected Eput(E elem)Adds or replaces element.protected EputByKey(int keyIndex, E elem, boolean replace)booleanremove(java.lang.Object elem)(package private) booleanremove(java.lang.Object elem, KeyCollectionImpl.KeyMap ignore)Remove element.java.util.Collection<E>removeAll(E elem)Removes all equal elements.booleanremoveAll(java.util.Collection<?> c)protected java.util.Collection<E>removeAllByKey(int keyIndex, java.lang.Object key)Removes element by key.protected voidremoveAllByKey(int keyIndex, java.lang.Object key, java.util.Collection<E> removeds)protected EremoveByKey(int keyIndex, java.lang.Object key)booleanretainAll(java.util.Collection<?> c)(package private) voidsetSorted(int index, E elem, E oldElem)intsize()java.lang.Object[]toArray()<T> T[]toArray(T[] a)GapList<E>toList()Returns all elements contained in this collection as list.java.lang.StringtoString()-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray
-
Methods inherited from interface org.magicwerk.brownies.collections.ICollection
containsIf, countIf, getFirst, getFirstOrNull, getIf, getSingle, getSingleOrNull
-
-
-
-
Field Detail
-
SYMBOL_ADDED
static final java.lang.Object SYMBOL_ADDED
-
SYMBOL_NOT_ADDED
static final java.lang.Object SYMBOL_NOT_ADDED
-
SYMBOL_ERROR_NULL_KEY
static final java.lang.Object SYMBOL_ERROR_NULL_KEY
-
DEBUG_CHECK
private static final boolean DEBUG_CHECK
If true the invariants are checked for debugging- See Also:
- Constant Field Values
-
size
int size
Size of collection. The size is cached, as the key maps do not know the size if duplicates are allowed.
-
maxSize
int maxSize
Maximum absolute or windows size, 0 if this list has no size restriction
-
movingWindow
boolean movingWindow
If maxSize is greater than 0, this boolean indicates whether the size is for window (true) or absolute (false)
-
keyMaps
KeyCollectionImpl.KeyMap<E,java.lang.Object>[] keyMaps
Maps for element and all defined keys. keyMaps may be null for a KeyListImpl without keys. Index 0 is reserved for the elem key using an IdentMapper. If there is no elem key, keyMaps[0] contains null.
-
orderByKey
int orderByKey
Index of key map which defines order (-1 for no order, only possible for KeyList). If an order key is defined for a KeyList, it must be implemented as KeyMap.keysList.
-
allowNullElem
boolean allowNullElem
True to allow null elements, false to reject them.
-
setBehavior
boolean setBehavior
true if collections implementsSet, false for @{link Collection} (behavior ofadd(E)changes)
-
constraint
java.util.function.Predicate<E> constraint
All elements in the list must fulfill this predicate, if null, all elements are allowed
-
beforeInsertTrigger
java.util.function.Consumer<E> beforeInsertTrigger
-
afterInsertTrigger
java.util.function.Consumer<E> afterInsertTrigger
-
beforeDeleteTrigger
java.util.function.Consumer<E> beforeDeleteTrigger
-
afterDeleteTrigger
java.util.function.Consumer<E> afterDeleteTrigger
-
keyList
KeyListImpl<E> keyList
Back pointer to KeyListImpl if this object is used to implement a KeyList, Key1List, Key2List. Otherwise null if it is part of a KeyCollection, Key1Collection, Key2Collection.
-
-
Method Detail
-
initCopy
void initCopy(KeyCollectionImpl<E> that)
Initialize object for copy() operation.- Parameters:
that- source object
-
initCrop
void initCrop(KeyCollectionImpl<E> that)
Initialize object for crop() operation.- Parameters:
that- source object
-
debugCheck
void debugCheck()
Private method to check invariant of KeyCollectionImpl. It is only used for debugging.
-
doDebugCheck
private void doDebugCheck(KeyCollectionImpl.KeyMap keyMap)
-
getKey
java.lang.Object getKey(int keyIndex, E elem)
-
isSorted
public boolean isSorted()
Determines whether this list is sorted or not.- Returns:
- true if this a sorted list, false if not
-
isSortedByElem
boolean isSortedByElem()
-
getElemSortComparator
java.util.Comparator<java.lang.Object> getElemSortComparator()
-
hasElemSet
boolean hasElemSet()
-
checkIndex
void checkIndex(int loIndex, int hiIndex, E elem)Check whether index is valid for the sorted list.
-
addSorted
void addSorted(int index, E elem)Called from KeyListImpl.doAdd() to add element to sorted list. It calls beforeInsert() and afterInsert() as needed.- Parameters:
index- index where element will be addedelem- element to add
-
addUnsorted
void addUnsorted(E elem)
Called from KeyListImpl.doAdd() to add element to sorted list. It calls beforeInsert() and afterInsert() as needed.- Parameters:
elem- element to add
-
binarySearchSorted
int binarySearchSorted(E elem)
-
indexOfSorted
int indexOfSorted(E elem)
-
checkElemAllowed
void checkElemAllowed(E elem)
Checks whether element is allowed in collection (null/constraint). The constraint is also checked if the element is null.- Parameters:
elem- element to check- Throws:
java.lang.IllegalArgumentException- if the element is not allowed
-
errorNullElement
static void errorNullElement()
-
errorConstraintElement
static void errorConstraintElement()
-
errorNullKey
static void errorNullKey()
-
errorMaxSize
static void errorMaxSize()
-
errorDuplicateKey
static void errorDuplicateKey(java.lang.Object key)
-
errorInvalidData
static void errorInvalidData()
-
errorInvalidIndex
static void errorInvalidIndex()
-
errorInvalidateNotSupported
static void errorInvalidateNotSupported()
-
errorInvalidSetBehavior
static void errorInvalidSetBehavior()
-
errorInvaliDuplicates
static void errorInvaliDuplicates()
-
beforeInsert
private void beforeInsert(E elem)
This method is called before a new element is added. If the addition should not happen, an exception can be thrown.- Parameters:
elem- element to insert
-
afterInsert
private void afterInsert(E elem)
This method is called after a new element has been added.- Parameters:
elem- element which has been inserted
-
beforeDelete
private void beforeDelete(E elem)
This method is called before an existing element is removed. If the deletion should not happen, an exception can be thrown.- Parameters:
elem- element to delete
-
afterDelete
private void afterDelete(E elem)
This method is called after an existing element has been removed.- Parameters:
elem- element which has been deleted
-
doAdd
protected boolean doAdd(E elem)
Helper method for adding an element to the collection. This is the only method which really adds an element. Override if you need to validity checks before adding. This method is called by both add() and addAll().
-
remove
public boolean remove(java.lang.Object elem)
- Specified by:
removein interfacejava.util.Collection<E>
-
checkAddElem
void checkAddElem(E elem)
-
remove
boolean remove(java.lang.Object elem, KeyCollectionImpl.KeyMap ignore)Remove element.- Parameters:
elem- element to removeignore- KeyMap to ignore (null to remove element from all key maps)- Returns:
- true if element has been removed
-
put
protected E put(E elem)
Adds or replaces element. If there is no such element, the element is added. If there is such an element, the element is replaced. So said simply, it is a shortcut for the following code:remove(elem); add(elem);
However the method is atomic in the sense that all or none operations are executed. So if there is already such an element, but adding the new one fails due to a constraint violation, the old element remains in the list.- Parameters:
elem- element- Returns:
- element which has been replaced or null otherwise
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Collection<E>
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
containsin interfacejava.util.Collection<E>
-
isContainsFast
boolean isContainsFast()
Determines whether calling contains() will be fast, i.e. it can use some sort of key lookup instead of traversing through all elements.- Returns:
- true if calling contains() will be fast, otherwise false
-
iterator
public java.util.Iterator<E> iterator()
-
addAll
public boolean addAll(java.util.Collection<? extends E> c)
- Specified by:
addAllin interfacejava.util.Collection<E>
-
toList
public GapList<E> toList()
Returns all elements contained in this collection as list.- Returns:
- all elements contained in this collection as list
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection<E>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArrayin interfacejava.util.Collection<E>
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAllin interfacejava.util.Collection<E>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAllin interfacejava.util.Collection<E>
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
- Specified by:
retainAllin interfacejava.util.Collection<E>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
doRemove
Option<E> doRemove(java.lang.Object elem, KeyCollectionImpl.KeyMap ignore)
Remove element. It does not adjust the size and does not call triggers.- Parameters:
elem- element to removeignore- KeyMap to ignore (null to remove element from all key maps)- Returns:
- optional with element which has been removed
-
copy
public KeyCollectionImpl copy()
Returns a copy of this collection with all its elements. The new collection will use the same comparator, ordering, etc.- Specified by:
copyin interfaceICollection<E>- Returns:
- a copy of this collection
-
crop
public KeyCollectionImpl crop()
Returns a copy of this collection but without elements. The new collection will use the same comparator, ordering, etc.- Specified by:
cropin interfaceICollection<E>- Returns:
- an empty copy of this collection
-
clone
protected java.lang.Object clone()
- Overrides:
clonein classjava.lang.Object
-
initClone
protected void initClone(java.lang.Object that)
Initialize this object after the bitwise copy has been made by Object.clone().- Parameters:
that- source object
-
asSet
public java.util.Set<E> asSet()
Returns a Set view of the element set.- Returns:
- set view
- Throws:
java.lang.IllegalArgumentException- if the element set cannot be viewed as Set
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection<E>
-
doClear
private void doClear(KeyCollectionImpl.KeyMap<E,?> keyMap)
-
doAddThrow
boolean doAddThrow(E elem, KeyCollectionImpl.KeyMap<?,?> ignore)
-
doAdd
java.lang.Object doAdd(E elem, KeyCollectionImpl.KeyMap<?,?> ignore)
Add element. This method does not change size, check whether the element may be added or calls any triggers, so this must be done by the calling method.- Parameters:
elem- element to addignore- KeyMap to ignore (null to add element to all key maps)- Returns:
- SYMBOL_ADDED if element has successfully been added, SYMBOL_NOT_ADDED if element has not been added, SYMBOL_ERROR_NULL_KEY if a null key is not allowed, otherwise the key which is rejected because of a duplicate exception
-
containsKey
protected <K> boolean containsKey(int keyIndex, K key)Checks whether the specified key exists in this list.- Parameters:
keyIndex- key indexkey- key to look for- Returns:
- true if the key exists, otherwise false
-
getDistinctKeys
protected java.util.Set<?> getDistinctKeys(int keyIndex)
Returns set containing all distinct keys.- Parameters:
keyIndex- key index- Returns:
- list containing all distinct keys
-
getAllKeys
protected IList<?> getAllKeys(int keyIndex)
Returns list containing all keys in element order.- Parameters:
keyIndex- key index- Returns:
- list containing all keys
-
checkKeyMap
void checkKeyMap(int keyIndex)
Check whether there is a KeyMap (can also be the elements set) with specified index.- Parameters:
keyIndex- key map index- Throws:
java.lang.IllegalArgumentException- if there is no such key map
-
checkAsMap
void checkAsMap(int keyIndex)
Check whether the key map can be viewed as Map.- Parameters:
keyIndex- key map index- Throws:
java.lang.IllegalArgumentException- if the key map cannot be viewed as Map
-
checkAsSet
void checkAsSet()
Check whether the element set can be viewed as Set.- Parameters:
keyIndex- key map index- Throws:
java.lang.IllegalArgumentException- if the element set cannot be viewed as Set
-
getKeyMap
KeyCollectionImpl.KeyMap<E,java.lang.Object> getKeyMap(int keyIndex)
-
getKeyMapper
protected java.util.function.Function<E,java.lang.Object> getKeyMapper(int keyIndex)
Returns mapper for specified key map.- Parameters:
keyIndex- key index- Returns:
- mapper for specified key map
-
getByKey
protected E getByKey(int keyIndex, java.lang.Object key)
Returns value for specified key. If there are several values for this key, the first is returned. If the key is not found, null is returned.- Parameters:
keyIndex- key indexkey- key to find- Returns:
- value of specified key or null
-
getByKey
private <K> E getByKey(KeyCollectionImpl.KeyMap<E,K> keyMap, K key)
-
getAllByKey
protected java.util.Collection<E> getAllByKey(int keyIndex, java.lang.Object key)
Returns a collection with all elements with the specified key.- Parameters:
keyIndex- key indexkey- key which elements must have- Returns:
- list with all elements
-
getAllByKey
protected void getAllByKey(int keyIndex, java.lang.Object key, java.util.Collection<E> coll)Fill the collection with all elements with the specified key.- Parameters:
keyIndex- key indexkey- key which elements must havecoll- collection with all elements
-
doGetAllByKey
private <K> void doGetAllByKey(KeyCollectionImpl.KeyMap<E,K> keyMap, K key, java.util.Collection<E> coll)
-
getCountByKey
protected int getCountByKey(int keyIndex, java.lang.Object key)Returns number of elements with specified key.- Parameters:
keyIndex- key indexkey- key which elements must have- Returns:
- number of elements with key
-
getCountByKey
private <K> int getCountByKey(KeyCollectionImpl.KeyMap<E,K> keyMap, K key)
-
invalidate
protected void invalidate(E elem)
Invalidate element, i.e. all keys of the element are extracted again and stored in the key maps. Old key values are removed if needed. You must call an invalidate method if an element's key value has changed after adding it to the collection.- Parameters:
elem- element to invalidate
-
invalidateKey
protected void invalidateKey(int keyIndex, java.lang.Object oldKey, java.lang.Object newKey, E elem)Invalidate key value of element. You must call an invalidate method if an element's key value has changed after adding it to the collection.- Parameters:
keyIndex- key indexoldKey- old key valuenewKey- new key valueelem- element to invalidate (can be null if there are no duplicates with this key)
-
doInvalidateKey
E doInvalidateKey(int keyIndex, java.lang.Object oldKey, java.lang.Object newKey, E elem)
-
invalidate
private Option<java.lang.Object> invalidate(KeyCollectionImpl.KeyMap keyMap, java.lang.Object elem)
- Parameters:
keyMap- key mapelem- elem to invalidate- Returns:
- null if key for keyMap and element is correct, else key which must be added to keymap
-
removeByKey
protected E removeByKey(int keyIndex, java.lang.Object key)
-
doRemoveByKey
protected Option<E> doRemoveByKey(int keyIndex, java.lang.Object key)
Removes element by key. It adjusts the size, but does not call triggers. If there are duplicates, only one element is removed.- Parameters:
keyIndex- index of key mapkey- key of element to remove- Returns:
- option with removed element as value or option without value if no element has been removed
-
removeAllByKey
protected java.util.Collection<E> removeAllByKey(int keyIndex, java.lang.Object key)
Removes element by key. If there are duplicates, all elements are removed.- Parameters:
keyIndex- key indexkey- key of element to remove- Returns:
- true if elements have been removed, false otherwise
-
removeAllByKey
protected void removeAllByKey(int keyIndex, java.lang.Object key, java.util.Collection<E> removeds)
-
equals
public boolean equals(java.lang.Object o)
- Specified by:
equalsin interfacejava.util.Collection<E>- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.util.Collection<E>- Overrides:
hashCodein classjava.lang.Object
-
getAll
public java.util.Collection<E> getAll(E elem)
Returns all equal elements.- Parameters:
elem- element- Returns:
- all equal elements (never null)
-
getCount
public int getCount(E elem)
Returns the number of equal elements.- Parameters:
elem- element- Returns:
- number of equal elements
-
removeAll
public java.util.Collection<E> removeAll(E elem)
Removes all equal elements.- Parameters:
elem- element- Returns:
- removed equal elements (never null)
-
getDistinct
public java.util.Set<E> getDistinct()
Returns all distinct elements in the same order as in the collection.- Returns:
- set with distinct elements
-
filter
public KeyCollectionImpl filter(java.util.function.Predicate<? super E> predicate)
Description copied from interface:ICollectionCreate a new collection by applying the specified filter to all elements. The returned collection has the same type as the original one.- Specified by:
filterin interfaceICollection<E>- Parameters:
predicate- filter predicate- Returns:
- created list
-
map
public <R> IList<R> map(java.util.function.Function<E,R> func)
Description copied from interface:ICollectionCreate a new list by applying the specified mapping function to all elements. The returned list is of typeIList, typicallyGapListunless the original type isBigList.- Specified by:
mapin interfaceICollection<E>- Parameters:
func- mapping function- Returns:
- created list
-
flatMap
public <R,C extends java.util.Collection<R>> IList<R> flatMap(java.util.function.Function<E,C> func)
Description copied from interface:ICollectionCreate a new list by applying the specified mapping function to all elements. The returned list is of typeIList, typicallyGapListunless the original type isBigList.- Specified by:
flatMapin interfaceICollection<E>- Parameters:
func- mapping function- Returns:
- created list
-
mapFilter
public <R> IList<R> mapFilter(java.util.function.Function<E,R> func, java.util.function.Predicate<R> filter)
Description copied from interface:ICollectionCreate a new list by applying the specified mapping function to all elements and then filtering it. The returned list is of typeIList, typicallyGapListunless the original type isBigList.- Specified by:
mapFilterin interfaceICollection<E>- Parameters:
func- mapping functionfilter- filter predicate- Returns:
- created list
-
filterMap
public <R> IList<R> filterMap(java.util.function.Predicate<E> filter, java.util.function.Function<E,R> func)
Description copied from interface:ICollectionCreate a new list by applying the specified filter first and then the mapping function to all elements selected. The returned list is of typeIList, typicallyGapListunless the original type isBigList.- Specified by:
filterMapin interfaceICollection<E>- Parameters:
filter- filter predicatefunc- mapping function- Returns:
- created list
-
-