public int calculateDiff(HollowEffigy comparison, int maxDiff) { runId++; simDiffCount.reset(); traverseComparisonFields(comparison, maxDiff); if(simDiffCount.diffCount >= maxDiff) return HollowEffigyCollectionPairer.MAX_MATRIX_ELEMENT_FIELD_VALUE; return score(); }
private int hashCode(HollowEffigy element, int[][] fieldPathIndexes) { int hash = 0; for(int i=0;i<fieldPathIndexes.length;i++) { hash = hash * 31; hash ^= fieldHashCode(element, fieldPathIndexes[i]); } return hash; }
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(); }
public static List<EffigyFieldPair> pair(HollowEffigy from, HollowEffigy to, Map<String, PrimaryKey> matchHints) { if(from == null || to == null) return new HollowEffigyNullPartnerPairer(from, to).pair(); if(from.getDataAccess() == null) return new HollowEffigyObjectPairer(from, to).pair(); HollowSchema schema = from.getDataAccess().getSchema(); switch(schema.getSchemaType()) { case OBJECT: return new HollowEffigyObjectPairer(from, to).pair(); case MAP: String keyType = ((HollowMapSchema)schema).getKeyType(); return new HollowEffigyMapPairer(from, to, matchHints.get(keyType)).pair(); case LIST: case SET: String elementType = ((HollowCollectionSchema)schema).getElementType(); return new HollowEffigyCollectionPairer(from, to, matchHints.get(elementType)).pair(); } throw new IllegalArgumentException("I don't know how to pair fields for type " + schema.getName() + "(" + schema.getSchemaType() + ")"); } }
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 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)); }
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)); }
@Override public List<EffigyFieldPair> pair() { if(matchHint != null) return pairByMatchHint(); return pairByMinDifference(); }
@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 traverseOriginalFields(HollowEffigy effigy) { for(Field field : effigy.getFields()) { if(field.isLeafNode()) { FieldDiffCount fieldCount = map.get(field); if(fieldCount == null) { fieldCount = new FieldDiffCount(); map.put(field, fieldCount); } fieldCount.incrementOriginalCount(); totalOriginalFieldCount++; } else { traverseOriginalFields((HollowEffigy) field.getValue()); } } }
public void traverseComparisonFields(HollowEffigy comparison, int maxDiff) { for(Field field : comparison.getFields()) { if(field.isLeafNode()) { FieldDiffCount fieldCount = map.get(field); if(fieldCount == null) { if(simDiffCount.diffCount+1 >= maxDiff) { simDiffCount.diffCount++; return; } fieldCount = new FieldDiffCount(); map.put(field, fieldCount); } if(fieldCount.incrementComparisonCount(runId)) { if(++simDiffCount.diffCount >= maxDiff) return; } else { simDiffCount.simCount++; } } else { traverseComparisonFields((HollowEffigy) field.getValue(), maxDiff); if(simDiffCount.diffCount >= maxDiff) return; } } }
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)); } }
private void collapseChildrenUnderRootOrderingDiffRows(HollowDiffViewRow row) { if(row.areChildrenPopulated()) { for(HollowDiffViewRow child : row.getChildren()) { if(child.getFieldPair().isOrderingDiff()) { makeAllChildrenInvisible(child); } else { collapseChildrenUnderRootOrderingDiffRows(child); } } } }
private boolean recordsMatch(HollowEffigy fromElement, HollowEffigy toElement, int[][] fromFieldPathIndexes, int[][] toFieldPathIndexes) { for(int i=0;i<fromFieldPathIndexes.length;i++) { if(!fieldsAreEqual(fromElement, toElement, fromFieldPathIndexes[i], toFieldPathIndexes[i])) return false; } return true; }
private boolean incrementComparisonCount(int runId) { clearComparisonIfRunChanged(runId); return ++comparisonCount > originalCount; }
public HollowEffigyDiffRecord(HollowEffigy basedOn) { this.map = new HashMap<HollowEffigy.Field, FieldDiffCount>(); traverseOriginalFields(basedOn); }
private boolean calculateIsDiff() { if((from == null && to != null) || (from != null && to == null)) return true; if(from.getValue() == null) return to.getValue() != null; if(isLeafNode()) return !from.getValue().equals(to.getValue()); return false; }
private void collapseChildrenUnderRootDiffRows(HollowDiffViewRow row) { if(row.areChildrenPopulated()) { for(HollowDiffViewRow child : row.getChildren()) { if(child.getFieldPair().isDiff()) { makeAllChildrenInvisible(child); } else { collapseChildrenUnderRootDiffRows(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 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; }