Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. import java.util.HashSet;
  6. import java.util.Set;
  7. import java.util.TreeSet;
  8.  
  9. public class Eliminator
  10. {
  11. private TreeSet<String> potentialDuplicates = new TreeSet<>();
  12. private HashSet<String> baseline = new HashSet<>();
  13.  
  14. public Eliminator(File potentialDuplicateSource, File baselineSource) throws IOException
  15. {
  16. populateHashSetFromFile(potentialDuplicateSource, this.potentialDuplicates);
  17. populateHashSetFromFile(baselineSource, this.baseline);
  18. }
  19.  
  20. public TreeSet<String> unique()
  21. {
  22. TreeSet<String> unique = new TreeSet<>();
  23.  
  24. for (String potential : this.potentialDuplicates)
  25. if (!this.baseline.contains(potential))
  26. unique.add(potential);
  27.  
  28. return unique;
  29. }
  30.  
  31. private static void populateHashSetFromFile(File source, Set<String> set) throws IOException
  32. {
  33. BufferedReader reader = new BufferedReader(new FileReader(source));
  34.  
  35. String line;
  36. while ((line = reader.readLine()) != null)
  37. set.add(line);
  38. }
  39.  
  40. public static void main(String[] args) throws Exception
  41. {
  42. if (args.length < 2)
  43. {
  44. System.err.printf("Usage: java Eliminator <potential_duplicates> <baseline>\n");
  45. System.exit(1);
  46. }
  47.  
  48. Eliminator eliminator = new Eliminator(new File(args[0]), new File(args[1]));
  49. for (String unique : eliminator.unique())
  50. System.out.printf("%s\n", unique);
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement