Class ArrayObjectList

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

    public final class ArrayObjectList
    extends Object
    An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted.
    The user can access elements by their integer index (position in the list), and search for elements in the list.
    This implementation uses a java script array as back-end to store objects (native JavaScript objects).
    Author:
    Andrea "Stock" Stocchero
    • Constructor Summary

      Constructors 
      Constructor Description
      ArrayObjectList()
      Creates an empty list
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int index, NativeObject element)
      Inserts the specified element at the specified position in this list.
      Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
      boolean add​(NativeObject element)
      Appends the specified element to the end of this list
      boolean addAll​(int index, Collection<? extends E> collection)  
      boolean addAll​(Collection<? extends NativeObject> collection)
      Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator
      void addAll​(NativeObject... values)
      Loads an array of elements in the list
      protected boolean checkRange​(int index)
      Checks if the index is in the right range.
      void clear()
      Removes all of the elements from this list.
      boolean contains​(Object object)
      Returns true if this list contains the specified element.
      boolean containsAll​(Collection<?> collection)
      Returns true if this list contains all of the elements of the specified collection.
      NativeObject get​(int index)
      Returns the element at the specified position in this list.
      int indexOf​(Object object)
      Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
      boolean isEmpty()
      Returns true if this list contains no elements
      Iterator<E> iterator()
      Returns an iterator over the elements in this list in proper sequence.
      int lastIndexOf​(Object object)
      Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.
      ListIterator<E> listIterator()
      Returns a list iterator over the elements in this list
      ListIterator<E> listIterator​(int index)
      Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.
      The specified index indicates the first element that would be returned by an initial call to next.
      An initial call to previous would return the element with the specified index minus one.
      NativeObject remove​(int index)
      Removes the element at the specified position in this list.
      Shifts any subsequent elements to the left (subtracts one from their indices).
      boolean remove​(Object object)
      Removes the first occurrence of the specified element from this list, if it is present.
      boolean removeAll​(Collection<?> collection)
      Removes from this list all of its elements that are contained in the specified collection.
      boolean retainAll​(Collection<?> collection)
      Retains only the elements in this list that are contained in the specified collection.
      In other words, removes from this list all of its elements that are not contained in the specified collection.
      NativeObject set​(int index, NativeObject element)
      Replaces the element at the specified position in this list with the specified element.
      int size()
      Returns the number of elements in this list.
      List<E> subList​(int fromIndex, int toIndex)
      Not implemented
      Object[] toArray()  
      <T> T[] toArray​(T[] a)  
      String toString()  
    • Constructor Detail

      • ArrayObjectList

        public ArrayObjectList()
        Creates an empty list
    • Method Detail

      • addAll

        public void addAll​(NativeObject... values)
        Loads an array of elements in the list
        Parameters:
        values - an array of elements to be loaded
      • add

        public boolean add​(NativeObject element)
        Appends the specified element to the end of this list
      • addAll

        public boolean addAll​(Collection<? extends NativeObject> collection)
        Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator
      • retainAll

        public boolean retainAll​(Collection<?> collection)
        Retains only the elements in this list that are contained in the specified collection.
        In other words, removes from this list all of its elements that are not contained in the specified collection.
      • clear

        public void clear()
        Removes all of the elements from this list. The list will be empty after this call returns.
      • get

        public NativeObject get​(int index)
        Returns the element at the specified position in this list. If index out of range, returns null
      • set

        public NativeObject set​(int index,
                                NativeObject element)
        Replaces the element at the specified position in this list with the specified element. If index out of range, returns null
      • add

        public void add​(int index,
                        NativeObject element)
        Inserts the specified element at the specified position in this list.
        Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
      • remove

        public NativeObject remove​(int index)
        Removes the element at the specified position in this list.
        Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.
      • indexOf

        public int indexOf​(Object object)
        Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
      • lastIndexOf

        public int lastIndexOf​(Object object)
        Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.
      • toArray

        public Object[] toArray()
      • size

        public int size()
        Returns the number of elements in this list.
        Specified by:
        size in interface Collection<E>
        Specified by:
        size in interface List<E>
      • isEmpty

        public boolean isEmpty()
        Returns true if this list contains no elements
        Specified by:
        isEmpty in interface Collection<E>
        Specified by:
        isEmpty in interface List<E>
      • contains

        public boolean contains​(Object object)
        Returns true if this list contains the specified element.
        Specified by:
        contains in interface Collection<E>
        Specified by:
        contains in interface List<E>
      • toArray

        public <T> T[] toArray​(T[] a)
        Specified by:
        toArray in interface Collection<E>
        Specified by:
        toArray in interface List<E>
      • listIterator

        public ListIterator<E> listIterator()
        Returns a list iterator over the elements in this list
        Specified by:
        listIterator in interface List<E>
      • addAll

        public final boolean addAll​(int index,
                                    Collection<? extends E> collection)
        Specified by:
        addAll in interface List<E>
      • remove

        public final boolean remove​(Object object)
        Removes the first occurrence of the specified element from this list, if it is present. If this list does not contain the element, it is unchanged.
        Specified by:
        remove in interface Collection<E>
        Specified by:
        remove in interface List<E>
      • containsAll

        public boolean containsAll​(Collection<?> collection)
        Returns true if this list contains all of the elements of the specified collection.
        Specified by:
        containsAll in interface Collection<E>
        Specified by:
        containsAll in interface List<E>
      • removeAll

        public final boolean removeAll​(Collection<?> collection)
        Removes from this list all of its elements that are contained in the specified collection.
        Specified by:
        removeAll in interface Collection<E>
        Specified by:
        removeAll in interface List<E>
      • listIterator

        public ListIterator<E> listIterator​(int index)
        Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list.
        The specified index indicates the first element that would be returned by an initial call to next.
        An initial call to previous would return the element with the specified index minus one.
        Specified by:
        listIterator in interface List<E>
      • subList

        public List<E> subList​(int fromIndex,
                               int toIndex)
        Not implemented
        Specified by:
        subList in interface List<E>
      • checkRange

        protected final boolean checkRange​(int index)
        Checks if the index is in the right range.
        Parameters:
        index - index to be checked
        Returns:
        true if the index is in the right range otherwise false