61 lines
1.3 KiB
Java
61 lines
1.3 KiB
Java
package it.cavallium.dbengine.client;
|
|
|
|
import java.util.Objects;
|
|
import java.util.StringJoiner;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
public class SearchResultItem<T, U> implements Comparable<SearchResultItem<T, U>> {
|
|
private final T key;
|
|
private final U value;
|
|
private final float score;
|
|
|
|
public SearchResultItem(T key, U value, float score) {
|
|
this.key = key;
|
|
this.value = value;
|
|
this.score = score;
|
|
}
|
|
|
|
public float getScore() {
|
|
return score;
|
|
}
|
|
|
|
public T getKey() {
|
|
return key;
|
|
}
|
|
|
|
public U getValue() {
|
|
return value;
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object o) {
|
|
if (this == o) {
|
|
return true;
|
|
}
|
|
if (o == null || getClass() != o.getClass()) {
|
|
return false;
|
|
}
|
|
SearchResultItem<?, ?> that = (SearchResultItem<?, ?>) o;
|
|
return Float.compare(that.score, score) == 0 && Objects.equals(key, that.key) && Objects.equals(value, that.value);
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return Objects.hash(key, value, score);
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return new StringJoiner(", ", SearchResultItem.class.getSimpleName() + "[", "]")
|
|
.add("key=" + key)
|
|
.add("value=" + value)
|
|
.add("score=" + score)
|
|
.toString();
|
|
}
|
|
|
|
@Override
|
|
public int compareTo(@NotNull SearchResultItem<T, U> o) {
|
|
return Float.compare(o.score, this.score);
|
|
}
|
|
}
|