Class KeyList<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>
-
- 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>,java.util.List<E>,java.util.RandomAccess,ICollection<E>,IListable<E>
- Direct Known Subclasses:
KeyList.ImmutableKeyList
public class KeyList<E> extends KeyListImpl<E>
KeyList implements a list. It can provide fast access to its elements like a Set. The elements allowed in the list can be constraint (null/duplicate values).- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classKeyList.Builder<E>Builder to construct KeyList instances.protected static classKeyList.ImmutableKeyList<E>A read-only version ofKeyList.-
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 inherited from class org.magicwerk.brownies.collections.KeyListImpl
keyColl, list
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description KeyList<E>clone()Returns a shallow copy of this list.KeyList<E>copy()Returns a shallow copy of this list.intcount(E elem)Counts how many times the specified element is contained in the list.KeyList<E>crop()Returns a copy this list but without elements.IList<E>getAll(E elem)Returns all elements in the list equal to the specified element.protected KeyList.Builder<E>getBuilder()java.util.Set<E>getDistinct()Returns distinct elements in the list.KeyList<E>immutableList()Returns an immutable copy of this list.booleanisReadOnly()Returns true if this list is either unmodifiable or immutable, false otherwise.Eput(E elem)Adds or replaces element.IList<E>removeAll(E elem)Removes all equal elements.KeyList<E>unmodifiableList()Returns an unmodifiable view of this list.-
Methods inherited from class org.magicwerk.brownies.collections.KeyListImpl
add, add, asSet, binarySearch, capacity, clear, contains, containsKey, doAdd, doAssign, doClone, doCreate, doEnsureCapacity, doGet, doGetAll, doRemove, doRemoveAll, doReSet, doSet, ensureCapacity, get, getAllByKey, getAllKeys, getByKey, getCountByKey, getDefaultElem, getDistinctKeys, getKeyMapper, indexOf, indexOfKey, indexOfKey, initCopy, initCrop, invalidate, invalidateKey, isContainsFast, isIndexOfFast, isSorted, putByKey, remove, removeAllByKey, removeByKey, 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, doClear, doCreateArray, doIndexOf, doIndexOfIf, doInitAll, doLastIndexOf, doLastIndexOfIf, doModify, 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
-
-
-
-
Method Detail
-
getBuilder
protected KeyList.Builder<E> getBuilder()
- Returns:
- builder to use in extending classes
-
copy
public KeyList<E> copy()
Description copied from class:IListReturns a shallow copy of this list. The new list will contain the same elements as the source list, i.e. the elements themselves are not copied. The capacity of the list will be set to the number of elements, i.e. size and capacity are equal. This returned list will be modifiable, i.e. a read-only list will be copied and be modifiable again.
-
clone
public KeyList<E> clone()
Description copied from class:IListReturns a shallow copy of this list. The new list will contain the same elements as the source list, i.e. the elements themselves are not copied. The capacity of the list will be set to the number of elements, i.e. size and capacity are equal. If the list is read-only, the same list is returned without change. UseIList.copy()to .- Overrides:
clonein classKeyListImpl<E>- Returns:
- a modifiable copy of this list
-
crop
public KeyList<E> crop()
Description copied from class:KeyListImplReturns a copy this list but without elements. The new list will have the same type as this list and use the same comparator, ordering, etc.- Specified by:
cropin interfaceICollection<E>- Overrides:
cropin classKeyListImpl<E>- Returns:
- an empty copy of this list
-
getAll
public IList<E> getAll(E elem)
Description copied from class:IListReturns all elements in the list equal to the specified element.- Overrides:
getAllin classKeyListImpl<E>- Parameters:
elem- element to look for- Returns:
- all elements in the list equal to the specified element
-
count
public int count(E elem)
Description copied from class:IListCounts how many times the specified element is contained in the list.- Overrides:
countin classKeyListImpl<E>- Parameters:
elem- element to count- Returns:
- count how many times the specified element is contained in the list
-
removeAll
public IList<E> removeAll(E elem)
Description copied from class:IListRemoves all equal elements.- Overrides:
removeAllin classKeyListImpl<E>- Parameters:
elem- element- Returns:
- removed equal elements (never null)
-
getDistinct
public java.util.Set<E> getDistinct()
Description copied from class:IListReturns distinct elements in the list.- Overrides:
getDistinctin classKeyListImpl<E>- Returns:
- distinct elements in the list
-
put
public E put(E elem)
Description copied from class:KeyListImplAdds 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:if (contains(elem)) { 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 classKeyListImpl<E>- Parameters:
elem- element- Returns:
- element which has been replaced or null otherwise
-
isReadOnly
public boolean isReadOnly()
Description copied from class:IListReturns true if this list is either unmodifiable or immutable, false otherwise.- Specified by:
isReadOnlyin classIList<E>
-
unmodifiableList
public KeyList<E> unmodifiableList()
Description copied from class:IListReturns an unmodifiable view of this list. This method allows modules to provide users with "read-only" access to internal lists, where changes made to the original list are visible as query operations on the returned list "read through" to the specified list. Attempts to modify the returned list, whether direct or via its iterator, result in an UnsupportedOperationException. If this list is already unmodifiable, it is returned unchanged. SeeIList.immutableList()to get an immutable copy of a list.- Specified by:
unmodifiableListin classIList<E>- Returns:
- an unmodifiable view of the specified list
-
immutableList
public KeyList<E> immutableList()
Description copied from class:IListReturns an immutable copy of this list. The returned list is independent from the original list, i.e. changes done later are not seen. Attempts to modify the returned list, whether direct or via its iterator, result in an UnsupportedOperationException. If this list is already immutable, it is returned unchanged. SeeIList.unmodifiableList()to get unmodifiable view of a list.- Specified by:
immutableListin classIList<E>- Returns:
- an immutable copy of the specified list
-
-