Csc 1302, Honors Principles of Computer Science II (Fall 2016)
Week 5 (22 September 2016)
Initialize Database from file
During class, you will complete coding of the Tuple.clone(), Relation.member(), and the
union, intersect, and minus operators. Pseudo code is given for some of these methods:
public Relation union(Relation r2) {
// Schema part of output relation
Create empty array list for attributes of output relation, call it attrs;
Create empty array list for domains of output relation, call it doms;
Copy values from attributes of "this" relation into attrs;
Copy values from domains of "this" relation into doms;
Create a new Relation object, called rel, with attributes attrs and domains doms, name can be null
//Instance part of output relation
Clone each tuple from the "this" relation and add to rel;
Clone each tuple from r2 and add to rel;
remove duplicates from rel;
return rel;
}
public Relation intersect(Relation r2) {
// Schema part of output relation
Create empty array list for attributes of output relation, call it attrs;
Create empty array list for domains of output relation, call it doms;
Copy values from attributes of "this" relation into attrs;
Copy values from domains of "this" relation into doms;
Create a new Relation object, called rel, with attributes attrs and domains doms, name can be null
//Instance part of output relation
for each tuple in "this" relation:
if tuple also belongs to r2, then
Clone tuple add to rel;
return rel;
}
public Relation minus(Relation r2) {
// Schema part of output relation
Create empty array list for attributes of output relation, call it attrs;
Create empty array list for domains of output relation, call it doms;
Copy values from attributes of "this" relation into attrs;
Copy values from domains of "this" relation into doms;
Create a new Relation object, called rel, with attributes attrs and domains doms, name can be null
//Instance part of output relation
for each tuple in "this" relation:
if tuple does not belong to r2, then
Clone tuple add to rel;
return rel;
}
Please turn in Relation.java and Tuple.java under assignment sep22