- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<E>
-
- org.arakhne.afc.util.InformedArrayList<E>
-
- Type Parameters:
E
- is the type of the list's elements.
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<E>
,Collection<E>
,List<E>
,RandomAccess
,InformedIterable<E>
public class InformedArrayList<E> extends ArrayList<E> implements InformedIterable<E>
This is an array list which knows that is the type of their elements.The type of the elements is automatically computed when adding an element inside the list.
For the removal actions, a flag is available to force this informed array list to compute the best fitting type after the removal action. If this flag is
false
, this class will keep unchanged the previously computed type. By default, this flag isfalse
(seeisTypeRecomputedAfterRemoval()
).- Since:
- 14.0
- Version:
- 17.0 2020-01-04 14:41:38
- Author:
- Stéphane GALLAND
- See Also:
- Serialized Form
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- util
-
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description InformedArrayList()
Create an empty list.InformedArrayList(int initialCapacity)
Create an empty list with the given initial capacity.InformedArrayList(int initialCapacity, Class<? extends E> clazz)
Constructor.InformedArrayList(Class<? extends E> clazz)
Constructor.InformedArrayList(Collection<? extends E> collection)
Create a list with the given collection.InformedArrayList(Collection<? extends E> collection, Class<? extends E> clazz)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, E element)
boolean
add(E elt)
boolean
addAll(int index, Collection<? extends E> collection)
boolean
addAll(Collection<? extends E> collection)
void
clear()
protected static <E> Class<? extends E>
extractClassFrom(Collection<? extends E> collection)
Extract the upper class that contains all the elements of this array.Class<? extends E>
getElementType()
Replies the class of the elements in this iterable object.boolean
isTypeRecomputedAfterRemoval()
Replies if this informed array list is trying to compute the best fitting type after a removal.E
remove(int index)
boolean
remove(Object obj)
protected void
removeRange(int fromIndex, int toIndex)
E
set(int index, E element)
void
setElementType(Class<? extends E> type)
Change the class of the elements in this iterable object.void
setTypeRecomputedAfterRemoval(boolean update)
Set if this informed array list is trying to compute the best fitting type after a removal.protected void
updateComponentType(E newElement)
Update the component type information with the type of the new array element.protected void
updateComponentType(Collection<? extends E> newElements)
Update the component type information with the type of the new array element.-
Methods inherited from class java.util.ArrayList
clone, contains, 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
-
-
-
-
Constructor Detail
-
InformedArrayList
public InformedArrayList()
Create an empty list.
-
InformedArrayList
public InformedArrayList(int initialCapacity)
Create an empty list with the given initial capacity.- Parameters:
initialCapacity
- is the initial capacity.
-
InformedArrayList
public InformedArrayList(Collection<? extends E> collection)
Create a list with the given collection.- Parameters:
collection
- is the list of initial elements.
-
InformedArrayList
public InformedArrayList(Class<? extends E> clazz)
Constructor.- Parameters:
clazz
- is the initial top type of the array's elements.
-
InformedArrayList
public InformedArrayList(int initialCapacity, Class<? extends E> clazz)
Constructor.- Parameters:
initialCapacity
- is the initial capacity.clazz
- is the initial top type of the array's elements.
-
InformedArrayList
public InformedArrayList(Collection<? extends E> collection, Class<? extends E> clazz)
Constructor.- Parameters:
collection
- is the list of initial elements.clazz
- is the initial top type of the array's elements.
-
-
Method Detail
-
extractClassFrom
protected static <E> Class<? extends E> extractClassFrom(Collection<? extends E> collection)
Extract the upper class that contains all the elements of this array.- Type Parameters:
E
- is the type of the list's elements.- Parameters:
collection
- is the collection to scan- Returns:
- the top class of all the elements.
-
isTypeRecomputedAfterRemoval
public boolean isTypeRecomputedAfterRemoval()
Replies if this informed array list is trying to compute the best fitting type after a removal. Iffalse
, this class will keep unchanged the previously computed type.- Returns:
true
if the type is recomputed after a removal,false
if not.
-
setTypeRecomputedAfterRemoval
public void setTypeRecomputedAfterRemoval(boolean update)
Set if this informed array list is trying to compute the best fitting type after a removal. Iffalse
, this class will keep unchanged the previously computed type.- Parameters:
update
- istrue
if the type is recomputed after a removal,false
if not.
-
updateComponentType
protected final void updateComponentType(E newElement)
Update the component type information with the type of the new array element.- Parameters:
newElement
- is the element for which the known top type in this array must be eventually updated.
-
updateComponentType
protected final void updateComponentType(Collection<? extends E> newElements)
Update the component type information with the type of the new array element.- Parameters:
newElements
- are the elements for which the known top type in this array must be eventually updated.
-
getElementType
public Class<? extends E> getElementType()
Description copied from interface:InformedIterable
Replies the class of the elements in this iterable object.- Specified by:
getElementType
in interfaceInformedIterable<E>
- Returns:
- the type of the elements.
-
setElementType
public void setElementType(Class<? extends E> type)
Change the class of the elements in this iterable object.- Parameters:
type
- the type of the elements.- Since:
- 15.0
-
add
public boolean add(E elt)
-
add
public void add(int index, E element)
-
addAll
public boolean addAll(Collection<? extends E> collection)
-
addAll
public boolean addAll(int index, Collection<? extends E> collection)
-
clear
public void clear()
-
remove
public E remove(int index)
-
remove
public boolean remove(Object obj)
-
removeRange
protected void removeRange(int fromIndex, int toIndex)
- Overrides:
removeRange
in classArrayList<E>
-
-