Package adams.data

Class SortedList<T>

    • Field Detail

      • m_List

        protected ArrayList<T> m_List
        the underlying list.
      • m_Comparator

        protected Comparator m_Comparator
        the comparator to use.
      • m_DefaultComparator

        protected static Comparator m_DefaultComparator
        the default comparator.
    • Constructor Detail

      • SortedList

        public SortedList​(Comparator comp)
        Initializes the list. Uses the specified Comparator.
        Parameters:
        comp - the comparator to use
      • SortedList

        public SortedList​(int initialCapacity)
        Initializes the list. Uses the SortedList.DefaultComparator.
        Parameters:
        initialCapacity - the initial capacity of the list
      • SortedList

        public SortedList​(int initialCapacity,
                          Comparator comp)
        Initializes the list. Uses the specified Comparator.
        Parameters:
        initialCapacity - the initial capacity of the list
        comp - the comparator to use
      • SortedList

        public SortedList​(Collection<? extends T> c,
                          Comparator comp)
        Initializes the list. Uses the specified Comparator.
        Parameters:
        c - the data to populate the list with
        comp - the comparator to use
    • Method Detail

      • getComparator

        public Comparator getComparator()
        Returns the comparator in use.
        Returns:
        the comparator
      • sort

        protected void sort()
        Sorts the list.
      • size

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

        public boolean isEmpty()
        Returns whether the list is empty.
        Specified by:
        isEmpty in interface Collection<T>
        Specified by:
        isEmpty in interface List<T>
        Returns:
        true if empty
      • contains

        public boolean contains​(Object o)
        Checks whether the object is present.
        Specified by:
        contains in interface Collection<T>
        Specified by:
        contains in interface List<T>
        Returns:
        true if present
      • toArray

        public Object[] toArray()
        Returns the list as array.
        Specified by:
        toArray in interface Collection<T>
        Specified by:
        toArray in interface List<T>
        Returns:
        the items as array
      • toArray

        public <T> T[] toArray​(T[] a)
        Returns the list as array.
        Specified by:
        toArray in interface Collection<T>
        Specified by:
        toArray in interface List<T>
        Parameters:
        a - the array to copy the items into
        Returns:
        the items as array
      • add

        public boolean add​(T e)
        Adds the element to the list.
        Specified by:
        add in interface Collection<T>
        Specified by:
        add in interface List<T>
        Parameters:
        e - the element to add
        Returns:
        true if list modified
      • remove

        public boolean remove​(Object o)
        Removes the object from the list.
        Specified by:
        remove in interface Collection<T>
        Specified by:
        remove in interface List<T>
        Parameters:
        o - the object to remove
        Returns:
        true if list modified
      • containsAll

        public boolean containsAll​(Collection<?> c)
        Checks whether all items of the collected are contained in the list.
        Specified by:
        containsAll in interface Collection<T>
        Specified by:
        containsAll in interface List<T>
        Parameters:
        c - the collection to check
        Returns:
        true if all contained
      • addAll

        public boolean addAll​(Collection<? extends T> c)
        Adds all the elements of the collection to this list.
        Specified by:
        addAll in interface Collection<T>
        Specified by:
        addAll in interface List<T>
        Parameters:
        c - the collection to add
        Returns:
        true if list modified
      • removeAll

        public boolean removeAll​(Collection<?> c)
        Removes all items from the collection in this list.
        Specified by:
        removeAll in interface Collection<T>
        Specified by:
        removeAll in interface List<T>
        Parameters:
        c - the items to remove
        Returns:
        true if list modified
      • retainAll

        public boolean retainAll​(Collection<?> c)
        Keeps all items present in the collection.
        Specified by:
        retainAll in interface Collection<T>
        Specified by:
        retainAll in interface List<T>
        Parameters:
        c - the items to keep
        Returns:
        true if list modified
      • clear

        public void clear()
        Empties the list.
        Specified by:
        clear in interface Collection<T>
        Specified by:
        clear in interface List<T>
      • addAll

        public boolean addAll​(int index,
                              Collection<? extends T> c)
        Adds all the elements of the collection starting at the specified index. NB: triggers a complete sort!
        Specified by:
        addAll in interface List<T>
        Parameters:
        index - the starting index
        c - the elements to add
        Returns:
        true if list modified
      • get

        public T get​(int index)
        Returns the item at the specified position.
        Specified by:
        get in interface List<T>
        Parameters:
        index - the position to get the item at
      • set

        public T set​(int index,
                     T element)
        Sets the item at the specified position. NB: expensive as it triggers a complete sort!
        Specified by:
        set in interface List<T>
        Parameters:
        index - the position to set the element
        element - the element to set
        Returns:
        the previous element at that position
      • add

        public void add​(int index,
                        T element)
        Adds the element at the specified position. NB: triggers a complete sort!
        Specified by:
        add in interface List<T>
        Parameters:
        index - the index to insert the element
        element - the element to insert
      • remove

        public T remove​(int index)
        Removes the item at the specified position.
        Specified by:
        remove in interface List<T>
        Parameters:
        index - the position of the item
        Returns:
        the removed item
      • indexOf

        public int indexOf​(Object o)
        Returns the index of the object in the list. Uses fast binary search for locating the object.
        Specified by:
        indexOf in interface List<T>
        Parameters:
        o - the object to find
        Returns:
        the index, -1 if not found
      • lastIndexOf

        public int lastIndexOf​(Object o)
        Returns the last index for the object in this list.
        Specified by:
        lastIndexOf in interface List<T>
        Parameters:
        o - the object to locate
        Returns:
        the index, -1 if not found
      • listIterator

        public ListIterator<T> listIterator()
        Returns a list iterator over the items.
        Specified by:
        listIterator in interface List<T>
        Returns:
        the iterator
      • listIterator

        public ListIterator<T> listIterator​(int index)
        Returns a list iterator over the items starting at the position.
        Specified by:
        listIterator in interface List<T>
        Parameters:
        index - the starting index
        Returns:
        the iterator
      • subList

        public List<T> subList​(int fromIndex,
                               int toIndex)
        Returns a sublist.
        Specified by:
        subList in interface List<T>
        Parameters:
        fromIndex - the starting index