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 class
Default implementation ofTextualSearchList.KeyExtractor
.static interface
Lets 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 TypeMethodDescriptionvoid
Adds the given object at the given position in this list.boolean
Adds the given object at the end of this list.boolean
addAll
(int index, Collection<? extends E> c) Appends all the objects of the given collection in this list after the given position.boolean
addAll
(Collection<? extends E> c) Appends all the objects of the given collection in this list.void
clear()
boolean
Returns 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) boolean
protected void
removeRange
(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, trimToSize
Methods inherited from class java.util.AbstractCollection
containsAll, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
Methods 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:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceList<E>
- Overrides:
contains
in 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:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceList<E>
- Overrides:
add
in 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:
add
in interfaceList<E>
- Overrides:
add
in 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:
addAll
in interfaceCollection<E>
- Specified by:
addAll
in interfaceList<E>
- Overrides:
addAll
in classArrayList<E>
- Parameters:
c
- Collection of objects to add.- Returns:
true
if this list changed as a result of the call,false
otherwise.- 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:
addAll
in interfaceList<E>
- Overrides:
addAll
in classArrayList<E>
- Parameters:
index
- Position from which objects of the given collection must be added.c
- Collection of objects to add.- Returns:
true
if this list changed as a result of the call,false
otherwise.- 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:
set
in interfaceList<E>
- Overrides:
set
in 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:
removeRange
in classArrayList<E>
- Throws:
IndexOutOfBoundsException
-