Package no.digipost.util.bisect
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/serializedsizeof 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBisectSearch.Builder<T>
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> BisectSearch.Builder<T>from(Suggester<T> suggester)Define the "source" of the search, how to generate suggested values which will be evaluated.BisectSearch<T>maximumAttempts(int maxAttempts)Specify how many suggestions the search should attempt before yielding a result.TsearchFor(Evaluator<? super T> evaluator)Perform a search for a value using a givenEvaluator
-
-
-
Method Detail
-
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- theSuggestiongenerator 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
BisectSearchinstance
-
searchFor
public T searchFor(Evaluator<? super T> evaluator)
Perform a search for a value using a givenEvaluator- Parameters:
evaluator- evaluates if a suggested value istoo low,too high, orfound.- Returns:
- the resulting value from the search, which has not necessarily been evaluated as
found, but was the last suggested value before reaching themaximum allowed attempts.
-
-