Class WeightedChoice<T>

java.lang.Object
com.sk89q.worldedit.util.WeightedChoice<T>
Type Parameters:
T - the type of choice

public class WeightedChoice<T> extends Object
Returns the best choice given a weighting function and a target weight.

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.

  • Constructor Details

    • WeightedChoice

      public WeightedChoice(Function<T,? extends Number> function, double target)
      Create a new instance.
      Parameters:
      function - a function that assigns a score for each choice
      target - the target score that the best choice should be closest to
  • Method Details

    • consider

      public void consider(T object)
      Consider the given object.
      Parameters:
      object - the choice
    • getChoice

      public Optional<WeightedChoice.Choice<T>> getChoice()
      Get the best choice.
      Returns:
      the best choice