Csc 1302, Honors Principles of Computer Science II (Fall 2016)
Week 4 (15 September 2016)
Clone tuple; Check membership of tuple in relation; and the Union, Intersect, and Minus Operators
During this week you will write the following methods:- (Tuple.java) Clone a tuple object:
public Tuple clone(ArrayList<String> attr)
This method creates a new copy of the tuple with the attributes set to attr and returns it. Note that when you read a value from the tuple array list, you will use a "cast" to convert the value to corresponding object type; For example if you are reading a INTEGER object from the array list, then you will use the following expression to convert it into INTEGER object:new Integer((Integer) tuple.get(i))
- (Relation.java) Check membership:
public boolean member(Tuple t)
This method returns true if tuple t is present in relation and false otherwise. - (Relation.java) Union operator:
public Relation union(Relation r2)
This method returns the union of two relations (this and r2); It should remove duplicates before returning. Clone the tuples from the input relations and then add to output. - (Relation.java) intersect operator:
public Relation intersect(Relation r2)
This method returns the intersection of two relations (this and r2); Clone the tuples from the input relations and then add to output. - (Relation.java) minus operator:
public Relation minus(Relation r2)
This method returns the difference of two relations (this and r2); Clone the tuples from the input relations and then add to output.
Download the Driver Programs and implement all the methods in this assignment. Compile and run the driver programs. You should see the following output when you run Driver.java:
[raj@tinman w3]$ java Driver REL1(COL1:INTEGER,COL2:VARCHAR) Number of tuples: 5 1111:Robert Adams: 1112:Charles Bailey: 1114:Richard Johnson: 1115:Graham Gooch: 1116:John Miller: REL2(COL1:INTEGER,COL2:VARCHAR) Number of tuples: 5 1113:John Smith: 1112:Charles Bailey: 1115:Graham Gooch: 1116:John Miller: 1117:Hugh Howell: REL1_UNION_REL2(COL1:INTEGER,COL2:VARCHAR) Number of tuples: 7 1111:Robert Adams: 1112:Charles Bailey: 1114:Richard Johnson: 1115:Graham Gooch: 1116:John Miller: 1113:John Smith: 1117:Hugh Howell: REL1_INTERSECT_REL2(COL1:INTEGER,COL2:VARCHAR) Number of tuples: 3 1112:Charles Bailey: 1115:Graham Gooch: 1116:John Miller: REL1_MINUS_REL2(COL1:INTEGER,COL2:VARCHAR) Number of tuples: 2 1111:Robert Adams: 1114:Richard Johnson: