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:
Serializable,Cloneable,Iterable<E>,Collection<E>,ICollection<E>
- Direct Known Subclasses:
KeySet
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder 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
ConstructorsModifierConstructorDescriptionprotectedProtected constructor used by builder or derived collections. -
Method Summary
Modifier and TypeMethodDescriptioncopy()Returns a copy of this collection with all its elements.crop()Returns a copy of this collection but without elements.Create a new collection by applying the specified filter to all elements.Returns all equal elements.protected KeyCollection.Builder<E> voidinvalidate(E elem) Invalidate element, i.e.Adds or replaces element.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, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArrayMethods inherited from interface org.magicwerk.brownies.collections.ICollection
containsIf, countIf, getFirst, getFirstOrNull, getIf, getSingle, getSingleOrNull
-
Constructor Details
-
KeyCollection
protected KeyCollection()Protected constructor used by builder or derived collections.
-
-
Method Details
-
getBuilder
- Returns:
- builder to use in extending classes
-
copy
Description copied from class:KeyCollectionImplReturns a copy of this collection with all its elements. The new collection will use the same comparator, ordering, etc.- Specified by:
copyin interfaceICollection<E>- Overrides:
copyin classKeyCollectionImpl<E>- Returns:
- a copy of this collection
-
crop
Description copied from class:KeyCollectionImplReturns a copy of this collection but without elements. The new collection will use the same comparator, ordering, etc.- Specified by:
cropin interfaceICollection<E>- Overrides:
cropin classKeyCollectionImpl<E>- Returns:
- an empty copy of this collection
-
getAll
Description copied from class:KeyCollectionImplReturns all equal elements.- Overrides:
getAllin classKeyCollectionImpl<E>- Parameters:
elem- element- Returns:
- all equal elements (never null)
-
removeAll
Description copied from class:KeyCollectionImplRemoves all equal elements.- Overrides:
removeAllin classKeyCollectionImpl<E>- Parameters:
elem- element- Returns:
- removed equal elements (never null)
-
put
Description copied from class:KeyCollectionImplAdds 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:
putin classKeyCollectionImpl<E>- Parameters:
elem- element- Returns:
- element which has been replaced or null otherwise
-
invalidate
Description copied from class:KeyCollectionImplInvalidate 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:
invalidatein classKeyCollectionImpl<E>- Parameters:
elem- element to invalidate
-
filter
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>- Overrides:
filterin classKeyCollectionImpl<E>- Parameters:
filter- filter predicate- Returns:
- created list
-