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.
@FunctionalInterface public interface Evaluator<T>
An evaluator is used to quantify a suggested value as one of the values ofEvaluator.Result, and sort defines what an ideal target value is like.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classEvaluator.ByteCounterstatic interfaceEvaluator.OutputStreamObjectWriter<T,O extends OutputStream>static classEvaluator.Result
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description 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.Evaluator.Resultevaluate(T 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 Detail
-
having
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.- 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
Evaluator.Result evaluate(T suggestion) throws Exception
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
-
-