CavalliumDBEngine/src/main/java/it/cavallium/dbengine/client/HitKey.java

26 lines
711 B
Java
Raw Normal View History

2021-10-28 23:48:25 +02:00
package it.cavallium.dbengine.client;
2022-06-04 16:33:45 +02:00
import it.cavallium.dbengine.database.collections.DatabaseEmpty.Nothing;
2021-10-28 23:48:25 +02:00
import java.util.function.Function;
import org.jetbrains.annotations.NotNull;
public record HitKey<T>(T key, float score) implements Comparable<HitKey<T>> {
public <U> HitEntry<T, U> withValue(Function<T, U> valueGetter) {
return new HitEntry<>(key, valueGetter.apply(key), score);
2021-10-28 23:48:25 +02:00
}
2022-06-04 16:33:45 +02:00
public <U> HitEntry<T, U> withNullValue() {
return new HitEntry<>(key, null, score);
}
public HitEntry<T, Nothing> withNothingValue() {
return new HitEntry<>(key, Nothing.INSTANCE, score);
}
2021-10-28 23:48:25 +02:00
@Override
public int compareTo(@NotNull HitKey<T> o) {
return Float.compare(o.score, this.score);
}
}