Compare Column/Attribute Data – Using Java Set Operations

/**
* This will return all Elements in Both the CSV files
* @param coll1
* @param coll2
* @return
*/
public static Collection union(Collection coll1, Collection coll2) {
Set union = new TreeSet(coll1);
union.addAll(new TreeSet(coll2));
return union;
}

/**
* This will return the common elements in both sets
* @param coll1
* @param coll2
* @return
*/
public static Collection intersect(Collection coll1, Collection coll2) {
Set intersection = new TreeSet(coll1);
intersection.retainAll(new TreeSet(coll2));
return intersection;
}

/**
* This will return Non overlap elements in Set 2
* @param coll1
* @param coll2
* @return
*/
public static Collection nonOverLap(Collection coll1, Collection coll2) {
Collection result = union(coll1, coll2);
result.removeAll(intersect(coll1, coll2));
return result;
}

/**
* This will return the left table uncommon elements
* @param coll1
* @param coll2
* @return
*/
public static Collection leftjoin(Collection coll1, Collection coll2) {
Collection intersect = intersect(coll1, coll2);
coll1.removeAll(intersect);
return coll1;
}

Advertisements

About ashokabhat

I am a C,C ,JAVA,Adobe Flex,.NET Programmer Currently working as a Software Developer
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s