Advertisement
elvirynwa

TextComparator

Apr 27th, 2020
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.36 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4. import java.util.LinkedHashMap;
  5. import java.util.Map;
  6. import java.util.Scanner;
  7. import java.util.concurrent.atomic.AtomicReference;
  8.  
  9. public class Registers {
  10.     public static void main(String[] args) throws IOException {
  11.         Scanner scanner = new Scanner(System.in);
  12.  
  13.         BufferedReader reader1 = new BufferedReader(new FileReader("C:\\Users\\SINKOPA\\Desktop\\5.txt"));
  14.         BufferedReader reader2 = new BufferedReader(new FileReader("C:\\Users\\SINKOPA\\Desktop\\6.txt"));
  15.  
  16.         Map<String, Map<String, String>> file1 = new LinkedHashMap<>();
  17.         Map<String, Map<String, String>> file2 = new LinkedHashMap<>();
  18.  
  19.         String line1 = reader1.readLine();
  20.         String line2 = reader2.readLine();
  21.  
  22.         String originalKey = "";
  23.  
  24.         while (line1 != null) {
  25.             String mainKey = "";
  26.             String attribute = "";
  27.             String value = "";
  28.             if (line1.startsWith("[")) {
  29.                 mainKey = line1;
  30.                 originalKey = mainKey;
  31.                 file1.put(originalKey, new LinkedHashMap<>());
  32.             }
  33.             if (line1.contains("=")) {
  34.                 attribute = line1.substring(0, line1.indexOf('='));
  35.                 value = line1.substring(line1.indexOf('=') + 1);
  36.                 file1.get(originalKey).put(attribute, value);
  37.  
  38.             }
  39.  
  40.             line1 = reader1.readLine();
  41.         }
  42.  
  43.         String originalKey2 = "";
  44.         while (line2 != null) {
  45.             String mainKey = "";
  46.             String attribute = "";
  47.             String value = "";
  48.             if (line2.startsWith("[")) {
  49.                 mainKey = line2;
  50.                 originalKey2 = mainKey;
  51.                 file2.put(originalKey2, new LinkedHashMap<>());
  52.             }
  53.             if (line2.startsWith("\"") || line2.startsWith("@")) {
  54.                 attribute = line2.substring(0, line2.indexOf('='));
  55.                 value = line2.substring(line2.indexOf('=') + 1);
  56.                 file2.get(originalKey2
  57.                 ).put(attribute, value);
  58.  
  59.             }
  60.  
  61.             line2 = reader2.readLine();
  62.         }
  63.  
  64.         while (file1.size() > 0 || file2.size() > 0) {
  65.             String keyFileOne = "";
  66.             String attributeFileOne = "";
  67.             String valueFileOne = "";
  68.  
  69.             String keyFileTwo = "";
  70.             String attributeFileTwo = "";
  71.             String valueFileTwo = "";
  72.             for (Map.Entry<String, Map<String, String>> kvp : file1.entrySet()) {
  73.                 keyFileOne = kvp.getKey();
  74.                 //System.out.println(keyFileOne);
  75.                 if (file1.get(kvp.getKey()).size() > 0) {
  76.                     for (Map.Entry<String, String> entry : kvp.getValue().entrySet()) {
  77.                         String a = entry.getKey();
  78.                         String v = entry.getValue();
  79.                         attributeFileOne = a;
  80.                         valueFileOne = v;
  81.                         //System.out.println(attributeFileOne.get() + "=" + valueFileOne.get());
  82.                     }
  83.                 }
  84.                 file1.remove(kvp.getKey());
  85.                 break;
  86.             }
  87.             for (Map.Entry<String, Map<String, String>> kvp1 : file2.entrySet()) {
  88.                 keyFileTwo = kvp1.getKey();
  89.                 //System.out.println(keyFileTwo);
  90.                 if (file2.get(kvp1.getKey()).size() > 0) {
  91.                     for (Map.Entry<String, String> entry : kvp1.getValue().entrySet()) {
  92.                         String a = entry.getKey();
  93.                         String v = entry.getValue();
  94.                         attributeFileTwo = a;
  95.                         valueFileTwo = v;
  96.                         //System.out.println(attributeFileTwo.get() + "=" + valueFileTwo.get());
  97.                     }
  98.                 }
  99.                 file2.remove(kvp1.getKey());
  100.                 break;
  101.             }
  102.             //do ovde radi
  103.             if (!keyFileOne.equalsIgnoreCase(keyFileTwo) || !attributeFileOne.equalsIgnoreCase(attributeFileTwo) || !valueFileOne.equalsIgnoreCase(valueFileTwo)) {
  104.                 System.out.println(keyFileOne);
  105.                 System.out.println(attributeFileOne + "=" + valueFileOne + "  |||  " + attributeFileTwo + "=" + valueFileTwo);
  106.                 System.out.println();
  107.             }
  108.         }
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement