MCPcopy Create free account
hub / github.com/1345414527/MIT6.830 / IntField

Class IntField

src/java/simpledb/storage/IntField.java:11–85  ·  view source on GitHub ↗

Instance of Field that stores a single integer.

Source from the content-addressed store, hash-verified

9 * Instance of Field that stores a single integer.
10 */
11public class IntField implements Field {
12
13 private static final long serialVersionUID = 1L;
14
15 private final int value;
16
17 public int getValue() {
18 return value;
19 }
20
21 /**
22 * Constructor.
23 *
24 * @param i The value of this field.
25 */
26 public IntField(int i) {
27 value = i;
28 }
29
30 public String toString() {
31 return Integer.toString(value);
32 }
33
34 public int hashCode() {
35 return value;
36 }
37
38 public boolean equals(Object field) {
39 if (!(field instanceof IntField)) return false;
40 return ((IntField) field).value == value;
41 }
42
43 public void serialize(DataOutputStream dos) throws IOException {
44 dos.writeInt(value);
45 }
46
47 /**
48 * Compare the specified field to the value of this Field.
49 * Return semantics are as specified by Field.compare
50 *
51 * @throws IllegalCastException if val is not an IntField
52 * @see Field#compare
53 */
54 public boolean compare(Predicate.Op op, Field val) {
55
56 IntField iVal = (IntField) val;
57
58 switch (op) {
59 case EQUALS:
60 case LIKE:
61 return value == iVal.value;
62 case NOT_EQUALS:
63 return value != iVal.value;
64 case GREATER_THAN:
65 return value > iVal.value;
66 case GREATER_THAN_OR_EQ:
67 return value >= iVal.value;
68 case LESS_THAN:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected