summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/prelude/query/WeightedSetItem.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-search/src/main/java/com/yahoo/prelude/query/WeightedSetItem.java')
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/query/WeightedSetItem.java29
1 files changed, 21 insertions, 8 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/WeightedSetItem.java b/container-search/src/main/java/com/yahoo/prelude/query/WeightedSetItem.java
index d7a07824251..907055d435b 100644
--- a/container-search/src/main/java/com/yahoo/prelude/query/WeightedSetItem.java
+++ b/container-search/src/main/java/com/yahoo/prelude/query/WeightedSetItem.java
@@ -8,6 +8,7 @@ import com.yahoo.prelude.query.textualrepresentation.Discloser;
import java.nio.ByteBuffer;
import java.util.Iterator;
import java.util.Map;
+import java.util.Objects;
/**
* A term which contains a weighted set.
@@ -26,7 +27,7 @@ import java.util.Map;
public class WeightedSetItem extends SimpleTaggableItem {
private String indexName;
- private CopyOnWriteHashMap<Object,Integer> set;
+ private CopyOnWriteHashMap<Object, Integer> set;
/** Creates an empty weighted set; note you must provide an index name up front */
public WeightedSetItem(String indexName) {
@@ -51,11 +52,11 @@ public class WeightedSetItem extends SimpleTaggableItem {
}
/**
- * Add weighted token.
- * If token is already in the set, the maximum weight is kept.
- * NOTE: The weight must be 1 or more; negative values (and zero) are not allowed.
+ * Adds a weighted token.
+ * If this token is already in the set, the maximum weight is kept.
+ * The weight must be 1 or more; negative values (and zero) are not allowed.
*
- * @return weight of added token (might be old value, if kept)
+ * @return the weight of the added token (might be the old value, if kept)
*/
public Integer addToken(String token, int weight) {
if (token == null) throw new IllegalArgumentException("token must be a string");
@@ -72,9 +73,7 @@ public class WeightedSetItem extends SimpleTaggableItem {
return newWeight;
}
- /**
- * Add token with weight 1.
- */
+ /** Adds a token with weight 1. */
public Integer addToken(String token) {
return addToken(token, 1);
}
@@ -180,4 +179,18 @@ public class WeightedSetItem extends SimpleTaggableItem {
return clone;
}
+ @Override
+ public boolean equals(Object o) {
+ if ( ! super.equals(o)) return false;
+ var other = (WeightedSetItem)o;
+ if ( ! Objects.equals(this.indexName, other.indexName)) return false;
+ if ( ! Objects.equals(this.set, other.set)) return false;
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(super.hashCode(), indexName, set);
+ }
+
}