Class AbstractObjectList<K>

    • Constructor Detail

      • AbstractObjectList

        protected AbstractObjectList()
    • Method Detail

      • ensureIndex

        protected void ensureIndex​(int index)
        Ensures that the given index is nonnegative and not greater than the list size.
        Parameters:
        index - an index.
        Throws:
        IndexOutOfBoundsException - if the given index is negative or greater than the list size.
      • ensureRestrictedIndex

        protected void ensureRestrictedIndex​(int index)
        Ensures that the given index is nonnegative and smaller than the list size.
        Parameters:
        index - an index.
        Throws:
        IndexOutOfBoundsException - if the given index is negative or not smaller than the list size.
      • add

        public void add​(int index,
                        K k)
        Specified by:
        add in interface List<K>
      • remove

        public K remove​(int i)
        Specified by:
        remove in interface List<K>
      • set

        public K set​(int index,
                     K k)
        Specified by:
        set in interface List<K>
      • addAll

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

        public void size​(int size)
        Description copied from interface: ObjectList
        Sets the size of this list.

        If the specified size is smaller than the current size, the last elements are discarded. Otherwise, they are filled with 0/null/false.

        Specified by:
        size in interface ObjectList<K>
        Parameters:
        size - the new size.
      • removeElements

        public void removeElements​(int from,
                                   int to)
        Removes elements of this type-specific list one-by-one.

        This is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.

        Specified by:
        removeElements in interface ObjectList<K>
        Parameters:
        from - the start index (inclusive).
        to - the end index (exclusive).
      • addElements

        public void addElements​(int index,
                                K[] a,
                                int offset,
                                int length)
        Adds elements to this type-specific list one-by-one.

        This is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.

        Specified by:
        addElements in interface ObjectList<K>
        Parameters:
        index - the index at which to add elements.
        a - the array containing the elements.
        offset - the offset of the first element to add.
        length - the number of elements to add.
      • addElements

        public void addElements​(int index,
                                K[] a)
        Description copied from interface: ObjectList
        Add (hopefully quickly) elements to this type-specific list.
        Specified by:
        addElements in interface ObjectList<K>
        Parameters:
        index - the index at which to add elements.
        a - the array containing the elements.
      • getElements

        public void getElements​(int from,
                                Object[] a,
                                int offset,
                                int length)
        Copies element of this type-specific list into the given array one-by-one.

        This is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.

        Specified by:
        getElements in interface ObjectList<K>
        Parameters:
        from - the start index (inclusive).
        a - the destination array.
        offset - the offset into the destination array where to store the first element copied.
        length - the number of elements to be copied.
      • compareTo

        public int compareTo​(List<? extends K> l)
        Compares this list to another object. If the argument is a List, this method performs a lexicographical comparison; otherwise, it throws a ClassCastException.
        Specified by:
        compareTo in interface Comparable<K>
        Parameters:
        l - a list.
        Returns:
        if the argument is a List, a negative integer, zero, or a positive integer as this list is lexicographically less than, equal to, or greater than the argument.
        Throws:
        ClassCastException - if the argument is not a list.
      • push

        public void push​(K o)
        Description copied from interface: Stack
        Pushes the given object on the stack.
        Specified by:
        push in interface Stack<K>
        Parameters:
        o - the object that will become the new top of the stack.
      • pop

        public K pop()
        Description copied from interface: Stack
        Pops the top off the stack.
        Specified by:
        pop in interface Stack<K>
        Returns:
        the top of the stack.
      • top

        public K top()
        Description copied from interface: Stack
        Peeks at the top of the stack (optional operation).
        Specified by:
        top in interface Stack<K>
        Returns:
        the top of the stack.
      • peek

        public K peek​(int i)
        Description copied from interface: Stack
        Peeks at an element on the stack (optional operation).
        Specified by:
        peek in interface Stack<K>
        Returns:
        the i-th element on the stack; 0 represents the top.