use of org.javers.core.diff.Change in project jag-pcss-civil by bcgov.
the class TestService method printDiff.
private void printDiff(Diff diff) {
int diffSize = diff.getChanges().size();
if (diffSize == 0) {
return;
}
String[] header = new String[] { "Property", "API Response", "WM Response" };
String[][] table = new String[diffSize + 1][3];
table[0] = header;
for (int i = 0; i < diffSize; ++i) {
Change ch = diff.getChanges().get(i);
if (ch instanceof ListChange) {
String apiVal = ((ListChange) ch).getLeft() == null ? "null" : ((ListChange) ch).getLeft().toString();
String wmVal = ((ListChange) ch).getRight() == null ? "null" : ((ListChange) ch).getRight().toString();
table[i + 1][0] = ((ListChange) ch).getPropertyNameWithPath();
table[i + 1][1] = apiVal;
table[i + 1][2] = wmVal;
} else if (ch instanceof ValueChange) {
String apiVal = ((ValueChange) ch).getLeft() == null ? "null" : ((ValueChange) ch).getLeft().toString();
String wmVal = ((ValueChange) ch).getRight() == null ? "null" : ((ValueChange) ch).getRight().toString();
table[i + 1][0] = ((ValueChange) ch).getPropertyNameWithPath();
table[i + 1][1] = apiVal;
table[i + 1][2] = wmVal;
}
}
boolean leftJustifiedRows = false;
int totalColumnLength = 10;
/*
* Calculate appropriate Length of each column by looking at width of data in
* each column.
*
* Map columnLengths is <column_number, column_length>
*/
Map<Integer, Integer> columnLengths = new HashMap<>();
Arrays.stream(table).forEach(a -> Stream.iterate(0, (i -> i < a.length), (i -> ++i)).forEach(i -> {
if (columnLengths.get(i) == null) {
columnLengths.put(i, 0);
}
if (columnLengths.get(i) < a[i].length()) {
columnLengths.put(i, a[i].length());
}
}));
for (Map.Entry<Integer, Integer> e : columnLengths.entrySet()) {
totalColumnLength += e.getValue();
}
fileOutput.println("=".repeat(totalColumnLength));
System.out.println("=".repeat(totalColumnLength));
final StringBuilder formatString = new StringBuilder("");
String flag = leftJustifiedRows ? "-" : "";
columnLengths.entrySet().stream().forEach(e -> formatString.append("| %" + flag + e.getValue() + "s "));
formatString.append("|\n");
Stream.iterate(0, (i -> i < table.length), (i -> ++i)).forEach(a -> {
fileOutput.printf(formatString.toString(), table[a]);
System.out.printf(formatString.toString(), table[a]);
});
fileOutput.println("=".repeat(totalColumnLength));
System.out.println("=".repeat(totalColumnLength));
}
Aggregations