Package no.digipost.util.bisect
Interface Evaluator<T>
- Type Parameters:
T- the type of values which are evaluated
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
An evaluator is used to quantify a suggested value as one of the
values of
Evaluator.Result, and sort defines what an ideal
target value is like.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classstatic interfaceEvaluator.OutputStreamObjectWriter<T,O extends OutputStream> static enum -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Evaluator<T>byteCount(long targetBytes, Evaluator.OutputStreamObjectWriter<? super T, ? super Evaluator.ByteCounter> serializer) Evaluate suggestions based on how many bytes is written from a suggestion.Evaluate a suggestion as eitherEvaluator.Result.TOO_LOW,Evaluator.Result.TOO_HIGH, orEvaluator.Result.FOUND.static <T,U extends Comparable<? super U>, X extends Exception>
Evaluator<T>having(ThrowingFunction<? super T, ? extends U, X> propertyExtractor, U comparableTarget) Evaluate suggestions using an extractedcomparableproperty of the suggestions.static <T> Evaluator<T>size(DataSize targetSize, Evaluator.OutputStreamObjectWriter<? super T, ? super Evaluator.ByteCounter> serializer) Evaluate suggestions based on how many bytes is written from a suggestion.
-
Method Details
-
having
static <T,U extends Comparable<? super U>, Evaluator<T> havingX extends Exception> (ThrowingFunction<? super T, ? extends U, X> propertyExtractor, U comparableTarget) Evaluate suggestions using an extractedcomparableproperty of the suggestions.- Parameters:
propertyExtractor- the function to resolve/extract the propertycomparableTarget- the ideal target to search for- Returns:
- the evaluator
-
size
static <T> Evaluator<T> size(DataSize targetSize, Evaluator.OutputStreamObjectWriter<? super T, ? super Evaluator.ByteCounter> serializer) Evaluate suggestions based on how many bytes is written from a suggestion.- Parameters:
targetSize- the ideal targetsizeserializer- the consumer function which defines how a suggestion is written as a series of bytes to aEvaluator.ByteCounter(anOutputStream).- Returns:
- the evaluator
-
byteCount
static <T> Evaluator<T> byteCount(long targetBytes, Evaluator.OutputStreamObjectWriter<? super T, ? super Evaluator.ByteCounter> serializer) Evaluate suggestions based on how many bytes is written from a suggestion.- Parameters:
targetBytes- the ideal target byte amountserializer- the consumer function which defines how a suggestion is written as a series of bytes to aEvaluator.ByteCounter(anOutputStream).- Returns:
- the evaluator
-
evaluate
Evaluate a suggestion as eitherEvaluator.Result.TOO_LOW,Evaluator.Result.TOO_HIGH, orEvaluator.Result.FOUND.- Parameters:
suggestion- the suggestion to evaluate- Returns:
- the result of the evaluation
- Throws:
Exception
-