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 TypeMethodDescriptionvoidAdd an element to the bag.voidAdd an element to the bag with a specific weight.voidAdd elements to the bag.voidAdd elements to the bag with a given weight.copyMe()Obtain a copy of thisWeightedBag.static <T> WeightedBag<T> create()Create a newWeightedBagwhere elements added with no weight will be given a default weight of 0.static <T> WeightedBag<T> create(double defaultWeight) Create a newWeightedBagwhere elements added with no weight will be given a default weight of 0.booleanisEmpty()Check if bag is empty.iterator()voidmerge(WeightedBag<? extends T> bag) Merge aWeightedBaginto thisWeightedBag.readOnly()Obtain an immutable copy of thisWeightedBag.stream()Obtain the contents of thisWeightedBagas an orderedStream.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
create
Create a newWeightedBagwhere 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
WeightedBagwhere elements added with no weight will be givenWeighted.DEFAULT_WEIGHT
-
create
Create a newWeightedBagwhere 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
WeightedBagwhere 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 aWeightedBaginto 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
Weightannotation 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
Weightannotation 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 thisWeightedBagas an orderedStream.- Returns:
- the contents of this
WeightedBagas an orderedStream
-
iterator
-