blob: 6dbaa129f66983604bbbf637214e6ee0e30ce6cd (
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
71
72
73
74
75
76
77
78
79
80
|
// Copyright 2016 Yahoo Inc. 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 edu.umd.cs.findbugs.annotations.NonNull;
import java.nio.ByteBuffer;
/**
* Common implementation for Item classes implementing the IndexedItem interface.
* Note that this file exist in 3 copies that should be kept in sync:
*
* CompositeIndexedItem.java
* SimpleIndexedItem.java
* IndexedSegmentItem.java
*
* These should only have trivial differences.
* (multiple inheritance or mixins would have been nice).
*
* @author arnej27959
*/
public abstract class CompositeIndexedItem extends CompositeTaggableItem implements IndexedItem {
@NonNull
private String index = "";
/**
* The name of the index this belongs to, or "" (never null) if not specified
**/
@NonNull
public String getIndexName() {
return index;
}
// encode index bytes
protected void encodeThis(ByteBuffer buffer) {
super.encodeThis(buffer);
putString(index, buffer);
}
/** Sets the name of the index to search */
public void setIndexName(String index) {
if (index == null) {
index = "";
}
this.index = index;
}
/** Appends the index prefix if necessary */
protected void appendIndexString(StringBuilder buffer) {
if (!getIndexName().equals("")) {
buffer.append(getIndexName());
buffer.append(":");
}
}
public boolean equals(Object object) {
if (!super.equals(object)) {
return false;
}
IndexedItem other = (IndexedItem) object; // Ensured by superclass
if (!this.index.equals(other.getIndexName())) {
return false;
}
return true;
}
public int hashCode() {
return super.hashCode() + 31 * index.hashCode();
}
public abstract String getIndexedString();
@Override
public void disclose(Discloser discloser) {
super.disclose(discloser);
discloser.addProperty("index", index);
}
}
|