Class KeyCollection<E>
- java.lang.Object
-
- org.magicwerk.brownies.collections.KeyCollectionImpl<E>
-
- org.magicwerk.brownies.collections.KeyCollection<E>
-
- Type Parameters:
E
- type of elements stored in the collection
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.lang.Iterable<E>
,java.util.Collection<E>
,ICollection<E>
- Direct Known Subclasses:
KeySet
public class KeyCollection<E> extends KeyCollectionImpl<E>
KeyCollection implements a collection. It can provide fast access to its elements like a Set. The elements allowed in the collection can be constraint (null/duplicate values).- See Also:
Key1List
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
KeyCollection.Builder<E>
Builder to construct KeyCollection instances.-
Nested classes/interfaces inherited from class org.magicwerk.brownies.collections.KeyCollectionImpl
KeyCollectionImpl.BuilderImpl<E>, KeyCollectionImpl.KeyMap<E,K>, KeyCollectionImpl.KeyMapList<E>
-
-
Field Summary
-
Fields inherited from class org.magicwerk.brownies.collections.KeyCollectionImpl
afterDeleteTrigger, afterInsertTrigger, allowNullElem, beforeDeleteTrigger, beforeInsertTrigger, constraint, keyList, keyMaps, maxSize, movingWindow, orderByKey, setBehavior, size, SYMBOL_ADDED, SYMBOL_ERROR_NULL_KEY, SYMBOL_NOT_ADDED
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
KeyCollection()
Protected constructor used by builder or derived collections.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description KeyCollection<E>
copy()
Returns a copy of this collection with all its elements.KeyCollection<E>
crop()
Returns a copy of this collection but without elements.KeyCollection<E>
filter(java.util.function.Predicate<? super E> filter)
Create a new collection by applying the specified filter to all elements.KeyCollection<E>
getAll(E elem)
Returns all equal elements.protected KeyCollection.Builder<E>
getBuilder()
void
invalidate(E elem)
Invalidate element, i.e.E
put(E elem)
Adds or replaces element.KeyCollection<E>
removeAll(E elem)
Removes all equal elements.-
Methods inherited from class org.magicwerk.brownies.collections.KeyCollectionImpl
add, addAll, addSorted, addUnsorted, asSet, binarySearchSorted, checkAddElem, checkAsMap, checkAsSet, checkElemAllowed, checkIndex, checkKeyMap, clear, clone, contains, containsAll, containsKey, debugCheck, doAdd, doAdd, doAddThrow, doInvalidateKey, doRemove, doRemoveByKey, equals, errorConstraintElement, errorDuplicateKey, errorInvalidateNotSupported, errorInvalidData, errorInvalidIndex, errorInvalidSetBehavior, errorInvaliDuplicates, errorMaxSize, errorNullElement, errorNullKey, filterMap, flatMap, getAllByKey, getAllByKey, getAllKeys, getByKey, getCount, getCountByKey, getDistinct, getDistinctKeys, getElemSortComparator, getKey, getKeyMap, getKeyMapper, hasElemSet, hashCode, indexOfSorted, initClone, initCopy, initCrop, invalidateKey, isContainsFast, isEmpty, isSorted, isSortedByElem, iterator, map, mapFilter, putByKey, remove, remove, removeAll, removeAllByKey, removeAllByKey, removeByKey, retainAll, setSorted, size, toArray, toArray, toList, toString
-
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
-
-
-
-
Method Detail
-
getBuilder
protected KeyCollection.Builder<E> getBuilder()
- Returns:
- builder to use in extending classes
-
copy
public KeyCollection<E> copy()
Description copied from class:KeyCollectionImpl
Returns a copy of this collection with all its elements. The new collection will use the same comparator, ordering, etc.- Specified by:
copy
in interfaceICollection<E>
- Overrides:
copy
in classKeyCollectionImpl<E>
- Returns:
- a copy of this collection
-
crop
public KeyCollection<E> crop()
Description copied from class:KeyCollectionImpl
Returns a copy of this collection but without elements. The new collection will use the same comparator, ordering, etc.- Specified by:
crop
in interfaceICollection<E>
- Overrides:
crop
in classKeyCollectionImpl<E>
- Returns:
- an empty copy of this collection
-
getAll
public KeyCollection<E> getAll(E elem)
Description copied from class:KeyCollectionImpl
Returns all equal elements.- Overrides:
getAll
in classKeyCollectionImpl<E>
- Parameters:
elem
- element- Returns:
- all equal elements (never null)
-
removeAll
public KeyCollection<E> removeAll(E elem)
Description copied from class:KeyCollectionImpl
Removes all equal elements.- Overrides:
removeAll
in classKeyCollectionImpl<E>
- Parameters:
elem
- element- Returns:
- removed equal elements (never null)
-
put
public E put(E elem)
Description copied from class:KeyCollectionImpl
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.- Overrides:
put
in classKeyCollectionImpl<E>
- Parameters:
elem
- element- Returns:
- element which has been replaced or null otherwise
-
invalidate
public void invalidate(E elem)
Description copied from class:KeyCollectionImpl
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.- Overrides:
invalidate
in classKeyCollectionImpl<E>
- Parameters:
elem
- element to invalidate
-
filter
public KeyCollection<E> filter(java.util.function.Predicate<? super E> filter)
Description copied from interface:ICollection
Create a new collection by applying the specified filter to all elements. The returned collection has the same type as the original one.- Specified by:
filter
in interfaceICollection<E>
- Overrides:
filter
in classKeyCollectionImpl<E>
- Parameters:
filter
- filter predicate- Returns:
- created list
-
-