summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/prelude/query/WordAlternativesItem.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-search/src/main/java/com/yahoo/prelude/query/WordAlternativesItem.java')
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/query/WordAlternativesItem.java65
1 files changed, 45 insertions, 20 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/WordAlternativesItem.java b/container-search/src/main/java/com/yahoo/prelude/query/WordAlternativesItem.java
index 3b22bdbb163..1e9a27f237d 100644
--- a/container-search/src/main/java/com/yahoo/prelude/query/WordAlternativesItem.java
+++ b/container-search/src/main/java/com/yahoo/prelude/query/WordAlternativesItem.java
@@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
import java.util.stream.Collectors;
import com.google.common.collect.ImmutableList;
@@ -20,26 +21,6 @@ public class WordAlternativesItem extends TermItem {
private List<Alternative> alternatives;
- public static final class Alternative {
-
- public final String word;
- public final double exactness;
-
- public Alternative(String word, double exactness) {
- super();
- this.word = word;
- this.exactness = exactness;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("Alternative [word=").append(word).append(", exactness=").append(exactness).append("]");
- return builder.toString();
- }
-
- }
-
public WordAlternativesItem(String indexName, boolean isFromQuery, Substring origin, Collection<Alternative> terms) {
super(indexName, isFromQuery, origin);
setAlternatives(terms);
@@ -159,4 +140,48 @@ public class WordAlternativesItem extends TermItem {
setAlternatives(newTerms);
}
+ @Override
+ public boolean equals(Object other) {
+ if ( ! super.equals(other)) return false;
+ return this.alternatives.equals(((WordAlternativesItem)other).alternatives);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(super.hashCode(), alternatives);
+ }
+
+ /** A word alternative. This is a value object. */
+ public static final class Alternative {
+
+ public final String word;
+ public final double exactness;
+
+ public Alternative(String word, double exactness) {
+ super();
+ this.word = word;
+ this.exactness = exactness;
+ }
+
+ @Override
+ public String toString() {
+ return "Alternative [word=" + word + ", exactness=" + exactness + "]";
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if ( ! (o instanceof Alternative)) return false;
+ var other = (Alternative)o;
+ if ( ! Objects.equals(this.word, other.word)) return false;
+ if (this.exactness != other.exactness) return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(word, exactness);
+ }
+
+ }
+
}