Guest User

Untitled

a guest
Jul 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. package Main;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. public class projBCNF {
  6.    
  7.    
  8.     public projBCNF(){
  9.         //Do nothing atm
  10.     }
  11.    
  12.     /**
  13.      * This function will only check if all of the attributes in the
  14.      * relation exists in the projection
  15.      * @param X Should contain what you want to project off
  16.      * @param FD Contains all the Function dependencies
  17.      * @return A ArrayList containing objects Relation which succeeded
  18.      */
  19.     public ArrayList<Relation> calcProj(ArrayList<String> X, ArrayList<Relation> FD){
  20.         ArrayList<Relation> okey = new ArrayList<Relation>();
  21.         //Loop over all of the FD
  22.         for(int r = 0; r < FD.size();r++){
  23.             //and check each one of them all only contains what X is
  24.             if(X.containsAll(FD.get(r).getVl()) && X.containsAll(FD.get(r).getHl())){
  25.                 //This one was okey to lets add it the new new array to return
  26.                 okey.add(FD.get(r));
  27.             }
  28.         }      
  29.         return okey;
  30.     }
  31.     public static void main(String[] args){
  32.         ArrayList<Relation> FD = new ArrayList<Relation>();
  33.         ArrayList<String> proj = new ArrayList<String>();
  34.        
  35.         //Add some stuff to the relation
  36.         ArrayList<String> v1 = new ArrayList<String>();
  37.             v1.add("B");
  38.             v1.add("C");
  39.         ArrayList<String> h1 =  new ArrayList<String>();
  40.             h1.add("D");
  41.         Relation r1 = new Relation(v1,h1);
  42.         FD.add(r1);
  43.        
  44.         ArrayList<String> v2 = new ArrayList<String>();
  45.             v2.add("D");
  46.         ArrayList<String> h2 = new ArrayList<String>();
  47.             h2.add("A");
  48.         Relation r2 = new Relation(v2,h2);
  49.         FD.add(r2);
  50.        
  51.         ArrayList<String> v3 = new ArrayList<String>();
  52.             v3.add("A");
  53.         ArrayList<String> h3 = new ArrayList<String>();
  54.             h3.add("B");
  55.         Relation r3 = new Relation(v3,h3);
  56.         FD.add(r3);
  57.        
  58.         proj.add("A");
  59.         proj.add("D");
  60.         //proj.add("B");
  61.         //proj.add("C");
  62.        
  63.        
  64.         projBCNF p = new projBCNF();
  65.         ArrayList<Relation> done = p.calcProj(proj, FD);
  66.         System.out.println(done);
  67.        
  68.        
  69.        
  70.        
  71.     }
  72. }
Add Comment
Please, Sign In to add comment