Class PriorityList<E>

  • All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>

    public class PriorityList<E>
    extends java.util.AbstractList<E>
    Builds a simple, priority-based List implementation. The list will be sorted according to the priority. If two items are inserted with the same priority, their order is the insertion order - i.e. the new one is appended last in the insertion list.

    Priority is an integer, and the list is sorted in descending order (that is, 100 is before 10 is before 0 is before -40).

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFAULT_PRIORITY
      This is the default priority, which is used if no priority is defined.
      • Fields inherited from class java.util.AbstractList

        modCount
    • Constructor Summary

      Constructors 
      Constructor Description
      PriorityList()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(E o)
      Adds an object using the default priority to the List.
      void add​(E o, int priority)
      Adds an object to its correct place in the list, using the given priority.
      E get​(int index)
      Returns the object at index "index".
      int size()
      Returns the current size of the list.
      • Methods inherited from class java.util.AbstractList

        add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
      • Methods inherited from class java.util.AbstractCollection

        addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.List

        addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
    • Field Detail

      • DEFAULT_PRIORITY

        public static final int DEFAULT_PRIORITY
        This is the default priority, which is used if no priority is defined. It's current value is zero.
        See Also:
        Constant Field Values
    • Method Detail

      • add

        public void add​(E o,
                        int priority)
        Adds an object to its correct place in the list, using the given priority.
        Parameters:
        o - Object to add.
        priority - Priority.
      • add

        public boolean add​(E o)
        Adds an object using the default priority to the List.
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add in interface java.util.List<E>
        Overrides:
        add in class java.util.AbstractList<E>
        Parameters:
        o - Object to add.
        Returns:
        true, as per the general Collections.add contract.
      • get

        public E get​(int index)
        Returns the object at index "index".
        Specified by:
        get in interface java.util.List<E>
        Specified by:
        get in class java.util.AbstractList<E>
        Parameters:
        index - The index.
        Returns:
        The object at the list at the position "index".
      • size

        public int size()
        Returns the current size of the list.
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in interface java.util.List<E>
        Specified by:
        size in class java.util.AbstractCollection<E>
        Returns:
        size of the list.