-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTuple.java
More file actions
99 lines (87 loc) · 2.46 KB
/
Tuple.java
File metadata and controls
99 lines (87 loc) · 2.46 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
package simpledb;
import com.sun.org.apache.bcel.internal.classfile.Field;
/**
* Tuple maintains information about the contents of a tuple.
* Tuples have a specified schema specified by a TupleDesc object and contain
* Field objects with the data for each field.
*/
public class Tuple {
/**
* The tuple descriptor associated with this Tuple.
*/
protected TupleDesc tupledesc;
/**
* The RecordId of this Tuple.
*/
protected RecordId recID;
/**
* The Fields of this Tuple.
*/
protected Field fields[];
/**
* Create a new tuple with the specified schema (type).
*
* @param td the schema of this tuple. It must be a valid TupleDesc
* instance with at least one field.
*/
public Tuple(TupleDesc td) {
if(td.numFields() > 0){
tupledesc = td;
fields = new Field[td.numFields()];
}
}
/**
* @return The TupleDesc representing the schema of this tuple.
*/
public TupleDesc getTupleDesc() {
return tupledesc;
}
/**
* @return The RecordID representing the location of this tuple on
* disk. May be null.
*/
public RecordId getRecordId() {
return recID;
}
/**
* Set the RecordID information for this tuple.
* @param rid the new RecordID for this tuple.
*/
public void setRecordId(RecordId rid) {
recID = rid;
}
/**
* Change the value of the ith field of this tuple.
*
* @param i index of the field to change. It must be a valid index.
* @param f new value for the field.
*/
public void setField(int i, Field f) {
if(i >= 0 && i < fields.length)
fields[i] = f;
}
/**
* @return the value of the ith field, or null if it has not been set.
*
* @param i field index to return. Must be a valid index.
*/
public Field getField(int i) {
if(i >= 0 && i < fields.length)
return fields[i];
return null;
}
/**
* Returns a string representing this Tuple.
* Note that to pass the system tests, the format needs to be as
* follows:
* "fields[0]|fields[1]|...|fields[M-1]", where M is the number of fields.
*/
public String toString() {
// some code goes here
System.out.print(fields[0]);
for(int i=1; i< fields.length; i++){
System.out.print("|"+fields[i]);
}
throw new UnsupportedOperationException("Implement this");
}
}