blob: da736d0adf600f471c0bba489216eef002c14028 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.query;
import com.yahoo.prelude.query.textualrepresentation.Discloser;
import java.nio.ByteBuffer;
import java.util.Objects;
/**
* A word item which only consists of a value and weight.
*
* @author baldersheim
*/
public class PureWeightedString extends PureWeightedItem {
private final String value;
public PureWeightedString(String value) {
this(value, 100);
}
public PureWeightedString(String value, int weight) {
super(weight);
this.value = value;
}
@Override
public ItemType getItemType() {
return ItemType.PURE_WEIGHTED_STRING;
}
@Override
protected void encodeThis(ByteBuffer buffer) {
super.encodeThis(buffer);
putString(value, buffer);
}
@Override
public int getTermCount() {
return 1;
}
@Override
protected void appendBodyString(StringBuilder buffer) {
buffer.append(value);
super.appendBodyString(buffer);
}
public String getString() {
return value;
}
@Override
public boolean equals(Object other) {
if ( ! super.equals(other)) return false;
return Objects.equals(value, ((PureWeightedString)other).value);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), value);
}
@Override
public void disclose(Discloser discloser) {
super.disclose(discloser);
discloser.setValue(value);
}
}
|