Created
December 14, 2012 20:52
-
-
Save jwebgordon/4288551 to your computer and use it in GitHub Desktop.
dupe cleaner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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