Class SimpleArrayList<T>

  • All Implemented Interfaces:
    Iterable<T>, Collection<T>, List<T>

    public class SimpleArrayList<T>
    extends Object
    implements List<T>
    Inexpensive (partial) list implementation. Not fully implemented, just what is needed. As soon as iterators and other things are involved, the memory savings we wanted are gone.

    Minimal checks for data correctness!! This is tuned for speed not elegance or safety.

    Since:
    7.0.0
    Author:
    Rene Schwietzke
    • Constructor Detail

      • SimpleArrayList

        public SimpleArrayList​(int capacity)
        Create a new list with a default capacity.
        Parameters:
        capacity - the capacity
      • SimpleArrayList

        public SimpleArrayList()
        Create a new list with a default capacity.
    • Method Detail

      • add

        public boolean add​(T element)
        Add an element to the end of the list
        Specified by:
        add in interface Collection<T>
        Specified by:
        add in interface List<T>
        Parameters:
        element - the element to add
        Returns:
        true if added and for this impl it is always true
      • add

        public void add​(int index,
                        T element)
        Specified by:
        add in interface List<T>
      • get

        public T get​(int index)
        Return an element at index. No range checks at all.
        Specified by:
        get in interface List<T>
        Parameters:
        index - the position
        Returns:
        the element at this position
      • size

        public int size()
        Returns the size of this list
        Specified by:
        size in interface Collection<T>
        Specified by:
        size in interface List<T>
      • toArray

        public Object[] toArray()
        Creates an array of the elements. This is a copy operation!
        Specified by:
        toArray in interface Collection<T>
        Specified by:
        toArray in interface List<T>
        Returns:
        an array of the elements
      • toArray

        public <T> T[] toArray​(T[] array)
        Creates an array of the elements. This is a copy operation!
        Specified by:
        toArray in interface Collection<T>
        Specified by:
        toArray in interface List<T>
        Returns:
        an array of the elements
      • clear

        public void clear()
        Clears the list by setting the size to zero. It does not release any elements for performance purposes.
        Specified by:
        clear in interface Collection<T>
        Specified by:
        clear in interface List<T>
      • partition

        public List<List<T>> partition​(int count)
        Returns view partitions on the underlying list. If the count is larger than size you get back the maximum possible list number with one element each. If count is 0 or smaller, we correct it to 1.
        Parameters:
        count - how many list do we want
        Returns:
        a list of lists
      • addAll

        public boolean addAll​(int index,
                              Collection<? extends T> c)
        Specified by:
        addAll in interface List<T>
      • set

        public T set​(int index,
                     T element)
        Specified by:
        set in interface List<T>
      • remove

        public T remove​(int index)
        Removes the data at index and shifts all data right of it
        Specified by:
        remove in interface List<T>
        Parameters:
        index - the position to clear
        Returns:
        the previous value at position index
      • subList

        public List<T> subList​(int fromIndex,
                               int toIndex)
        Specified by:
        subList in interface List<T>