Skip to content

Make AbstractAucRoc.Result.docCount field non-nullable #63231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -234,26 +234,26 @@ public static class Result implements EvaluationMetricResult {
private static final String CURVE = "curve";

private final double score;
private final Long docCount;
private final long docCount;
private final List<AucRocPoint> curve;

public Result(double score, Long docCount, List<AucRocPoint> curve) {
public Result(double score, long docCount, List<AucRocPoint> curve) {
this.score = score;
this.docCount = docCount;
this.curve = Objects.requireNonNull(curve);
}

public Result(StreamInput in) throws IOException {
this.score = in.readDouble();
this.docCount = in.readOptionalLong();
this.docCount = in.readLong();
this.curve = in.readList(AucRocPoint::new);
}

public double getScore() {
return score;
}

public Long getDocCount() {
public long getDocCount() {
return docCount;
}

Expand All @@ -274,17 +274,15 @@ public String getMetricName() {
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeDouble(score);
out.writeOptionalLong(docCount);
out.writeLong(docCount);
out.writeList(curve);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(SCORE, score);
if (docCount != null) {
builder.field(DOC_COUNT, docCount);
}
builder.field(DOC_COUNT, docCount);
if (curve.isEmpty() == false) {
builder.field(CURVE, curve);
}
Expand All @@ -298,7 +296,7 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
Result that = (Result) o;
return score == that.score
&& Objects.equals(docCount, that.docCount)
&& docCount == that.docCount
&& Objects.equals(curve, that.curve);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class AucRocResultTests extends AbstractWireSerializingTestCase<Result> {

public static Result createRandom() {
double score = randomDoubleBetween(0.0, 1.0, true);
Long docCount = randomBoolean() ? randomLong() : null;
long docCount = randomLong();
List<AucRocPoint> curve =
Stream
.generate(() -> new AucRocPoint(randomDouble(), randomDouble(), randomDouble()))
Expand Down