java.lang.Object
io.helidon.grpc.core.WeightedBag<T>
- Type Parameters:
T
- the type of elements in the bag
- All Implemented Interfaces:
Iterable<T>
A bag of values ordered by weight. All weights must be greater or equal to 0.
The higher the weight the higher the priority. For cases where the weight is the same, elements are returned in the order that they were added to the bag.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add an element to the bag.void
Add an element to the bag with a specific weight.void
Add elements to the bag.void
Add elements to the bag with a given weight.copyMe()
Obtain a copy of thisWeightedBag
.static <T> WeightedBag
<T> create()
Create a newWeightedBag
where elements added with no weight will be given a default weight of 0.static <T> WeightedBag
<T> create
(double defaultWeight) Create a newWeightedBag
where elements added with no weight will be given a default weight of 0.boolean
isEmpty()
Check if bag is empty.iterator()
void
merge
(WeightedBag<? extends T> bag) Merge aWeightedBag
into thisWeightedBag
.readOnly()
Obtain an immutable copy of thisWeightedBag
.stream()
Obtain the contents of thisWeightedBag
as an orderedStream
.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 Details
-
create
Create a newWeightedBag
where elements added with no weight will be given a default weight of 0.- Type Parameters:
T
- the type of elements in the bag- Returns:
- a new
WeightedBag
where elements added with no weight will be givenWeighted.DEFAULT_WEIGHT
-
create
Create a newWeightedBag
where elements added with no weight will be given a default weight of 0.- Type Parameters:
T
- the type of elements in the bag- Parameters:
defaultWeight
- default weight for elements- Returns:
- a new
WeightedBag
where elements added with no weight will be givenWeighted.DEFAULT_WEIGHT
-
isEmpty
public boolean isEmpty()Check if bag is empty.- Returns:
- outcome of test
-
readOnly
Obtain an immutable copy of thisWeightedBag
.- Returns:
- an immutable copy of this
WeightedBag
-
merge
Merge aWeightedBag
into thisWeightedBag
.- Parameters:
bag
- the bag to merge
-
copyMe
Obtain a copy of thisWeightedBag
.- Returns:
- a copy of this
WeightedBag
-
addAll
Add elements to the bag.If the element's class is annotated with the
Weight
annotation then that value will be used to determine weight otherwise the default weight value will be used.- Parameters:
values
- the elements to add
-
addAll
Add elements to the bag with a given weight.- Parameters:
values
- the elements to addweight
- the weight to assign to the elements
-
add
Add an element to the bag.If the element's class is annotated with the
Weight
annotation then that value will be used to determine weight otherwise the default weight value will be used.- Parameters:
value
- the element to add
-
add
Add an element to the bag with a specific weight.- Parameters:
value
- the element to addweight
- the weight of the element
-
stream
Obtain the contents of thisWeightedBag
as an orderedStream
.- Returns:
- the contents of this
WeightedBag
as an orderedStream
-
iterator
-