Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement