Skip to content

Instantly share code, notes, and snippets.

@jwebgordon
Created December 14, 2012 20:52
Show Gist options
  • Save jwebgordon/4288551 to your computer and use it in GitHub Desktop.
Save jwebgordon/4288551 to your computer and use it in GitHub Desktop.
dupe cleaner
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package hsutils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import sun.misc.IOUtils;
/**
*
* @author wgordon
*/
public class DupeCleaner {
public static void main(String[] args) {
FileInputStream stream;
HashMap<String, String> magicMap = new HashMap<String, String>();
try {
stream = new FileInputStream(new File("C:/Users/wgordon/Downloads/ContactsExpedia.csv"));
BufferedReader br = new BufferedReader(
new InputStreamReader(stream));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
//System.out.println(sb.toString());
br.close();
stream.close();
//System.out.println(sb.toString());
String[] wholeCSV = sb.toString().split(";");
//System.out.println(wholeCSV);
System.out.println(wholeCSV.length);
for(int i=1;i<wholeCSV.length;i++){
String key = wholeCSV[i].split(",")[0];
System.out.println(key);
String value = wholeCSV[i].split(",")[1];
System.out.println(value);
if(!magicMap.containsKey(key)){
magicMap.put(key,value);
}
else{
System.out.println("went into else");
String existingVal = magicMap.get(key);
if(!existingVal.toString().contains(value)){
String newVal = existingVal + ";" + value;
magicMap.put(key, newVal);
System.out.println("Found dupe! " + key);
}
}
}
System.out.println(magicMap.toString());
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment