Class PriorityBag<T>

  • Type Parameters:
    T - the type of elements in the bag
    All Implemented Interfaces:
    Iterable<T>

    public class PriorityBag<T>
    extends Object
    implements Iterable<T>
    A bag of values ordered by priority.

    An element with lower priority number is more significant than an element with a higher priority number.

    For cases where priority is the same, elements are ordered in the order that they were added to the bag.

    Elements added with negative priorities are assumed to have no priority and will be least significant in order.

    • Method Detail

      • create

        public static <T> PriorityBag<T> create()
        Create a new PriorityBag where elements added with no priority will be last in the order.
        Type Parameters:
        T - the type of elements in the bag
        Returns:
        a new PriorityBag where elements dded with no priority will be last in the order
      • withDefaultPriority

        public static <T> PriorityBag<T> withDefaultPriority​(int priority)
        Create a new PriorityBag where elements added with no priority will be be given a default priority value.
        Type Parameters:
        T - the type of elements in the bag
        Parameters:
        priority - the default priority value to assign to elements added with no priority
        Returns:
        a new PriorityBag where elements added with no priority will be be given a default priority value
      • addAll

        public void addAll​(Iterable<? extends T> values)
        Add elements to the bag.

        If the element's class is annotated with the Priority annotation then that value will be used to determine priority otherwise the default priority value will be used.

        Parameters:
        values - the elements to add
      • addAll

        public void addAll​(Iterable<? extends T> values,
                           int priority)
        Add elements to the bag.
        Parameters:
        values - the elements to add
        priority - the priority to assign to the elements
      • add

        public void add​(T value)
        Add an element to the bag.

        If the element's class is annotated with the Priority annotation then that value will be used to determine priority otherwise the default priority value will be used.

        Parameters:
        value - the element to add
      • add

        public void add​(T value,
                        int priority)
        Add an element to the bag with a specific priority.

        Parameters:
        value - the element to add
        priority - the priority of the element