Skip to content

Commit

Permalink
Remove some dead code in o.e.s.a.b.t.heuristic (elastic#119633)
Browse files Browse the repository at this point in the history
Random finds from auditing code for batched execution:
The builders are unused and the `equals` implementations are unnecessarily verbose, cleaning both up here.
  • Loading branch information
original-brownbear authored Jan 7, 2025
1 parent 8612080 commit 11ece15
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ public ChiSquare(StreamInput in) throws IOException {

@Override
public boolean equals(Object other) {
if ((other instanceof ChiSquare) == false) {
return false;
}
return super.equals(other);
return other instanceof ChiSquare && super.equals(other);
}

@Override
Expand Down Expand Up @@ -80,17 +77,4 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder;
}

public static class ChiSquareBuilder extends NXYSignificanceHeuristic.NXYBuilder {
public ChiSquareBuilder(boolean includeNegatives, boolean backgroundIsSuperset) {
super(includeNegatives, backgroundIsSuperset);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(NAME);
super.build(builder);
builder.endObject();
return builder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ public void writeTo(StreamOutput out) throws IOException {

@Override
public boolean equals(Object other) {
if ((other instanceof GND) == false) {
return false;
}
return super.equals(other);
return other instanceof GND && super.equals(other);
}

@Override
Expand Down Expand Up @@ -99,17 +96,4 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder;
}

public static class GNDBuilder extends NXYBuilder {
public GNDBuilder(boolean backgroundIsSuperset) {
super(true, backgroundIsSuperset);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(NAME);
builder.field(BACKGROUND_IS_SUPERSET.getPreferredName(), backgroundIsSuperset);
builder.endObject();
return builder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws

@Override
public boolean equals(Object obj) {
if (obj == null || obj.getClass() != getClass()) {
return false;
}
return true;
return obj != null && obj.getClass() == getClass();
}

@Override
public int hashCode() {
return getClass().hashCode();
}

public static class JLHScoreBuilder implements SignificanceHeuristicBuilder {

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(NAME).endObject();
return builder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ public MutualInformation(StreamInput in) throws IOException {

@Override
public boolean equals(Object other) {
if ((other instanceof MutualInformation) == false) {
return false;
}
return super.equals(other);
return other instanceof MutualInformation && super.equals(other);
}

@Override
Expand Down Expand Up @@ -119,17 +116,4 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder;
}

public static class MutualInformationBuilder extends NXYBuilder {
public MutualInformationBuilder(boolean includeNegatives, boolean backgroundIsSuperset) {
super(includeNegatives, backgroundIsSuperset);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(NAME);
super.build(builder);
builder.endObject();
return builder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ public boolean equals(Object obj) {
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
NXYSignificanceHeuristic other = (NXYSignificanceHeuristic) obj;
if (backgroundIsSuperset != other.backgroundIsSuperset) return false;
if (includeNegatives != other.includeNegatives) return false;
return true;
return backgroundIsSuperset == other.backgroundIsSuperset && includeNegatives == other.includeNegatives;
}

@Override
Expand Down Expand Up @@ -160,24 +158,10 @@ protected static void declareParseFields(ConstructingObjectParser<? extends NXYS
*/
protected static <T> Function<Object[], T> buildFromParsedArgs(BiFunction<Boolean, Boolean, T> ctor) {
return args -> {
boolean includeNegatives = args[0] == null ? false : (boolean) args[0];
boolean backgroundIsSuperset = args[1] == null ? true : (boolean) args[1];
boolean includeNegatives = args[0] != null && (boolean) args[0];
boolean backgroundIsSuperset = args[1] == null || (boolean) args[1];
return ctor.apply(includeNegatives, backgroundIsSuperset);
};
}

protected abstract static class NXYBuilder implements SignificanceHeuristicBuilder {
protected boolean includeNegatives = true;
protected boolean backgroundIsSuperset = true;

public NXYBuilder(boolean includeNegatives, boolean backgroundIsSuperset) {
this.includeNegatives = includeNegatives;
this.backgroundIsSuperset = backgroundIsSuperset;
}

protected void build(XContentBuilder builder) throws IOException {
builder.field(INCLUDE_NEGATIVES_FIELD.getPreferredName(), includeNegatives)
.field(BACKGROUND_IS_SUPERSET.getPreferredName(), backgroundIsSuperset);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,12 @@ public double getScore(long subsetFreq, long subsetSize, long supersetFreq, long

@Override
public boolean equals(Object obj) {
if (obj == null || obj.getClass() != getClass()) {
return false;
}
return true;
return obj != null && obj.getClass() == getClass();
}

@Override
public int hashCode() {
return getClass().hashCode();
}

public static class PercentageScoreBuilder implements SignificanceHeuristicBuilder {

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(NAME).endObject();
return builder;
}
}
}

This file was deleted.

0 comments on commit 11ece15

Please sign in to comment.