Package moa.core

Class FixedLengthList<E>

  • Type Parameters:
    E - the type of object found in the FixedLengthList
    All Implemented Interfaces:
    Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess

    public class FixedLengthList<E>
    extends ArrayList<E>
    FixedLengthList is an extension of an ArrayList with a fixed maximum size. If an element is added that would put the list over its maximum size then the oldest element in the list is removed.
    Author:
    Richard Hugh Moulton
    See Also:
    Serialized Form
    • Constructor Detail

      • FixedLengthList

        public FixedLengthList​(int m)
        Constructor
        Parameters:
        m - the length of the list
    • Method Detail

      • add

        public boolean add​(E entry)
        Calls super.add(entry) to append the entry to the end of the FixedLengthList. Removes the oldest entry if required. Returns true at completion.
        Specified by:
        add in interface Collection<E>
        Specified by:
        add in interface List<E>
        Overrides:
        add in class ArrayList<E>
        Parameters:
        entry - the entry to add to the list
      • addAll

        public boolean addAll​(Collection<? extends E> c)
        Appends all of the elements in the argument collection in the order that they are returned by the collection's iterator. Does so by calling FixedLengthList.add(E entry).
        Specified by:
        addAll in interface Collection<E>
        Specified by:
        addAll in interface List<E>
        Overrides:
        addAll in class ArrayList<E>
      • getOldestEntry

        public E getOldestEntry()
        Returns:
        the least recently added object in the list.
      • getYoungestEntry

        public E getYoungestEntry()
        Returns:
        the most recently added object in the list.
      • getMaxSize

        public int getMaxSize()
        Returns:
        the size limit of the FixedLengthList.