E
- type of elements stored in the listpublic abstract class KeyListImpl<E> extends IList<E>
GapList
,
Serialized FormIList.IListableFromArray<E>, IList.IListableFromCollection<E>, IList.IListableFromList<E>, IList.IListableFromMult<E>
Modifier | Constructor and Description |
---|---|
protected |
KeyListImpl(boolean copy,
KeyListImpl<E> that) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E elem)
Note that the behavior of the operation depends on the defined constraints.
|
void |
add(int index,
E elem)
Inserts the specified element at the specified position in this list.
|
java.util.Set<E> |
asSet()
Returns a Set view of the element set.
|
<K> int |
binarySearch(int index,
int len,
K key,
java.util.Comparator<? super K> comparator)
Searches the specified range for an object using the binary search algorithm.
|
int |
capacity()
Returns capacity of this list.
|
void |
clear() |
KeyListImpl<E> |
clone()
Returns a shallow copy of this list.
|
boolean |
contains(java.lang.Object elem)
If the list defines maps for the keys, they are used to speed up the lookup operation.
|
boolean |
containsKey(int keyIndex,
java.lang.Object key)
Checks whether the specified key exists in this list.
|
int |
count(E elem)
Counts how many times the specified element is contained in the list.
|
KeyListImpl<E> |
crop()
Returns a copy this list but without elements.
|
protected boolean |
doAdd(int index,
E elem)
Helper method for adding an element to the list.
|
protected void |
doAssign(IList<E> that)
Assign this list the content of the that list.
|
protected void |
doClone(IList<E> that)
Initialize this object after the bitwise copy has been made by Object.clone().
|
protected IList<E> |
doCreate(int capacity)
Create list with specified capacity.
|
protected void |
doEnsureCapacity(int minCapacity)
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 E |
doGet(int index)
Helper method for getting an element from the list.
|
protected <T> void |
doGetAll(T[] array,
int index,
int len)
Helper method to fill the specified elements in an array.
|
protected E |
doRemove(int index)
Helper method to remove an element.
|
protected void |
doRemoveAll(int index,
int len)
Remove specified range of elements from list.
|
protected E |
doReSet(int index,
E elem)
Sets an element at specified position.
|
protected E |
doSet(int index,
E elem)
Helper method for setting an element in the list.
|
void |
ensureCapacity(int minCapacity)
Increases the capacity of this instance, if necessary, to ensure that it can hold at least the number of
elements specified by the minimum capacity argument.
|
E |
get(int index)
Return element at specified position
|
IList<E> |
getAll(E elem)
Returns all elements in the list equal to the specified element.
|
IList<E> |
getAllByKey(int keyIndex,
java.lang.Object key)
Returns a list with all elements with the specified key.
|
protected IList<java.lang.Object> |
getAllKeys(int keyIndex)
Returns list containing all keys in element order.
|
E |
getByKey(int keyIndex,
java.lang.Object key)
Returns value for given key.
|
int |
getCountByKey(int keyIndex,
java.lang.Object key)
Returns number of elements with specified key.
|
protected E |
getDefaultElem() |
java.util.Set<E> |
getDistinct()
Returns distinct elements in the list.
|
java.util.Set<?> |
getDistinctKeys(int keyIndex)
Returns set containing all distinct keys.
|
java.util.function.Function<E,java.lang.Object> |
getKeyMapper(int keyIndex)
Returns mapper for specified key map.
|
int |
indexOf(java.lang.Object elem)
If the list is sorted, this is used to speed up the lookup operation.
|
int |
indexOfKey(int keyIndex,
java.lang.Object key)
Find given key and return its index.
|
int |
indexOfKey(int keyIndex,
java.lang.Object key,
int start)
Find given key and return its index.
|
protected void |
invalidate(E elem)
Invalidate element, i.e. all keys of the element are extracted
again and stored in the key maps.
|
protected void |
invalidateKey(int keyIndex,
java.lang.Object oldKey,
java.lang.Object newKey,
E elem)
Invalidate key value of element.
|
boolean |
isSorted()
Determines whether this list is sorted or not.
|
protected E |
put(E elem)
Adds or replaces element.
|
protected E |
putByKey(int keyIndex,
E elem,
boolean replace)
Put element by key into list.
|
boolean |
remove(java.lang.Object elem)
If the list is sorted, this is used to speed up the remove operation.
|
IList<E> |
removeAll(E elem)
Removes all equal elements.
|
protected IList<E> |
removeAllByKey(int keyIndex,
java.lang.Object key)
Removes element by key.
|
protected E |
removeByKey(int keyIndex,
java.lang.Object key)
Removes element by key.
|
E |
set(int index,
E elem)
Note that the behavior of the operation depends on the defined constraints.
|
int |
size()
Return size of list
|
void |
sort(int index,
int len,
java.util.Comparator<? super E> comparator)
Sort specified elements in the list using the specified comparator.
|
void |
trimToSize()
An application can use this operation to minimize the storage of an instance.
|
IList<E> |
unwrap()
Returns the elements stored in the KeyList as simple IList without constraints etc.
|
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, copy, countIf, descendingIterator, doAddAll, doClear, doCreateArray, doIndexOf, doIndexOfIf, doInitAll, doLastIndexOf, doLastIndexOfIf, doModify, doPutAll, doReplace, doRotate, drag, element, equals, extract, extractIf, fill, filter, filterMap, flatMap, getAll, getFirst, getFirstOrNull, getIf, getLast, getLastOrNull, getSingle, getSingleOrNull, hashCode, immutableList, indexOf, indexOfIf, indexOfIf, initAll, initAll, initArray, initMult, isEmpty, isReadOnly, 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, toString, transferCopy, transferMove, transferRemove, transferSwap, transform, transformedList, unmodifiableList
protected KeyListImpl(boolean copy, KeyListImpl<E> that)
protected void doAssign(IList<E> that)
IList
public KeyListImpl<E> clone()
IList
IList.copy()
to .public KeyListImpl<E> crop()
public IList<E> unwrap()
protected void doClone(IList<E> that)
IList
public java.util.Set<E> asSet()
java.lang.IllegalArgumentException
- if the element set cannot be viewed as Setpublic boolean isSorted()
public int capacity()
IList
public int size()
IListable
public E get(int index)
IListable
protected E doGet(int index)
IList
protected <T> void doGetAll(T[] array, int index, int len)
IList
public boolean contains(java.lang.Object elem)
If the list defines maps for the keys, they are used to speed up the lookup operation. So if the list defines a primary key, performance will be similar to a lookup in a set.
public boolean remove(java.lang.Object elem)
If the list is sorted, this is used to speed up the remove operation. If the list defines unsorted map, this does not improve performance.
public boolean add(E elem)
Note that the behavior of the operation depends on the defined constraints.
public void add(int index, E elem)
Note that the behavior of the operation depends on the defined constraints.
public E set(int index, E elem)
Note that the behavior of the operation depends on the defined constraints.
public void clear()
public void ensureCapacity(int minCapacity)
IList
ensureCapacity
in class IList<E>
minCapacity
- the desired minimum capacityprotected boolean doAdd(int index, E elem)
IList
protected E doSet(int index, E elem)
IList
protected E doRemove(int index)
IList
protected void doRemoveAll(int index, int len)
IList
doRemoveAll
in class IList<E>
index
- index of first element to removelen
- number of elements to removeprotected E doReSet(int index, E elem)
IList
public int indexOf(java.lang.Object elem)
If the list is sorted, this is used to speed up the lookup operation. If the list defines unsorted map, this does not improve performance.
public int indexOfKey(int keyIndex, java.lang.Object key)
keyIndex
- key indexkey
- key to findpublic int indexOfKey(int keyIndex, java.lang.Object key, int start)
keyIndex
- key indexkey
- key to findstart
- start index for searchpublic boolean containsKey(int keyIndex, java.lang.Object key)
keyIndex
- key indexkey
- key to look forpublic java.util.function.Function<E,java.lang.Object> getKeyMapper(int keyIndex)
keyIndex
- key indexpublic E getByKey(int keyIndex, java.lang.Object key)
keyIndex
- key indexkey
- key to findpublic IList<E> getAllByKey(int keyIndex, java.lang.Object key)
keyIndex
- key indexkey
- key which elements must havepublic int getCountByKey(int keyIndex, java.lang.Object key)
keyIndex
- key indexkey
- key which elements must haveprotected E removeByKey(int keyIndex, java.lang.Object key)
keyIndex
- key indexkey
- key of element to removeprotected E putByKey(int keyIndex, E elem, boolean replace)
keyIndex
- key indexelem
- element to putreplace
- true to replace an existing element with the same key, false to let the element unchangedprotected IList<E> removeAllByKey(int keyIndex, java.lang.Object key)
keyIndex
- key indexkey
- key of element to removeprotected IList<java.lang.Object> getAllKeys(int keyIndex)
keyIndex
- key indexpublic java.util.Set<?> getDistinctKeys(int keyIndex)
keyIndex
- key indexpublic <K> int binarySearch(int index, int len, K key, java.util.Comparator<? super K> comparator)
IList
Note that the method is defined to work with an arbitrary type <K>. This allows to search directly for a key field in the object without the need to construct an object containing the key:
persons.binarySearch("john", new SearchByName());
class SearchByName implements Comparator<Object> {
public int compare(Object o1, Object o2) {
String s1 = (o1 instanceof String) ? (String) o1 : ((Name) o1).getName();
String s2 = (o2 instanceof String) ? (String) o2 : ((Name) o2).getName();
return s1.compareTo(s2);
}
}
/
binarySearch
in class IList<E>
index
- index of first element to searchlen
- number of elements to searchkey
- the value to be searched forcomparator
- the comparator by which the list is ordered.
A null value indicates that the elements'
natural ordering should be used.Arrays.binarySearch(long[], long)
public void sort(int index, int len, java.util.Comparator<? super E> comparator)
IList
public IList<E> getAll(E elem)
IList
public int count(E elem)
IList
public IList<E> removeAll(E elem)
IList
public java.util.Set<E> getDistinct()
IList
getDistinct
in class IList<E>
protected E put(E elem)
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.
elem
- elementprotected void invalidate(E elem)
elem
- element to invalidateprotected void invalidateKey(int keyIndex, java.lang.Object oldKey, java.lang.Object newKey, E elem)
keyIndex
- key indexoldKey
- old key valuenewKey
- new key valueelem
- element to invalidate (can be null if there are no duplicates with this key)protected E getDefaultElem()
getDefaultElem
in class IList<E>
protected void doEnsureCapacity(int minCapacity)
IList
doEnsureCapacity
in class IList<E>
minCapacity
- the desired minimum capacitypublic void trimToSize()
IList
trimToSize
in class IList<E>