rendered paste body/* equals() for the FunctionalDependency class */
public boolean equals(Object obj) {
boolean equal = false;
if(this == obj)
return true;
if((obj == null) || (obj.getClass() != this.getClass()))
return false;
// object must be FunctionalDependency at this point
FunctionalDependency FD = (FunctionalDependency)obj;
if ( LeftHandSide.size() == FD.LeftHandSide.size() &&
RightHandSide.size() == FD.RightHandSide.size()) {
for (String s : LeftHandSide) {
if (!FD.LeftHandSide.contains(s)) {
return false;
}
}
for (String s : RightHandSide) {
if (!FD.RightHandSide.contains(s)) {
return false;
}
}
return true;
} else {
return false;
}
}
...
Rinitial = new Relation();
FunctionalDependency fd = new FunctionalDependency();
String s;
s = "A"; if (!fd.addLHS(s)) { System.out.println("add "+s+" failed"); }
s = "B"; if (!fd.addLHS(s)) { System.out.println("add "+s+" failed1"); }
s = "B"; if (!fd.addLHS(s)) { System.out.println("add "+s+" failed2"); }
s = "C"; if (!fd.addLHS(s)) { System.out.println("add "+s+" failed"); }
s = "D"; if (!fd.addRHS(s)) { System.out.println("add "+s+" failed"); }
s = "E"; if (!fd.addRHS(s)) { System.out.println("add "+s+" failed"); }
s = "F"; if (!fd.addRHS(s)) { System.out.println("add "+s+" failed"); }
if (!Rinitial.add(fd)) {System.out.println("adding "+fd+" failed1");}
if (!Rinitial.add(fd)) {System.out.println("adding "+fd+" failed2");}
fd = new FunctionalDependency();
s = "A"; if (!fd.addLHS(s)) { System.out.println("add "+s+" failed"); }
s = "B"; if (!fd.addLHS(s)) { System.out.println("add "+s+" failed"); }
s = "C"; if (!fd.addLHS(s)) { System.out.println("add "+s+" failed"); }
s = "D"; if (!fd.addRHS(s)) { System.out.println("add "+s+" failed"); }
s = "E"; if (!fd.addRHS(s)) { System.out.println("add "+s+" failed"); }
s = "F"; if (!fd.addRHS(s)) { System.out.println("add "+s+" failed"); }
if (!Rinitial.add(fd)) {System.out.println("adding "+fd+" failed3");}
System.out.println(Rinitial);
... prints:
adding 'A', 'C', 'B' -> 'D', 'F', 'E' failed2
['A', 'C', 'B' -> 'D', 'F', 'E'] ['A', 'C', 'B' -> 'D', 'F', 'E']