Class PriorityBag<T>

java.lang.Object
io.helidon.grpc.core.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 Details

    • 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
    • copyMe

      public PriorityBag<T> copyMe()
      Obtain a copy of this PriorityBag.
      Returns:
      a copy of this PriorityBag
    • readOnly

      public PriorityBag<T> readOnly()
      Obtain an immutable copy of this PriorityBag.
      Returns:
      an immutable copy of this PriorityBag
    • merge

      public void merge(PriorityBag<? extends T> bag)
      Merge a PriorityBag into this PriorityBag.
      Parameters:
      bag - the bag to merge
    • 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
    • stream

      public Stream<T> stream()
      Obtain the contents of this PriorityBag as an ordered Stream.
      Returns:
      the contents of this PriorityBag as an ordered Stream
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>