Created
December 20, 2014 18:35
-
-
Save MrDOS/ceef24e92f56dcd8bc58 to your computer and use it in GitHub Desktop.
The Eliminator reads in two files, the first containing the set of “potential duplicates”, the second containing the “baseline” set, and outputs only those lines which exist in the first file but not the second.
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
| import java.io.BufferedReader; | |
| import java.io.File; | |
| import java.io.FileReader; | |
| import java.io.IOException; | |
| import java.util.HashSet; | |
| import java.util.Set; | |
| import java.util.TreeSet; | |
| public class Eliminator | |
| { | |
| private TreeSet<String> potentialDuplicates = new TreeSet<>(); | |
| private HashSet<String> baseline = new HashSet<>(); | |
| public Eliminator(File potentialDuplicateSource, File baselineSource) throws IOException | |
| { | |
| populateHashSetFromFile(potentialDuplicateSource, this.potentialDuplicates); | |
| populateHashSetFromFile(baselineSource, this.baseline); | |
| } | |
| public TreeSet<String> unique() | |
| { | |
| TreeSet<String> unique = new TreeSet<>(); | |
| for (String potential : this.potentialDuplicates) | |
| if (!this.baseline.contains(potential)) | |
| unique.add(potential); | |
| return unique; | |
| } | |
| private static void populateHashSetFromFile(File source, Set<String> set) throws IOException | |
| { | |
| BufferedReader reader = new BufferedReader(new FileReader(source)); | |
| String line; | |
| while ((line = reader.readLine()) != null) | |
| set.add(line); | |
| } | |
| public static void main(String[] args) throws Exception | |
| { | |
| if (args.length < 2) | |
| { | |
| System.err.printf("Usage: java Eliminator <potential_duplicates> <baseline>\n"); | |
| System.exit(1); | |
| } | |
| Eliminator eliminator = new Eliminator(new File(args[0]), new File(args[1])); | |
| for (String unique : eliminator.unique()) | |
| System.out.printf("%s\n", unique); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment