-
Notifications
You must be signed in to change notification settings - Fork 0
/
Table.java
76 lines (64 loc) · 1.7 KB
/
Table.java
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
package models;
import java.util.ArrayList;
import java.util.List;
import java.io.BufferedReader;
import java.io.IOException;
import helpers.DBCatalog;
/**
* Table object to handle all table level operations
*
* @author shweta
*
*/
public class Table {
//Every table will have a name and schema associated with it
//We also create a buffer through which we connect to the data file of the table and read the tuples
public String tableName;
public List<String> tableSchema=null;
private BufferedReader tableBuffer=null;
/**
* Constructor class for table object
* @param tableName name of the table
* @param tableSchema schema of the table
* @param tableBuffer buffer to the table data file
*/
public Table(String tableName, List<String> tableSchema, BufferedReader tableBuffer){
this.tableName = tableName;
this.tableSchema = tableSchema;
this.tableBuffer = tableBuffer;
}
/**
* Get next tuple from the buffer
* @return next tuple
*/
public Tuple getNextTuple(){
String row = null;
try {
row = tableBuffer.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(row == null)
return null;
String[] rowvalues = row.split(",");
int[] tupleValues = new int[rowvalues.length];
for(int i=0;i<rowvalues.length;i++){
tupleValues[i] = Integer.parseInt(rowvalues[i]);
}
Tuple tup = new Tuple(tupleValues);
return tup;
}
/**
* In order to reset, close the existing buffer and reset it again
*/
public void reset(){
try {
tableBuffer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
tableBuffer = DBCatalog.createTableBuffer(tableName);
}
}