package org.warp.commonutils.type; import java.util.Objects; import org.jetbrains.annotations.NotNull; public final class ScoredValue implements Comparable> { private final float score; private final T value; private ScoredValue(float score, T value) { this.score = score; this.value = value; } public static ScoredValue of(float score, T value) { return new ScoredValue(score, value); } @Override public int compareTo(@NotNull ScoredValue o) { // This is reversed return Float.compare(o.score, this.score); } public float getScore() { return this.score; } public T getValue() { return this.value; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ScoredValue that = (ScoredValue) o; return Objects.equals(value, that.value); } @Override public int hashCode() { return Objects.hash(value); } public String toString() { return "ScoredValue(score=" + this.getScore() + ", value=" + this.getValue() + ")"; } }