blob: 6c0b1664328b8557a7dd34fe159a3ad4b63737fb (
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 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchlib.expression;
import com.yahoo.vespa.objects.Deserializer;
import com.yahoo.vespa.objects.Serializer;
import java.util.ArrayList;
/**
* This result holds nothing.
*
* @author baldersheim
* @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
*/
public class StringResultNodeVector extends ResultNodeVector {
// The global class identifier shared with C++.
public static final int classId = registerClass(0x4000 + 111, StringResultNodeVector.class);
private ArrayList<StringResultNode> vector = new ArrayList<StringResultNode>();
@Override
protected int onGetClassId() {
return classId;
}
public StringResultNodeVector() {
}
public StringResultNodeVector add(StringResultNode v) {
vector.add(v);
return this;
}
public ResultNodeVector add(ResultNode r) {
return add((StringResultNode)r);
}
public ArrayList<StringResultNode> getVector() {
return vector;
}
@Override
protected void onSerialize(Serializer buf) {
super.onSerialize(buf);
buf.putInt(null, vector.size());
for (StringResultNode node : vector) {
node.serialize(buf);
}
}
@Override
protected void onDeserialize(Deserializer buf) {
super.onDeserialize(buf);
int sz = buf.getInt(null);
vector = new ArrayList<StringResultNode>();
for (int i = 0; i < sz; i++) {
StringResultNode node = new StringResultNode();
node.deserialize(buf);
vector.add(node);
}
}
@Override
protected int onCmp(ResultNode rhs) {
if (classId != rhs.getClassId()) {
return (classId - rhs.getClassId());
}
StringResultNodeVector b = (StringResultNodeVector)rhs;
int minLength = vector.size();
if (b.vector.size() < minLength) {
minLength = b.vector.size();
}
int diff = 0;
for (int i = 0; (diff == 0) && (i < minLength); i++) {
diff = vector.get(i).compareTo(b.vector.get(i));
}
return (diff == 0) ? (vector.size() - b.vector.size()) : diff;
}
}
|