Skip to content

Commit 11ece15

Browse files
Remove some dead code in o.e.s.a.b.t.heuristic (#119633)
Random finds from auditing code for batched execution: The builders are unused and the `equals` implementations are unnecessarily verbose, cleaning both up here.
1 parent 8612080 commit 11ece15

File tree

7 files changed

+8
-108
lines changed

7 files changed

+8
-108
lines changed

server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/ChiSquare.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ public ChiSquare(StreamInput in) throws IOException {
3838

3939
@Override
4040
public boolean equals(Object other) {
41-
if ((other instanceof ChiSquare) == false) {
42-
return false;
43-
}
44-
return super.equals(other);
41+
return other instanceof ChiSquare && super.equals(other);
4542
}
4643

4744
@Override
@@ -80,17 +77,4 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
8077
return builder;
8178
}
8279

83-
public static class ChiSquareBuilder extends NXYSignificanceHeuristic.NXYBuilder {
84-
public ChiSquareBuilder(boolean includeNegatives, boolean backgroundIsSuperset) {
85-
super(includeNegatives, backgroundIsSuperset);
86-
}
87-
88-
@Override
89-
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
90-
builder.startObject(NAME);
91-
super.build(builder);
92-
builder.endObject();
93-
return builder;
94-
}
95-
}
9680
}

server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/GND.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ public void writeTo(StreamOutput out) throws IOException {
4646

4747
@Override
4848
public boolean equals(Object other) {
49-
if ((other instanceof GND) == false) {
50-
return false;
51-
}
52-
return super.equals(other);
49+
return other instanceof GND && super.equals(other);
5350
}
5451

5552
@Override
@@ -99,17 +96,4 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
9996
return builder;
10097
}
10198

102-
public static class GNDBuilder extends NXYBuilder {
103-
public GNDBuilder(boolean backgroundIsSuperset) {
104-
super(true, backgroundIsSuperset);
105-
}
106-
107-
@Override
108-
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
109-
builder.startObject(NAME);
110-
builder.field(BACKGROUND_IS_SUPERSET.getPreferredName(), backgroundIsSuperset);
111-
builder.endObject();
112-
return builder;
113-
}
114-
}
11599
}

server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/JLHScore.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
9090

9191
@Override
9292
public boolean equals(Object obj) {
93-
if (obj == null || obj.getClass() != getClass()) {
94-
return false;
95-
}
96-
return true;
93+
return obj != null && obj.getClass() == getClass();
9794
}
9895

9996
@Override
10097
public int hashCode() {
10198
return getClass().hashCode();
10299
}
103100

104-
public static class JLHScoreBuilder implements SignificanceHeuristicBuilder {
105-
106-
@Override
107-
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
108-
builder.startObject(NAME).endObject();
109-
return builder;
110-
}
111-
}
112101
}

server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/MutualInformation.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ public MutualInformation(StreamInput in) throws IOException {
4040

4141
@Override
4242
public boolean equals(Object other) {
43-
if ((other instanceof MutualInformation) == false) {
44-
return false;
45-
}
46-
return super.equals(other);
43+
return other instanceof MutualInformation && super.equals(other);
4744
}
4845

4946
@Override
@@ -119,17 +116,4 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
119116
return builder;
120117
}
121118

122-
public static class MutualInformationBuilder extends NXYBuilder {
123-
public MutualInformationBuilder(boolean includeNegatives, boolean backgroundIsSuperset) {
124-
super(includeNegatives, backgroundIsSuperset);
125-
}
126-
127-
@Override
128-
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
129-
builder.startObject(NAME);
130-
super.build(builder);
131-
builder.endObject();
132-
return builder;
133-
}
134-
}
135119
}

server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/NXYSignificanceHeuristic.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ public boolean equals(Object obj) {
6666
if (obj == null) return false;
6767
if (getClass() != obj.getClass()) return false;
6868
NXYSignificanceHeuristic other = (NXYSignificanceHeuristic) obj;
69-
if (backgroundIsSuperset != other.backgroundIsSuperset) return false;
70-
if (includeNegatives != other.includeNegatives) return false;
71-
return true;
69+
return backgroundIsSuperset == other.backgroundIsSuperset && includeNegatives == other.includeNegatives;
7270
}
7371

7472
@Override
@@ -160,24 +158,10 @@ protected static void declareParseFields(ConstructingObjectParser<? extends NXYS
160158
*/
161159
protected static <T> Function<Object[], T> buildFromParsedArgs(BiFunction<Boolean, Boolean, T> ctor) {
162160
return args -> {
163-
boolean includeNegatives = args[0] == null ? false : (boolean) args[0];
164-
boolean backgroundIsSuperset = args[1] == null ? true : (boolean) args[1];
161+
boolean includeNegatives = args[0] != null && (boolean) args[0];
162+
boolean backgroundIsSuperset = args[1] == null || (boolean) args[1];
165163
return ctor.apply(includeNegatives, backgroundIsSuperset);
166164
};
167165
}
168166

169-
protected abstract static class NXYBuilder implements SignificanceHeuristicBuilder {
170-
protected boolean includeNegatives = true;
171-
protected boolean backgroundIsSuperset = true;
172-
173-
public NXYBuilder(boolean includeNegatives, boolean backgroundIsSuperset) {
174-
this.includeNegatives = includeNegatives;
175-
this.backgroundIsSuperset = backgroundIsSuperset;
176-
}
177-
178-
protected void build(XContentBuilder builder) throws IOException {
179-
builder.field(INCLUDE_NEGATIVES_FIELD.getPreferredName(), includeNegatives)
180-
.field(BACKGROUND_IS_SUPERSET.getPreferredName(), backgroundIsSuperset);
181-
}
182-
}
183167
}

server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/PercentageScore.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,12 @@ public double getScore(long subsetFreq, long subsetSize, long supersetFreq, long
5656

5757
@Override
5858
public boolean equals(Object obj) {
59-
if (obj == null || obj.getClass() != getClass()) {
60-
return false;
61-
}
62-
return true;
59+
return obj != null && obj.getClass() == getClass();
6360
}
6461

6562
@Override
6663
public int hashCode() {
6764
return getClass().hashCode();
6865
}
6966

70-
public static class PercentageScoreBuilder implements SignificanceHeuristicBuilder {
71-
72-
@Override
73-
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
74-
builder.startObject(NAME).endObject();
75-
return builder;
76-
}
77-
}
7867
}

server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/SignificanceHeuristicBuilder.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)