E
- Type of object to manage in this list.public class TextualSearchList<E>
extends java.util.ArrayList<E>
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 !
Modifier and Type | Class and Description |
---|---|
protected static class |
TextualSearchList.DefaultKeyExtractor<E>
Default implementation of
TextualSearchList.KeyExtractor . |
static interface |
TextualSearchList.KeyExtractor<E>
Lets extract an unique textual key (case-sensitive) from a given type of object.
|
Modifier and Type | Field and Description |
---|---|
protected java.util.HashMap<java.lang.String,java.util.ArrayList<E>> |
csMap
Map which associates objects of type E with its textual string (case-sensitive).
|
TextualSearchList.KeyExtractor<E> |
keyExtractor
Object to use to extract an unique textual string.
|
protected java.util.HashMap<java.lang.String,java.util.ArrayList<E>> |
ncsMap
Map which associates objects of type E with their lower-case textual string.
|
Constructor and Description |
---|
TextualSearchList()
Builds an empty TextualSearchList.
|
TextualSearchList(java.util.Collection<? extends E> c)
Builds a TextualSearchList filled with the objects of the given collection.
|
TextualSearchList(java.util.Collection<? extends E> c,
TextualSearchList.KeyExtractor<E> keyExtractor)
Builds a TextualSearchList filled with the objects of the given collection.
|
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.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E obj)
Adds the given object at the end of this list.
|
void |
add(int index,
E obj)
Adds the given object at the given position in this list.
|
boolean |
addAll(java.util.Collection<? extends E> c)
Appends all the objects of the given collection in this list.
|
boolean |
addAll(int index,
java.util.Collection<? extends E> c)
Appends all the objects of the given collection in this list after the given position.
|
void |
clear() |
boolean |
contains(java.lang.Object o)
Returns true if this list contains the specified element.
|
java.util.List<E> |
get(java.lang.String key)
Searches (CASE-INSENSITIVE) the object which has the given key.
|
java.util.List<E> |
get(java.lang.String key,
boolean caseSensitive)
Searches of all the object which has the given key.
|
E |
remove(int index) |
boolean |
remove(java.lang.Object obj) |
protected void |
removeRange(int fromIndex,
int toIndex) |
E |
set(int index,
E obj)
Replaces the element at the specified position in this list with the specified element.
|
clone, ensureCapacity, forEach, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, removeAll, removeIf, replaceAll, retainAll, size, sort, spliterator, subList, toArray, toArray, trimToSize
public final TextualSearchList.KeyExtractor<E> keyExtractor
protected final java.util.HashMap<java.lang.String,java.util.ArrayList<E>> csMap
protected final java.util.HashMap<java.lang.String,java.util.ArrayList<E>> ncsMap
public TextualSearchList()
Builds an empty TextualSearchList.
Note:
the key of inserted objects will be the string returned by their toString()
function.
TextualSearchList(KeyExtractor)
public TextualSearchList(TextualSearchList.KeyExtractor<E> keyExtractor)
keyExtractor
- The object to use to extract a textual key from objects to insert.ArrayList.ArrayList()
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.
initialCapacity
- Initial capacity of this list.TextualSearchList(int, KeyExtractor)
public TextualSearchList(int initialCapacity, TextualSearchList.KeyExtractor<E> keyExtractor)
initialCapacity
- Initial capacity of this list.keyExtractor
- The object to use to extract a textual key from objects to insert.ArrayList.ArrayList(int)
public TextualSearchList(java.util.Collection<? extends E> c)
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.
c
- Collection to copy into this list.public TextualSearchList(java.util.Collection<? extends E> c, TextualSearchList.KeyExtractor<E> keyExtractor)
c
- Collection to copy into this list.keyExtractor
- The object object to use to extract a textual key from objects to insert.addAll(Collection)
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection<E>
contains
in interface java.util.List<E>
contains
in class java.util.ArrayList<E>
ArrayList.contains(java.lang.Object)
,
getKey(Object)
public final java.util.List<E> get(java.lang.String key)
key
- Textual key of the object to search.null
.public java.util.List<E> get(java.lang.String key, boolean caseSensitive)
key
- Textual key of the object to search.caseSensitive
- true to consider the case of the key, false otherwise.public boolean add(E obj) throws java.lang.NullPointerException, java.lang.IllegalArgumentException
add
in interface java.util.Collection<E>
add
in interface java.util.List<E>
add
in class java.util.ArrayList<E>
obj
- Object to add (different from NULL).java.lang.NullPointerException
- If the given object or its extracted key is null
.java.lang.IllegalArgumentException
- If the extracted key is already used by another object in this list.ArrayList.add(java.lang.Object)
public void add(int index, E obj) throws java.lang.NullPointerException, java.lang.IllegalArgumentException, java.lang.IndexOutOfBoundsException
add
in interface java.util.List<E>
add
in class java.util.ArrayList<E>
index
- Index at which the given object must be added.obj
- Object to add (different from NULL).java.lang.NullPointerException
- If the given object or its extracted key is null
.java.lang.IllegalArgumentException
- If the extracted key is already used by another object in this list.java.lang.IndexOutOfBoundsException
- If the given index is negative or greater than the size of this list.ArrayList.add(int, java.lang.Object)
public boolean addAll(java.util.Collection<? extends E> c) throws java.lang.NullPointerException, java.lang.IllegalArgumentException
addAll
in interface java.util.Collection<E>
addAll
in interface java.util.List<E>
addAll
in class java.util.ArrayList<E>
c
- Collection of objects to add.true
if this list changed as a result of the call, false
otherwise.java.lang.NullPointerException
- If an object to add or its extracted key is null
.java.lang.IllegalArgumentException
- If the extracted key is already used by another object in this list.ArrayList.addAll(java.util.Collection)
,
add(Object)
public boolean addAll(int index, java.util.Collection<? extends E> c) throws java.lang.NullPointerException, java.lang.IllegalArgumentException, java.lang.IndexOutOfBoundsException
addAll
in interface java.util.List<E>
addAll
in class java.util.ArrayList<E>
index
- Position from which objects of the given collection must be added.c
- Collection of objects to add.true
if this list changed as a result of the call, false
otherwise.java.lang.NullPointerException
- If an object to add or its extracted key is null
.java.lang.IllegalArgumentException
- If the extracted key is already used by another object in this list.java.lang.IndexOutOfBoundsException
- If the given index is negative or greater than the size of this list.ArrayList.addAll(int, java.util.Collection)
,
add(int, Object)
public E set(int index, E obj) throws java.lang.NullPointerException, java.lang.IllegalArgumentException
set
in interface java.util.List<E>
set
in class java.util.ArrayList<E>
index
- Position of the object to replace.obj
- Object to be stored at the given position (different from NULL).java.lang.NullPointerException
- If the object to add or its extracted key is null
.java.lang.IllegalArgumentException
- If the extracted key is already used by another object in this list.java.lang.IndexOutOfBoundsException
- If the given index is negative or greater than the size of this list.ArrayList.set(int, java.lang.Object)
public void clear()
public E remove(int index)
public boolean remove(java.lang.Object obj)
protected void removeRange(int fromIndex, int toIndex) throws java.lang.IndexOutOfBoundsException
removeRange
in class java.util.ArrayList<E>
java.lang.IndexOutOfBoundsException