# HG changeset patch
# User dirk
# Date 1316234953 -7200
# Node ID 47f6cbd38de3e1cf146c3bf3ba932dc097fbc584
# Parent  e60d38aa42fe4a13a0a1169a67d6c5690a38ab7c
clean code!

diff -r e60d38aa42fe -r 47f6cbd38de3 conflict-editor/src/main/java/de/codedo/conflicteditor/DocumentMatcher.java
--- a/conflict-editor/src/main/java/de/codedo/conflicteditor/DocumentMatcher.java	Fri Sep 16 17:03:57 2011 +0200
+++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/DocumentMatcher.java	Sat Sep 17 06:49:13 2011 +0200
@@ -44,11 +44,7 @@
 
     private void createDifferencesFromFieldsOnlyAvailableInOriginal()
     {
-        Set<String> originalFieldNames = getFieldNames(_original);
-        Set<String> otherFieldNames = getFieldNames(_other);
-        originalFieldNames.removeAll(otherFieldNames);
-
-        for (String name : originalFieldNames)
+        for (String name : calculateFieldNamesInOriginalOnly())
         {
             // TODO value may not be text
             String value = _original.findValue(name).getTextValue();
@@ -57,13 +53,17 @@
         }
     }
 
-    private void createDifferencesFromFieldsOnlyAvailableInConflict()
+    private Set<String> calculateFieldNamesInOriginalOnly()
     {
         Set<String> originalFieldNames = getFieldNames(_original);
         Set<String> otherFieldNames = getFieldNames(_other);
-        otherFieldNames.removeAll(originalFieldNames);
+        originalFieldNames.removeAll(otherFieldNames);
+        return originalFieldNames;
+    }
 
-        for (String name : otherFieldNames)
+    private void createDifferencesFromFieldsOnlyAvailableInConflict()
+    {
+        for (String name : calculateFieldNamesInOtherOnly())
         {
             // TODO value may not be text
             String value = _other.findValue(name).getTextValue();
@@ -72,13 +72,17 @@
         }
     }
 
-    private void createDifferencesFromFieldValues()
+    private Set<String> calculateFieldNamesInOtherOnly()
     {
         Set<String> originalFieldNames = getFieldNames(_original);
         Set<String> otherFieldNames = getFieldNames(_other);
-        originalFieldNames.retainAll(otherFieldNames);
+        otherFieldNames.removeAll(originalFieldNames);
+        return otherFieldNames;
+    }
 
-        for (String name : originalFieldNames)
+    private void createDifferencesFromFieldValues()
+    {
+        for (String name : calculateCommonFieldNames())
         {
             Difference difference = compareValuesForKey(name);
             if (difference != null)
@@ -88,6 +92,14 @@
         }
     }
 
+    private Set<String> calculateCommonFieldNames()
+    {
+        Set<String> originalFieldNames = getFieldNames(_original);
+        Set<String> otherFieldNames = getFieldNames(_other);
+        originalFieldNames.retainAll(otherFieldNames);
+        return originalFieldNames;
+    }
+
     private Difference compareValuesForKey(String key)
     {
         JsonNode original = _original.findValue(key);