Field field = new Field(fieldName, fieldType, fieldValue); if(schema.getFieldType(i) != FieldType.REFERENCE) field = memoize(field);
HollowEffigy comparisonEffigy = getComparisonEffigy((HollowEffigy) to.getFields().get(i).getValue()); int hash = hashCode(comparisonEffigy, toFieldPathIndexes); hash &= hashedToFieldIndexes.length-1; HollowEffigy fromEffigy = getComparisonEffigy((HollowEffigy) from.getFields().get(i).getValue()); int hash = hashCode(fromEffigy, fromFieldPathIndexes); hash &= hashedToFieldIndexes.length-1; int toIdx = hashedToFieldIndexes[hash]; if(!matchedToElements.get(toIdx)) { 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));
@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; }
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; } } }
public long[] pair(final BitSet pairedFromIndices, final BitSet pairedToIndices, final int maxDiff) { final long diffMatrixElements[] = new long[from.getFields().size() * to.getFields().size()]; int matrixElementIdx = 0; for(int i=0;i<from.getFields().size();i++) { final int fromIdx = i; if(pairedFromIndices.get(fromIdx)) { for(int j=0;j<to.getFields().size();j++) { diffMatrixElements[matrixElementIdx++] = getDiffMatrixElement(fromIdx, j, MAX_MATRIX_ELEMENT_FIELD_VALUE); } } else { HollowEffigy fromElement = getComparisonEffigy((HollowEffigy) from.getFields().get(fromIdx).getValue()); HollowEffigyDiffRecord diffRecord = new HollowEffigyDiffRecord(fromElement); for(int j=0;j<to.getFields().size();j++) { if(pairedToIndices.get(j)) { diffMatrixElements[matrixElementIdx++] = getDiffMatrixElement(fromIdx, j, MAX_MATRIX_ELEMENT_FIELD_VALUE); } else { HollowEffigy toElement = getComparisonEffigy((HollowEffigy) to.getFields().get(j).getValue()); int diffScore = diffRecord.calculateDiff(toElement, maxDiff); diffMatrixElements[matrixElementIdx++] = getDiffMatrixElement(fromIdx, j, diffScore); } } } } return diffMatrixElements; }
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; }
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"; }
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"; }
/** * 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 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()); } } }
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()); } }
@Override protected HollowEffigy getComparisonEffigy(HollowEffigy effigy) { return (HollowEffigy) effigy.getFields().get(0).getValue(); }
private List<Field> createMapFields(HollowEffigy effigy) { List<Field> fields = new ArrayList<Field>(); HollowMapTypeDataAccess typeDataAccess = (HollowMapTypeDataAccess)effigy.dataAccess; HollowMapSchema schema = typeDataAccess.getSchema(); HollowMapEntryOrdinalIterator iter = typeDataAccess.ordinalIterator(effigy.ordinal); while(iter.next()) { HollowEffigy entryEffigy = new HollowEffigy("Map.Entry"); entryEffigy.add(new Field("key", effigy(typeDataAccess.getDataAccess(), schema.getKeyType(), iter.getKey()))); entryEffigy.add(new Field("value", effigy(typeDataAccess.getDataAccess(), schema.getValueType(), iter.getValue()))); fields.add(new Field("entry", "Map.Entry", entryEffigy)); } return fields; }
private List<Field> createCollectionFields(HollowEffigy effigy) { List<Field> fields = new ArrayList<Field>(); HollowCollectionTypeDataAccess typeDataAccess = (HollowCollectionTypeDataAccess) effigy.dataAccess; HollowCollectionSchema schema = typeDataAccess.getSchema(); HollowOrdinalIterator iter = typeDataAccess.ordinalIterator(effigy.ordinal); int elementOrdinal = iter.next(); while(elementOrdinal != NO_MORE_ORDINALS) { HollowEffigy elementEffigy = effigy(typeDataAccess.getDataAccess(), schema.getElementType(), elementOrdinal); fields.add(new Field("element", elementEffigy)); elementOrdinal = iter.next(); } return fields; }
public boolean isLeafNode() { return (from != null && from.getValue() != null) ? from.isLeafNode() : to == null ? true : to.isLeafNode(); } public boolean isDiff() {
private boolean rowIsExactMatch(HollowDiffViewRow row) { EffigyFieldPair fieldPair = row.getFieldPair(); if(fieldPair.getFrom() == null || fieldPair.getTo() == null || fieldPair.isLeafNode()) return false; HollowEffigy fromEffigy = (HollowEffigy)fieldPair.getFrom().getValue(); HollowEffigy toEffigy = (HollowEffigy)fieldPair.getTo().getValue(); if(fromEffigy == null || toEffigy == null) return false; return exactRecordMatcher.isExactMatch(fromEffigy.getDataAccess(), fromEffigy.getOrdinal(), toEffigy.getDataAccess(), toEffigy.getOrdinal()); }
public Field getField(HollowEffigy effigy, String fieldName) { for(Field field : effigy.getFields()) { if(field.getFieldName().equals(fieldName)) return field; } return null; }
private HollowEffigy list(HollowEffigy... elements) { HollowEffigy list = new HollowEffigy("list"); for(HollowEffigy element : elements) { list.add(new Field("element", element)); } return list; }