Class TextualSearchList<E>
- Type Parameters:
E- Type of object to manage in this list.
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<E>,Collection<E>,List<E>,RandomAccess
- Direct Known Subclasses:
SearchColumnList,SearchTableList
A TextualSearchList is an ArrayList with a textual search capability.
The interest of this class lies in the fact that objects can be searched with
or without case sensitivity on their textual key thanks to get(String, boolean).
The textual key is extracted by an object implementing the TextualSearchList.KeyExtractor instance.
If no TextualSearchList.KeyExtractor instance is given at initialization, the string returned
by the toString() function will be used as key.
WARNING: The extracted key MUST be CASE-SENSITIVE and UNIQUE !
- Version:
- 1.4 (09/2017)
- Author:
- Grégory Mantelet (CDS;ARI)
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classDefault implementation ofTextualSearchList.KeyExtractor.static interfaceLets extract an unique textual key (case-sensitive) from a given type of object. -
Field Summary
FieldsModifier and TypeFieldDescriptionMap which associates objects of type E with its textual string (case-sensitive).final TextualSearchList.KeyExtractor<E>Object to use to extract an unique textual string.Map which associates objects of type E with their lower-case textual string.Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionBuilds an empty TextualSearchList.TextualSearchList(int initialCapacity) Builds an empty TextualSearchList with an initial capacity.TextualSearchList(int initialCapacity, TextualSearchList.KeyExtractor<E> keyExtractor) Builds an empty TextualSearchList with an initial capacity.TextualSearchList(TextualSearchList.KeyExtractor<E> keyExtractor) Builds an empty TextualSearchList.TextualSearchList(Collection<? extends E> c) Builds a TextualSearchList filled with the objects of the given collection.TextualSearchList(Collection<? extends E> c, TextualSearchList.KeyExtractor<E> keyExtractor) Builds a TextualSearchList filled with the objects of the given collection. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the given object at the given position in this list.booleanAdds the given object at the end of this list.booleanaddAll(int index, Collection<? extends E> c) Appends all the objects of the given collection in this list after the given position.booleanaddAll(Collection<? extends E> c) Appends all the objects of the given collection in this list.voidclear()booleanReturns true if this list contains the specified element.Searches (CASE-INSENSITIVE) the object which has the given key.Searches of all the object which has the given key.remove(int index) booleanprotected voidremoveRange(int fromIndex, int toIndex) Replaces the element at the specified position in this list with the specified element.Methods inherited from class java.util.ArrayList
clone, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, removeAll, removeIf, replaceAll, retainAll, size, sort, spliterator, subList, toArray, toArray, trimToSizeMethods inherited from class java.util.AbstractCollection
containsAll, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, stream, toArrayMethods inherited from interface java.util.List
containsAll
-
Field Details
-
keyExtractor
Object to use to extract an unique textual string. -
csMap
Map which associates objects of type E with its textual string (case-sensitive). -
ncsMap
Map which associates objects of type E with their lower-case textual string.
-
-
Constructor Details
-
TextualSearchList
public TextualSearchList()Builds an empty TextualSearchList.
Note: the key of inserted objects will be the string returned by their
toString()function.- See Also:
-
TextualSearchList
Builds an empty TextualSearchList.- Parameters:
keyExtractor- The object to use to extract a textual key from objects to insert.- See Also:
-
TextualSearchList
public TextualSearchList(int initialCapacity) Builds an empty TextualSearchList with an initial capacity.
Note: the key of inserted objects will be the string returned by their
toString()function.- Parameters:
initialCapacity- Initial capacity of this list.- See Also:
-
TextualSearchList
Builds an empty TextualSearchList with an initial capacity.- Parameters:
initialCapacity- Initial capacity of this list.keyExtractor- The object to use to extract a textual key from objects to insert.- See Also:
-
TextualSearchList
Builds a TextualSearchList filled with the objects of the given collection.
Note: the key of inserted objects will be the string returned by their
toString()function.- Parameters:
c- Collection to copy into this list.
-
TextualSearchList
Builds a TextualSearchList filled with the objects of the given collection.- Parameters:
c- Collection to copy into this list.keyExtractor- The object object to use to extract a textual key from objects to insert.- See Also:
-
-
Method Details
-
contains
Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (keyExtractor.getKey(o).equals(keyExtractor.getKey(e))).- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceList<E>- Overrides:
containsin classArrayList<E>- Since:
- 1.1
- See Also:
-
ArrayList.contains(java.lang.Object)getKey(Object)
-
get
Searches (CASE-INSENSITIVE) the object which has the given key.- Parameters:
key- Textual key of the object to search.- Returns:
- The corresponding object or
null.
-
get
Searches of all the object which has the given key.- Parameters:
key- Textual key of the object to search.caseSensitive- true to consider the case of the key, false otherwise.- Returns:
- All the objects whose the key is the same as the given one.
-
add
Adds the given object at the end of this list.- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceList<E>- Overrides:
addin classArrayList<E>- Parameters:
obj- Object to add (different from NULL).- Throws:
NullPointerException- If the given object or its extracted key isnull.IllegalArgumentException- If the extracted key is already used by another object in this list.- See Also:
-
add
public void add(int index, E obj) throws NullPointerException, IllegalArgumentException, IndexOutOfBoundsException Adds the given object at the given position in this list.- Specified by:
addin interfaceList<E>- Overrides:
addin classArrayList<E>- Parameters:
index- Index at which the given object must be added.obj- Object to add (different from NULL).- Throws:
NullPointerException- If the given object or its extracted key isnull.IllegalArgumentException- If the extracted key is already used by another object in this list.IndexOutOfBoundsException- If the given index is negative or greater than the size of this list.- See Also:
-
addAll
public boolean addAll(Collection<? extends E> c) throws NullPointerException, IllegalArgumentException Appends all the objects of the given collection in this list.- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceList<E>- Overrides:
addAllin classArrayList<E>- Parameters:
c- Collection of objects to add.- Returns:
trueif this list changed as a result of the call,falseotherwise.- Throws:
NullPointerException- If an object to add or its extracted key isnull.IllegalArgumentException- If the extracted key is already used by another object in this list.- See Also:
-
addAll
public boolean addAll(int index, Collection<? extends E> c) throws NullPointerException, IllegalArgumentException, IndexOutOfBoundsException Appends all the objects of the given collection in this list after the given position.- Specified by:
addAllin interfaceList<E>- Overrides:
addAllin classArrayList<E>- Parameters:
index- Position from which objects of the given collection must be added.c- Collection of objects to add.- Returns:
trueif this list changed as a result of the call,falseotherwise.- Throws:
NullPointerException- If an object to add or its extracted key isnull.IllegalArgumentException- If the extracted key is already used by another object in this list.IndexOutOfBoundsException- If the given index is negative or greater than the size of this list.- See Also:
-
set
Replaces the element at the specified position in this list with the specified element.- Specified by:
setin interfaceList<E>- Overrides:
setin classArrayList<E>- Parameters:
index- Position of the object to replace.obj- Object to be stored at the given position (different from NULL).- Returns:
- Replaced object.
- Throws:
NullPointerException- If the object to add or its extracted key isnull.IllegalArgumentException- If the extracted key is already used by another object in this list.IndexOutOfBoundsException- If the given index is negative or greater than the size of this list.- See Also:
-
clear
public void clear() -
remove
-
remove
-
removeRange
- Overrides:
removeRangein classArrayList<E>- Throws:
IndexOutOfBoundsException
-