Class 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 is false (see isTypeRecomputedAfterRemoval()).

    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
    • 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. If false, 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. If false, this class will keep unchanged the previously computed type.
        Parameters:
        update - is true 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 interface InformedIterable<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 void add​(int index,
                        E element)
        Specified by:
        add in interface List<E>
        Overrides:
        add in class ArrayList<E>
      • removeRange

        protected void removeRange​(int fromIndex,
                                   int toIndex)
        Overrides:
        removeRange in class ArrayList<E>
      • set

        public E set​(int index,
                     E element)
        Specified by:
        set in interface List<E>
        Overrides:
        set in class ArrayList<E>