Main.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package com.pact;
  2. import java.io.*;
  3. import java.util.HashSet;
  4. public class Main {
  5. public HashSet<Node> process(String in)
  6. throws IOException, BracketException
  7. {
  8. BufferedReader inB = new BufferedReader(new FileReader(in));
  9. String line;
  10. HashSet<Node> templates = null;
  11. while((line = inB.readLine()) != null){
  12. if(templates == null) {
  13. // Load first line into template
  14. templates = new HashSet();
  15. templates.add(new Node(null, line));
  16. continue;
  17. }
  18. HashSet<Node> allCombined = new HashSet();
  19. Node input = new Node(null, line);
  20. for (Node template : templates) {
  21. // Get all the ways we can combine input with template
  22. HashSet<Node> combined = template.reducedCombine(input);
  23. System.out.println("com: " + combined);
  24. allCombined.addAll(combined);
  25. }
  26. templates = allCombined;
  27. }
  28. inB.close();
  29. return templates;
  30. }
  31. public static void main(String[] args) {
  32. Main main = new Main();
  33. String inputFilename = "input.txt";
  34. HashSet<Node> result;
  35. try {
  36. result = main.process(inputFilename);
  37. System.out.println("----------------------------------------");
  38. System.out.println("----------------------------------------");
  39. for(Node node : result){
  40. System.out.println(node.getVenn());
  41. }
  42. } catch (IOException e){
  43. System.out.println("Status: Fail, write error\n" + e);
  44. }
  45. }
  46. }