Class SortedIntArrayList

All Implemented Interfaces:
IntCollection, IntList, Serializable, Cloneable, Iterable<Integer>, Collection<Integer>, List<Integer>, RandomAccess

public class SortedIntArrayList extends IntArrayList implements Cloneable, Serializable
A SortedIntArrayList stores is elements in numerical order and provides means of quickly locating objects.
Author:
AO Industries, Inc.
See Also:
  • Constructor Details

    • SortedIntArrayList

      public SortedIntArrayList(int initialCapacity)
      Constructs an empty list with the specified initial capacity.
      Parameters:
      initialCapacity - the initial capacity of the list.
      Throws:
      IllegalArgumentException - if the specified initial capacity is negative
    • SortedIntArrayList

      public SortedIntArrayList()
      Constructs an empty list with an initial capacity of ten.
  • Method Details

    • clone

      public Object clone()
      Description copied from class: IntArrayList
      Returns a shallow copy of this IntArrayList instance. (The elements themselves are not copied.)
      Overrides:
      clone in class IntArrayList
      Returns:
      a clone of this IntArrayList instance.
    • binarySearch

      protected int binarySearch(int value)
      Performs a binary search for the provide value. It will return any matching element, not necessarily the first or the last.
    • indexOf

      public int indexOf(int elem)
      Searches for the first occurrence of the given value.
      Specified by:
      indexOf in interface IntList
      Overrides:
      indexOf in class IntArrayList
      Parameters:
      elem - the value
      Returns:
      the index of the first occurrence of the argument in this list; returns -1 if the object is not found.
      See Also:
    • lastIndexOf

      public int lastIndexOf(int elem)
      Returns the index of the last occurrence of the specified object in this list.
      Specified by:
      lastIndexOf in interface IntList
      Overrides:
      lastIndexOf in class IntArrayList
      Parameters:
      elem - the desired element.
      Returns:
      the index of the last occurrence of the specified object in this list; returns -1 if the object is not found.
    • set

      public int set(int index, int element)
      Not allowed to set specific indexes.
      Specified by:
      set in interface IntList
      Overrides:
      set in class IntArrayList
      Parameters:
      index - index of element to replace.
      element - element to be stored at the specified position.
      Returns:
      the element previously at the specified position.
    • add

      public boolean add(int o)
      Adds the specified element in sorted position within this list.
      Specified by:
      add in interface IntCollection
      Overrides:
      add in class IntArrayList
      Parameters:
      o - element to be appended to this list.
      Returns:
      true (as per the general contract of Collection.add).
    • add

      public void add(int index, int element)
      Not allowed to add to specific indexes.
      Specified by:
      add in interface IntList
      Overrides:
      add in class IntArrayList
      Parameters:
      index - index at which the specified element is to be inserted.
      element - element to be inserted.
    • removeByValue

      public boolean removeByValue(int value)
      Removes a single instance of the specified element from this list, if it is present (optional operation). More formally, removes an element e such that (o == null ? e == null : o.equals(e)), if the list contains one or more such elements. Returns true if the list contained the specified element (or equivalently, if the list changed as a result of the call).
      Specified by:
      removeByValue in interface IntCollection
      Overrides:
      removeByValue in class IntArrayList
      Parameters:
      value - element to be removed from this list, if present.
      Returns:
      true if the list contained the specified element.
    • addAll

      public boolean addAll(Collection<? extends Integer> c)
      Adds all of the elements in the specified Collection and sorts during the add. This may operate slowly as it is the same as individual calls to the add method.
      Specified by:
      addAll in interface Collection<Integer>
      Specified by:
      addAll in interface List<Integer>
      Overrides:
      addAll in class IntArrayList
      Parameters:
      c - the elements to be inserted into this list.
      Returns:
      true if this list changed as a result of the call.
    • addAll

      public boolean addAll(int index, Collection<? extends Integer> c)
      Not allowed to add to a specific index.
      Specified by:
      addAll in interface List<Integer>
      Overrides:
      addAll in class IntArrayList
      Parameters:
      index - index at which to insert first element from the specified collection.
      c - elements to be inserted into this list.
      Returns:
      true if this list changed as a result of the call.