This post is not about federated search but I keep using bunch of set operations to compare the search results, comparing the unique doc id etc.
public class SetOperations {
public staticSet union(Set setA, Set setB) {
Settmp = new TreeSet (setA);
tmp.addAll(setB);
return tmp;
}
public staticSet intersection(Set setA, Set setB) {
Settmp = new TreeSet ();
for (T x : setA)
if (setB.contains(x))
tmp.add(x);
return tmp;
}
public staticSet difference(Set setA, Set setB) {
Settmp = new TreeSet (setA);
tmp.removeAll(setB);
return tmp;
}
public static void main(String[] args) {
SortedSets1= new TreeSet ();
s1.add("one");
s1.add("two");
SortedSets2= new TreeSet ();
s2.add("two");
s2.add("three");
s2.add("four");
SortedSetresult = (SortedSet ) union(s1,s2);
Iteratorit = result.iterator();
System.out.print("union result -->");
while (it.hasNext()) {
String value = it.next();
System.out.print(value+", ");
}
System.out.println("\n");
result = (SortedSet) intersection(s1,s2);
it = result.iterator();
System.out.print("intersection result-->");
while (it.hasNext()) {
String value = it.next();
System.out.print(value+ ", ");
}
System.out.println("\n");
result = (SortedSet) difference(s1,s2);
it = result.iterator();
System.out.print("difference result-->");
while (it.hasNext()) {
String value = it.next();
System.out.print(value+", ");
}
System.out.println("\n");
/*
SortedSeti1= new TreeSet ();
i1.add(new Integer("1"));
SortedSeti2= new TreeSet ();
i2.add(new Integer("2"));
SortedSetiresult = (SortedSet ) union(i1,i2);
Iteratoriit = iresult.iterator();
System.out.println("Integer union result");
while (iit.hasNext()) {
Integer value = iit.next();
System.out.println(value+",");
}
*/
}
}
No comments:
Post a Comment