Class KeyList.ImmutableKeyList<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- org.magicwerk.brownies.collections.IList<E>
-
- org.magicwerk.brownies.collections.KeyListImpl<E>
-
- org.magicwerk.brownies.collections.KeyList<E>
-
- org.magicwerk.brownies.collections.KeyList.ImmutableKeyList<E>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<E>,java.util.Collection<E>,java.util.List<E>,java.util.RandomAccess,ICollection<E>,IListable<E>
protected static class KeyList.ImmutableKeyList<E> extends KeyList<E>
A read-only version ofKeyList. It is used to implement both unmodifiable and immutable lists. Note that the client cannot change the list, but the content may change if the underlying list is changed.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.magicwerk.brownies.collections.KeyList
KeyList.Builder<E>, KeyList.ImmutableKeyList<E>
-
Nested classes/interfaces inherited from class org.magicwerk.brownies.collections.IList
IList.IListableFromArray<E>, IList.IListableFromCollection<E>, IList.IListableFromList<E>, IList.IListableFromMult<E>, IList.Iter, IList.ListIter
-
-
Field Summary
Fields Modifier and Type Field Description private static longserialVersionUIDUID for serialization-
Fields inherited from class org.magicwerk.brownies.collections.KeyListImpl
keyColl, list
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedImmutableKeyList(KeyList<E> that)Private constructor used internally.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleandoAdd(int index, E elem)Helper method for adding an element to the list.protected voiddoClear()protected voiddoEnsureCapacity(int capacity)Increases the capacity of this list instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.protected voiddoModify()This method is called internally before elements are allocated or freed.protected EdoRemove(int index)Helper method to remove an element.protected voiddoRemoveAll(int index, int len)Remove specified range of elements from list.protected EdoReSet(int index, E elem)Sets an element at specified position.protected EdoSet(int index, E elem)Helper method for setting an element in the list.private voiderror()Throw exception if an attempt is made to change an immutable list.protected voidinvalidateKey(int keyIndex, java.lang.Object oldKey, java.lang.Object newKey, E elem)Invalidate key value of element.protected EputByKey(int keyIndex, E elem, boolean replace)Put element by key into list.protected IList<E>removeAllByKey(int keyIndex, java.lang.Object key)Removes element by key.protected EremoveByKey(int keyIndex, java.lang.Object key)Removes element by key.-
Methods inherited from class org.magicwerk.brownies.collections.KeyList
clone, copy, count, crop, getAll, getBuilder, getDistinct, immutableList, isReadOnly, put, removeAll, unmodifiableList
-
Methods inherited from class org.magicwerk.brownies.collections.KeyListImpl
add, add, asSet, binarySearch, capacity, clear, contains, containsKey, doAssign, doClone, doCreate, doGet, doGetAll, ensureCapacity, get, getAllByKey, getAllKeys, getByKey, getCountByKey, getDefaultElem, getDistinctKeys, getKeyMapper, indexOf, indexOfKey, indexOfKey, initCopy, initCrop, invalidate, isContainsFast, isIndexOfFast, isSorted, remove, set, size, sort, trimToSize, unwrap
-
Methods inherited from class org.magicwerk.brownies.collections.IList
addAll, addAll, addAll, addAll, addArray, addArray, addArray, addArray, addFirst, addIfAbsent, addLast, addMult, addMult, asDeque, asIListable, binarySearch, checkIndex, checkIndexAdd, checkLength, checkLengths, checkNonNull, checkRange, containsAll, containsAny, containsIf, copy, countIf, descendingIterator, doAddAll, doCreateArray, doIndexOf, doIndexOfIf, doInitAll, doLastIndexOf, doLastIndexOfIf, doPutAll, doReplace, doRotate, doTransfer, doTransferSwap, drag, element, equals, equalsElem, extract, extractIf, fill, filter, filterMap, flatMap, getAll, getFirst, getFirstOrNull, getIf, getLast, getLastOrNull, getSingle, getSingleOrNull, hashCode, hashCodeElem, indexOf, indexOfIf, indexOfIf, initAll, initAll, initArray, initMult, isEmpty, iterator, lastIndexOf, lastIndexOf, lastIndexOfIf, lastIndexOfIf, listIterator, listIterator, map, mapFilter, move, offer, offerFirst, offerLast, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, push, put, putAll, putAll, putArray, putMult, remove, remove, remove, removeAll, removeAll, removeFirst, removeFirstOccurrence, removeIf, removeLast, removeLastOccurrence, replace, replaceAll, replaceAll, replaceArray, replaceMult, resize, retain, retainAll, retainAll, retainIf, reverse, reverse, rotate, rotate, setAll, setAll, setArray, setArray, setMult, sort, swap, toArray, toArray, toArray, toArray, toArray, toArray, toArray, toString, transferCopy, transferMove, transferRemove, transferSwap, transform, transformedList
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
UID for serialization- See Also:
- Constant Field Values
-
-
Method Detail
-
doEnsureCapacity
protected void doEnsureCapacity(int capacity)
Description copied from class:IListIncreases the capacity of this list instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.- Overrides:
doEnsureCapacityin classKeyListImpl<E>- Parameters:
capacity- the desired minimum capacity
-
doAdd
protected boolean doAdd(int index, E elem)Description copied from class:IListHelper method for adding an element to the list. This is the only method which really adds an element. Override if you need to validity checks before adding.- Overrides:
doAddin classKeyListImpl<E>- Parameters:
index- index where element should be added (-1 means it is up to the implementation to choose the index)elem- element to add- Returns:
- true if element has been added, false otherwise
-
doSet
protected E doSet(int index, E elem)
Description copied from class:IListHelper method for setting an element in the list. This is the only method which really sets an element. Override if you need to validity checks before setting.- Overrides:
doSetin classKeyListImpl<E>- Parameters:
index- index where element will be placedelem- element to set- Returns:
- old element which was at the position
-
doReSet
protected E doReSet(int index, E elem)
Description copied from class:IListSets an element at specified position. This method is used internally if existing elements will be moved etc. Override if you need to validity checks.- Overrides:
doReSetin classKeyListImpl<E>- Parameters:
index- index where element will be placedelem- element to set- Returns:
- old element which was at the position
-
doRemove
protected E doRemove(int index)
Description copied from class:IListHelper method to remove an element. This is the only method which really removes an element. Override if you need to validity checks before removing.- Overrides:
doRemovein classKeyListImpl<E>- Parameters:
index- index of element to remove- Returns:
- removed element
-
doRemoveAll
protected void doRemoveAll(int index, int len)Description copied from class:IListRemove specified range of elements from list.- Overrides:
doRemoveAllin classKeyListImpl<E>- Parameters:
index- index of first element to removelen- number of elements to remove
-
doModify
protected void doModify()
Description copied from class:IListThis method is called internally before elements are allocated or freed. Override if you need to validity checks.
-
removeByKey
protected E removeByKey(int keyIndex, java.lang.Object key)
Description copied from class:KeyListImplRemoves element by key. If there are duplicates, only one element is removed.- Overrides:
removeByKeyin classKeyListImpl<E>- Parameters:
keyIndex- key indexkey- key of element to remove- Returns:
- removed element or null if no element has been removed
-
removeAllByKey
protected IList<E> removeAllByKey(int keyIndex, java.lang.Object key)
Description copied from class:KeyListImplRemoves element by key. If there are duplicates, all elements are removed.- Overrides:
removeAllByKeyin classKeyListImpl<E>- Parameters:
keyIndex- key indexkey- key of element to remove- Returns:
- true if elements have been removed, false otherwise
-
putByKey
protected E putByKey(int keyIndex, E elem, boolean replace)
Description copied from class:KeyListImplPut element by key into list.- Overrides:
putByKeyin classKeyListImpl<E>- Parameters:
keyIndex- key indexelem- element to putreplace- true to replace an existing element with the same key, false to let the element unchanged- Returns:
- element with the same key (i.e. element which was replaced if replace is true / which was left unchanged if false), null if no element with the same key has been found
-
invalidateKey
protected void invalidateKey(int keyIndex, java.lang.Object oldKey, java.lang.Object newKey, E elem)Description copied from class:KeyListImplInvalidate key value of element. You must call an invalidate method if an element's key value has changed after adding it to the collection.- Overrides:
invalidateKeyin classKeyListImpl<E>- Parameters:
keyIndex- key indexoldKey- old key valuenewKey- new key valueelem- element to invalidate (can be null if there are no duplicates with this key)
-
error
private void error()
Throw exception if an attempt is made to change an immutable list.
-
-