Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Main;
- import java.util.ArrayList;
- public class projBCNF {
- public projBCNF(){
- //Do nothing atm
- }
- /**
- * This function will only check if all of the attributes in the
- * relation exists in the projection
- * @param X Should contain what you want to project off
- * @param FD Contains all the Function dependencies
- * @return A ArrayList containing objects Relation which succeeded
- */
- public ArrayList<Relation> calcProj(ArrayList<String> X, ArrayList<Relation> FD){
- ArrayList<Relation> okey = new ArrayList<Relation>();
- //Loop over all of the FD
- for(int r = 0; r < FD.size();r++){
- //and check each one of them all only contains what X is
- if(X.containsAll(FD.get(r).getVl()) && X.containsAll(FD.get(r).getHl())){
- //This one was okey to lets add it the new new array to return
- okey.add(FD.get(r));
- }
- }
- return okey;
- }
- public static void main(String[] args){
- ArrayList<Relation> FD = new ArrayList<Relation>();
- ArrayList<String> proj = new ArrayList<String>();
- //Add some stuff to the relation
- ArrayList<String> v1 = new ArrayList<String>();
- v1.add("B");
- v1.add("C");
- ArrayList<String> h1 = new ArrayList<String>();
- h1.add("D");
- Relation r1 = new Relation(v1,h1);
- FD.add(r1);
- ArrayList<String> v2 = new ArrayList<String>();
- v2.add("D");
- ArrayList<String> h2 = new ArrayList<String>();
- h2.add("A");
- Relation r2 = new Relation(v2,h2);
- FD.add(r2);
- ArrayList<String> v3 = new ArrayList<String>();
- v3.add("A");
- ArrayList<String> h3 = new ArrayList<String>();
- h3.add("B");
- Relation r3 = new Relation(v3,h3);
- FD.add(r3);
- proj.add("A");
- proj.add("D");
- //proj.add("B");
- //proj.add("C");
- projBCNF p = new projBCNF();
- ArrayList<Relation> done = p.calcProj(proj, FD);
- System.out.println(done);
- }
- }
Add Comment
Please, Sign In to add comment