diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/ChiSquare.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/ChiSquare.java index 64a589f38910d..8c856750f053f 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/ChiSquare.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/ChiSquare.java @@ -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 @@ -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; - } - } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/GND.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/GND.java index 2020b00c3c68c..6b00245d51468 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/GND.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/GND.java @@ -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 @@ -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; - } - } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/JLHScore.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/JLHScore.java index 80e477dfab3dd..028a4fab6d574 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/JLHScore.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/JLHScore.java @@ -90,10 +90,7 @@ 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 @@ -101,12 +98,4 @@ 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; - } - } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/MutualInformation.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/MutualInformation.java index efdd10ca145f0..a10f4d62bfe94 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/MutualInformation.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/MutualInformation.java @@ -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 @@ -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; - } - } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/NXYSignificanceHeuristic.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/NXYSignificanceHeuristic.java index 2e38219bae337..d17d3a85fee61 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/NXYSignificanceHeuristic.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/NXYSignificanceHeuristic.java @@ -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 @@ -160,24 +158,10 @@ protected static void declareParseFields(ConstructingObjectParser Function buildFromParsedArgs(BiFunction 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); - } - } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/PercentageScore.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/PercentageScore.java index 5f200b8778897..133de5a066dac 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/PercentageScore.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/PercentageScore.java @@ -56,10 +56,7 @@ 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 @@ -67,12 +64,4 @@ 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; - } - } } diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/SignificanceHeuristicBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/SignificanceHeuristicBuilder.java deleted file mode 100644 index 4044c3a72a30b..0000000000000 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/heuristic/SignificanceHeuristicBuilder.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the "Elastic License - * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -package org.elasticsearch.search.aggregations.bucket.terms.heuristic; - -import org.elasticsearch.xcontent.ToXContentFragment; - -public interface SignificanceHeuristicBuilder extends ToXContentFragment {}