Class BisectSearch<T>

java.lang.Object
no.digipost.util.bisect.BisectSearch<T>
Type Parameters:
T - the type of the values/objects which are searched for

public final class BisectSearch<T> extends Object
Implementation of bisection search algorithm, which can be used to find objects having any quantifiable properties one would evaluate as approaching a certain ideal target value. This can e.g. be the binary/serialized size of an image generated from different dimensions, or a document with differenct amount of pages.

To specify a search, one starts by defining the "source" of the search space, using the from(Suggester) method.

  • Method Details

    • from

      public static <T> BisectSearch.Builder<T> from(Suggester<T> suggester)
      Define the "source" of the search, how to generate suggested values which will be evaluated.
      Parameters:
      suggester - the Suggestion generator function
      Returns:
      a new builder which is used for further specification of the search
    • maximumAttempts

      public BisectSearch<T> maximumAttempts(int maxAttempts)
      Specify how many suggestions the search should attempt before yielding a result.
      Parameters:
      maxAttempts - the amount of suggestions to attempt
      Returns:
      the new BisectSearch instance
    • searchFor

      public T searchFor(Evaluator<? super T> evaluator)
      Perform a search for a value using a given Evaluator
      Parameters:
      evaluator - evaluates if a suggested value is too low, too high, or found.
      Returns:
      the resulting value from the search, which has not necessarily been evaluated as found, but was the last suggested value before reaching the maximum allowed attempts.