- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringField.java
More file actions
Latest commit
106 lines (85 loc) · 2.36 KB
/
Copy pathStringField.java
File metadata and controls
106 lines (85 loc) · 2.36 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
packagesimpledb;
importjava.io.*;
/**
* Instance of Field that stores a single String of a fixed length.
*/
publicclassStringFieldimplementsField {
privateStringvalue;
privateintmaxSize;
publicStringgetValue() {
returnvalue;
}
/**
* Constructor.
*
* @param s The value of this field.
* @param maxSize The maximum size of this string
*/
publicStringField(Strings, intmaxSize) {
this.maxSize = maxSize;
if (s.length() > maxSize)
value = s.substring(0,maxSize);
else
value = s;
}
publicStringtoString() {
returnvalue;
}
publicinthashCode() {
returnvalue.hashCode();
}
publicbooleanequals(Objectfield) {
return ((StringField) field).value.equals(value);
}
/** Write this string to dos. Always writes maxSize + 4 bytes to the
passed in dos. First four bytes are string length, next bytes are
string, with remainder padded with 0 to maxSize.
@param dos Where the string is written
*/
publicvoidserialize(DataOutputStreamdos) throwsIOException {
Strings = value;
intoverflow = maxSize - s.length();
if (overflow < 0) {
Stringnews = s.substring(0,maxSize);
s = news;
}
dos.writeInt(s.length());
dos.writeBytes(s);
while (overflow-- > 0)
dos.write((byte)0);
}
/**
* Compare the specified field to the value of this Field.
* Return semantics are as specified by Field.compare
*
* @throws IllegalCastException if val is not a StringField
* @see Field#compare
*/
publicbooleancompare(Predicate.Opop, Fieldval) {
StringFieldiVal = (StringField) val;
intcmpVal = value.compareTo(iVal.value);
switch (op) {
caseEQUALS:
returncmpVal == 0;
caseNOT_EQUALS:
returncmpVal != 0;
caseGREATER_THAN:
returncmpVal > 0;
caseGREATER_THAN_OR_EQ:
returncmpVal >= 0;
caseLESS_THAN:
returncmpVal < 0;
caseLESS_THAN_OR_EQ:
returncmpVal <= 0;
caseLIKE:
returnvalue.indexOf(iVal.value) >= 0;
}
returnfalse;
}
/**
* @return the Type for this Field
*/
publicTypegetType() {
returnType.STRING_TYPE;
}
}