List<HollowDiffViewRow> traverseEffigyToCreateViewRows(HollowDiffViewRow parent) { if(parent.getFieldPair().isLeafNode()) return Collections.emptyList(); Field fromField = parent.getFieldPair().getFrom(); Field toField = parent.getFieldPair().getTo(); HollowEffigy from = fromField == null ? null : (HollowEffigy) fromField.getValue(); HollowEffigy to = toField == null ? null : (HollowEffigy) toField.getValue(); List<EffigyFieldPair> pairs = HollowEffigyFieldPairer.pair(from, to, diffUI.getMatchHints()); List<HollowDiffViewRow> childRows = new ArrayList<HollowDiffViewRow>(); for(int i=0;i<pairs.size();i++) { EffigyFieldPair pair = pairs.get(i); int indentation = parent.getRowPath().length + 1; int rowPath[] = Arrays.copyOf(parent.getRowPath(), indentation); rowPath[rowPath.length - 1] = i; childRows.add(new HollowDiffViewRow(pair, rowPath, parent, this)); } return childRows; }
fieldPairs.add(new EffigyFieldPair(null, to.getFields().get(i), -1, i)); return fieldPairs; } else if(to.getFields().size() == 0) { for(int i=0;i<from.getFields().size();i++) fieldPairs.add(new EffigyFieldPair(from.getFields().get(i), null, i, -1)); HollowEffigy toEffigy = getComparisonEffigy((HollowEffigy) to.getFields().get(toIdx).getValue()); if(recordsMatch(fromEffigy, toEffigy, fromFieldPathIndexes, toFieldPathIndexes)) { fieldPairs.add(new EffigyFieldPair(from.getFields().get(i), to.getFields().get(toIdx), i, toIdx));
private static void buildChildRowDisplayData(HollowDiffViewRow parentRow, Writer writer, boolean firstRow) throws IOException { for(HollowDiffViewRow row : parentRow.getChildren()) { if(row.isVisible()) { if(firstRow) { firstRow = false; } else { writer.write("|"); } writeRowPathString(row, writer); writer.write("|"); writer.write(row.getAvailableAction().toString()); writer.write("|"); writer.write(marginIdx(row.getFieldPair().getFromIdx())); writer.write("|"); writer.write(fromCellClassname(row)); writer.write("|"); writer.write(fromContent(row)); writer.write("|"); writer.write(marginIdx(row.getFieldPair().getToIdx())); writer.write("|"); writer.write(toCellClassname(row)); writer.write("|"); writer.write(toContent(row)); buildChildRowDisplayData(row, writer, false); } } }
continue; fieldPairs.add(new EffigyFieldPair(from.getFields().get(fromIndex), to.getFields().get(toIndex), fromIndex, toIndex)); pairedFromIndices.set(fromIndex); pairedToIndices.set(toIndex);
private int resetViewForDiff(HollowDiffViewRow row, int runningVisibilityCount) { if(rowIsExactMatch(row)) return 0; int branchVisibilityCount = 0; if(row.getFieldPair().isDiff()) { row.setVisibility(true); totalVisibilityCount++; branchVisibilityCount++; branchVisibilityCount += makeAllChildrenVisible(row, branchVisibilityCount + runningVisibilityCount); } else { for(HollowDiffViewRow child : row.getChildren()) { branchVisibilityCount += resetViewForDiff(child, branchVisibilityCount + runningVisibilityCount); if(branchVisibilityCount > 0) { row.setVisibility(true); totalVisibilityCount++; branchVisibilityCount++; } } } return branchVisibilityCount; }
private int resetViewForOrderingChanges(HollowDiffViewRow row, int runningVisibilityCount) { if(rowIsExactMatch(row)) return 0; int branchVisibilityCount = 0; if(row.getFieldPair().isOrderingDiff()) { row.setVisibility(true); branchVisibilityCount++; } else { for(HollowDiffViewRow child : row.getChildren()) { int childBranchVisibilityCount = resetViewForOrderingChanges(child, runningVisibilityCount + branchVisibilityCount); if(childBranchVisibilityCount > 0) { row.setVisibility(true); branchVisibilityCount += childBranchVisibilityCount; } } } return branchVisibilityCount; }
/** * Returns a String representation of the provided row's field value. If `useFrom` is * true, this will use the `from` value from the pair, otherwise this will use the * `to` value. */ private static String getFieldValue(HollowDiffViewRow row, boolean useFrom) { Field field = useFrom ? row.getFieldPair().getFrom() : row.getFieldPair().getTo(); if (row.getFieldPair().isLeafNode()) { return field.getValue() == null ? "null" : field.getValue().toString().replace("|", "│"); } else { String suffix = field.getValue() == null ? " [null]" : ""; return "(" + field.getTypeName() + ")" + suffix; } }
private static String fromCellClassname(HollowDiffViewRow currentRow) { if(currentRow.getFieldPair().getTo() == null) return "delete"; else if(currentRow.getFieldPair().getFrom() == null) return "empty"; if(currentRow.getFieldPair().getFrom().getValue() == null && currentRow.getFieldPair().getTo().getValue() != null) return "replace"; if(currentRow.getFieldPair().getFrom().getValue() != null && currentRow.getFieldPair().getTo().getValue() == null) return "replace"; if(currentRow.getFieldPair().getFrom().getValue() == null && currentRow.getFieldPair().getTo().getValue() == null) return "equal"; if(currentRow.getFieldPair().isLeafNode() && !currentRow.getFieldPair().getFrom().getValue().equals(currentRow.getFieldPair().getTo().getValue())) return "replace"; return "equal"; }
@Override public List<EffigyFieldPair> pair() { List<EffigyFieldPair> pairs = new ArrayList<EffigyFieldPair>(); if(from != null) { for(int i=0;i<from.getFields().size();i++) { pairs.add(new EffigyFieldPair(from.getFields().get(i), null, i, -1)); } } else if(to != null) { for(int i=0;i<to.getFields().size();i++) { pairs.add(new EffigyFieldPair(null, to.getFields().get(i), -1, i)); } } return pairs; }
private static String toCellClassname(HollowDiffViewRow currentRow) { if(currentRow.getFieldPair().getFrom() == null) return "insert"; else if(currentRow.getFieldPair().getTo() == null) return "empty"; if(currentRow.getFieldPair().getFrom().getValue() == null && currentRow.getFieldPair().getTo().getValue() != null) return "replace"; if(currentRow.getFieldPair().getFrom().getValue() != null && currentRow.getFieldPair().getTo().getValue() == null) return "replace"; if(currentRow.getFieldPair().getFrom().getValue() == null && currentRow.getFieldPair().getTo().getValue() == null) return "equal"; if(currentRow.getFieldPair().isLeafNode() && !currentRow.getFieldPair().getFrom().getValue().equals(currentRow.getFieldPair().getTo().getValue())) return "replace"; return "equal"; }
@Override public List<EffigyFieldPair> pair() { List<EffigyFieldPair> fieldPairs = new ArrayList<EffigyFieldPair>(); for(Field fromField : from.getFields()) { fieldPairs.add(new EffigyFieldPair(fromField, getField(to, fromField.getFieldName()), -1, -1)); } for(Field toField : to.getFields()) { Field fromField = getField(from, toField.getFieldName()); if(fromField == null) fieldPairs.add(new EffigyFieldPair(null, toField, -1, -1)); } return fieldPairs; }
private void assertPair(EffigyFieldPair pair, String expectedFromField1, String expectedToField1) { if(expectedFromField1 != null) { HollowEffigy element = (HollowEffigy) pair.getFrom().getValue(); Assert.assertEquals(expectedFromField1, element.getFields().get(0).getValue()); } else { Assert.assertNull(pair.getFrom()); } if(expectedToField1 != null) { HollowEffigy element = (HollowEffigy) pair.getTo().getValue(); Assert.assertEquals(expectedToField1, element.getFields().get(0).getValue()); } else { Assert.assertNull(pair.getTo()); } }
private void collapseChildrenUnderRootOrderingDiffRows(HollowDiffViewRow row) { if(row.areChildrenPopulated()) { for(HollowDiffViewRow child : row.getChildren()) { if(child.getFieldPair().isOrderingDiff()) { makeAllChildrenInvisible(child); } else { collapseChildrenUnderRootOrderingDiffRows(child); } } } }
private HollowDiffViewRow createRootRow(HollowEffigy fromEffigy, HollowEffigy toEffigy) { HollowEffigy.Field fromField = fromEffigy == null ? null : new HollowEffigy.Field(null, fromEffigy); HollowEffigy.Field toField = toEffigy == null ? null : new HollowEffigy.Field(null, toEffigy); EffigyFieldPair fieldPair = new EffigyFieldPair(fromField, toField, -1, -1); return new HollowDiffViewRow(fieldPair, new int[0], null, this); }
private void addUnmatchedElements(List<EffigyFieldPair> fieldPairs, BitSet pairedFromIndices, BitSet pairedToIndices) { for(int i=0;i<from.getFields().size();i++) { if(!pairedFromIndices.get(i)) fieldPairs.add(new EffigyFieldPair(from.getFields().get(i), null, i, -1)); } for(int i=0;i<to.getFields().size();i++) { if(!pairedToIndices.get(i)) fieldPairs.add(new EffigyFieldPair(null, to.getFields().get(i), -1, i)); } }
public EffigyFieldPair(Field from, Field to, int fromIdx, int toIdx) { this.from = from; this.to = to; this.fromIdx = fromIdx; this.toIdx = toIdx; this.isDiff = calculateIsDiff(); }
private void collapseChildrenUnderRootDiffRows(HollowDiffViewRow row) { if(row.areChildrenPopulated()) { for(HollowDiffViewRow child : row.getChildren()) { if(child.getFieldPair().isDiff()) { makeAllChildrenInvisible(child); } else { collapseChildrenUnderRootDiffRows(child); } } } }
private boolean moreRows(HollowDiffViewRow parent, int childIdx, boolean from) { for(int i=childIdx+1;i<parent.getChildren().size();i++) { EffigyFieldPair fieldPair = parent.getChildren().get(i).getFieldPair(); if((from && fieldPair.getFrom() != null) || (!from && fieldPair.getTo() != null)) return true; } return false; }
private static String toContent(HollowDiffViewRow row) { boolean moreRows[] = new boolean[row.getIndentation() + 1]; for(int i=0;i<=row.getIndentation();i++) moreRows[i] = row.hasMoreToRows(i); if(row.getFieldPair().getTo() == null) return unpopulatedContent(moreRows); String fieldName = row.getFieldPair().getTo().getFieldName(); return populatedContent(moreRows, row.getIndentation(), row.getFieldPair().isLeafNode(), fieldName, getFieldValue(row, false)); }
private static String fromContent(HollowDiffViewRow row) { boolean moreRows[] = new boolean[row.getIndentation() + 1]; for(int i=0;i<=row.getIndentation();i++) moreRows[i] = row.hasMoreFromRows(i); if(row.getFieldPair().getFrom() == null) return unpopulatedContent(moreRows); String fieldName = row.getFieldPair().getFrom().getFieldName(); return populatedContent(moreRows, row.getIndentation(), row.getFieldPair().isLeafNode(), fieldName, getFieldValue(row, true)); }