Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.LinkedHashMap;
- import java.util.Map;
- import java.util.Scanner;
- import java.util.concurrent.atomic.AtomicReference;
- public class Registers {
- public static void main(String[] args) throws IOException {
- Scanner scanner = new Scanner(System.in);
- BufferedReader reader1 = new BufferedReader(new FileReader("C:\\Users\\SINKOPA\\Desktop\\5.txt"));
- BufferedReader reader2 = new BufferedReader(new FileReader("C:\\Users\\SINKOPA\\Desktop\\6.txt"));
- Map<String, Map<String, String>> file1 = new LinkedHashMap<>();
- Map<String, Map<String, String>> file2 = new LinkedHashMap<>();
- String line1 = reader1.readLine();
- String line2 = reader2.readLine();
- String originalKey = "";
- while (line1 != null) {
- String mainKey = "";
- String attribute = "";
- String value = "";
- if (line1.startsWith("[")) {
- mainKey = line1;
- originalKey = mainKey;
- file1.put(originalKey, new LinkedHashMap<>());
- }
- if (line1.contains("=")) {
- attribute = line1.substring(0, line1.indexOf('='));
- value = line1.substring(line1.indexOf('=') + 1);
- file1.get(originalKey).put(attribute, value);
- }
- line1 = reader1.readLine();
- }
- String originalKey2 = "";
- while (line2 != null) {
- String mainKey = "";
- String attribute = "";
- String value = "";
- if (line2.startsWith("[")) {
- mainKey = line2;
- originalKey2 = mainKey;
- file2.put(originalKey2, new LinkedHashMap<>());
- }
- if (line2.startsWith("\"") || line2.startsWith("@")) {
- attribute = line2.substring(0, line2.indexOf('='));
- value = line2.substring(line2.indexOf('=') + 1);
- file2.get(originalKey2
- ).put(attribute, value);
- }
- line2 = reader2.readLine();
- }
- while (file1.size() > 0 || file2.size() > 0) {
- String keyFileOne = "";
- String attributeFileOne = "";
- String valueFileOne = "";
- String keyFileTwo = "";
- String attributeFileTwo = "";
- String valueFileTwo = "";
- for (Map.Entry<String, Map<String, String>> kvp : file1.entrySet()) {
- keyFileOne = kvp.getKey();
- //System.out.println(keyFileOne);
- if (file1.get(kvp.getKey()).size() > 0) {
- for (Map.Entry<String, String> entry : kvp.getValue().entrySet()) {
- String a = entry.getKey();
- String v = entry.getValue();
- attributeFileOne = a;
- valueFileOne = v;
- //System.out.println(attributeFileOne.get() + "=" + valueFileOne.get());
- }
- }
- file1.remove(kvp.getKey());
- break;
- }
- for (Map.Entry<String, Map<String, String>> kvp1 : file2.entrySet()) {
- keyFileTwo = kvp1.getKey();
- //System.out.println(keyFileTwo);
- if (file2.get(kvp1.getKey()).size() > 0) {
- for (Map.Entry<String, String> entry : kvp1.getValue().entrySet()) {
- String a = entry.getKey();
- String v = entry.getValue();
- attributeFileTwo = a;
- valueFileTwo = v;
- //System.out.println(attributeFileTwo.get() + "=" + valueFileTwo.get());
- }
- }
- file2.remove(kvp1.getKey());
- break;
- }
- //do ovde radi
- if (!keyFileOne.equalsIgnoreCase(keyFileTwo) || !attributeFileOne.equalsIgnoreCase(attributeFileTwo) || !valueFileOne.equalsIgnoreCase(valueFileTwo)) {
- System.out.println(keyFileOne);
- System.out.println(attributeFileOne + "=" + valueFileOne + " ||| " + attributeFileTwo + "=" + valueFileTwo);
- System.out.println();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement