# 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 originalFieldNames = getFieldNames(_original); - Set 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 calculateFieldNamesInOriginalOnly() { Set originalFieldNames = getFieldNames(_original); Set 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 calculateFieldNamesInOtherOnly() { Set originalFieldNames = getFieldNames(_original); Set 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 calculateCommonFieldNames() + { + Set originalFieldNames = getFieldNames(_original); + Set otherFieldNames = getFieldNames(_other); + originalFieldNames.retainAll(otherFieldNames); + return originalFieldNames; + } + private Difference compareValuesForKey(String key) { JsonNode original = _original.findValue(key);