T
- the type of choicepublic class WeightedChoice<T>
extends java.lang.Object
A function must be supplied that returns a numeric score for each choice. The function can return null to mean that the choice should not be considered.
Modifier and Type | Class and Description |
---|---|
static class |
WeightedChoice.Choice<T>
A tuple of choice and score.
|
Constructor and Description |
---|
WeightedChoice(java.util.function.Function<T,? extends java.lang.Number> function,
double target)
Create a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
consider(T object)
Consider the given object.
|
java.util.Optional<WeightedChoice.Choice<T>> |
getChoice()
Get the best choice.
|
public WeightedChoice(java.util.function.Function<T,? extends java.lang.Number> function, double target)
function
- a function that assigns a score for each choicetarget
- the target score that the best choice should be closest topublic void consider(T object)
object
- the choicepublic java.util.Optional<WeightedChoice.Choice<T>> getChoice()