- 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 Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(T value)
Add an element to the bag.void
add(T value, int priority)
Add an element to the bag with a specific priority.void
addAll(Iterable<? extends T> values)
Add elements to the bag.void
addAll(Iterable<? extends T> values, int priority)
Add elements to the bag.PriorityBag<T>
copyMe()
Obtain a copy of thisPriorityBag
.static <T> PriorityBag<T>
create()
Create a newPriorityBag
where elements added with no priority will be last in the order.Iterator<T>
iterator()
void
merge(PriorityBag<? extends T> bag)
Merge aPriorityBag
into thisPriorityBag
.PriorityBag<T>
readOnly()
Obtain an immutable copy of thisPriorityBag
.Stream<T>
stream()
Obtain the contents of thisPriorityBag
as an orderedStream
.static <T> PriorityBag<T>
withDefaultPriority(int priority)
Create a newPriorityBag
where elements added with no priority will be be given a default priority value.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
create
public static <T> PriorityBag<T> create()
Create a newPriorityBag
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 newPriorityBag
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 thisPriorityBag
.- Returns:
- a copy of this
PriorityBag
-
readOnly
public PriorityBag<T> readOnly()
Obtain an immutable copy of thisPriorityBag
.- Returns:
- an immutable copy of this
PriorityBag
-
merge
public void merge(PriorityBag<? extends T> bag)
Merge aPriorityBag
into thisPriorityBag
.- 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 addpriority
- 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 addpriority
- the priority of the element
-
stream
public Stream<T> stream()
Obtain the contents of thisPriorityBag
as an orderedStream
.- Returns:
- the contents of this
PriorityBag
as an orderedStream
-
-