# HG changeset patch # User Dirk Olmes # Date 1315821808 -7200 # Node ID 9c42f25cd944487b7dba330febcd21e2a8d9c020 # Parent 6f11757c48115ddf89eca2a2f67b8aa208911d4f use a Difference object to describe the diff diff -r 6f11757c4811 -r 9c42f25cd944 conflict-editor/src/main/java/de/codedo/conflicteditor/ConflictsView.java --- a/conflict-editor/src/main/java/de/codedo/conflicteditor/ConflictsView.java Mon Sep 12 11:47:48 2011 +0200 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/ConflictsView.java Mon Sep 12 12:03:28 2011 +0200 @@ -9,6 +9,9 @@ import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.map.ObjectMapper; +/** + * Creates a temporary view in the database to retrieve all documents that have conflicts. + */ public class ConflictsView extends Object { // @formatter:off diff -r 6f11757c4811 -r 9c42f25cd944 conflict-editor/src/main/java/de/codedo/conflicteditor/Difference.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/Difference.java Mon Sep 12 12:03:28 2011 +0200 @@ -0,0 +1,31 @@ + +package de.codedo.conflicteditor; + +public class Difference extends Object +{ + public final String key; + public final Object currentValue; + public final Object otherValue; + + @SuppressWarnings("hiding") + public Difference(String key, Object currentValue, Object otherValue) + { + super(); + this.key = key; + this.currentValue = currentValue; + this.otherValue = otherValue; + } + + @Override + public String toString() + { + StringBuilder buf = new StringBuilder(128); + buf.append(key); + buf.append(" : \""); + buf.append(currentValue); + buf.append("\" - \""); + buf.append(otherValue); + buf.append("\""); + return buf.toString(); + } +} diff -r 6f11757c4811 -r 9c42f25cd944 conflict-editor/src/main/java/de/codedo/conflicteditor/DocumentMatcher.java --- a/conflict-editor/src/main/java/de/codedo/conflicteditor/DocumentMatcher.java Mon Sep 12 11:47:48 2011 +0200 +++ b/conflict-editor/src/main/java/de/codedo/conflicteditor/DocumentMatcher.java Mon Sep 12 12:03:28 2011 +0200 @@ -1,10 +1,12 @@ package de.codedo.conflicteditor; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Set; import org.codehaus.jackson.JsonNode; @@ -27,18 +29,24 @@ _other = other; } - public void compare() + public List compare() { + List differences = new ArrayList(); + Set originalFieldNames = getFieldNames(_original); for (String name : originalFieldNames) { + // TODO better handling of values - could be of non-string type really Object originalValue = _original.findValue(name).getValueAsText(); Object otherValue = _other.findValue(name).getValueAsText(); if (originalValue.equals(otherValue) == false) { - System.out.printf("%s : \"%s\" - \"%s\"\n", name, originalValue, otherValue); + Difference diff = new Difference(name, originalValue, otherValue); + differences.add(diff); } } + + return differences; } private Set getFieldNames(JsonNode node) diff -r 6f11757c4811 -r 9c42f25cd944 conflict-editor/src/test/java/de/codedo/conflicteditor/Playground.java --- a/conflict-editor/src/test/java/de/codedo/conflicteditor/Playground.java Mon Sep 12 11:47:48 2011 +0200 +++ b/conflict-editor/src/test/java/de/codedo/conflicteditor/Playground.java Mon Sep 12 12:03:28 2011 +0200 @@ -6,6 +6,7 @@ import java.io.PrintStream; import java.io.Reader; import java.net.URL; +import java.util.List; import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.map.ObjectMapper; @@ -46,7 +47,11 @@ private static void compare(JsonNode currentDocument, JsonNode conflictDocument) { - new DocumentMatcher(currentDocument, conflictDocument).compare(); + List result = new DocumentMatcher(currentDocument, conflictDocument).compare(); + for (Difference diff : result) + { + System.out.println(diff); + } } private static void prettyPrint(JsonNode node) throws IOException