GroupingCallBack implements MatchMergeAlgorithm.Callback { @Override public void onNewMerge(Record record) { RichRecord richRecord = (RichRecord) record; richRecord.setMaster(true); richRecord.setScore(1.0); if (record.getGroupId() != null) { richRecord.setMerged(true); richRecord.setGrpSize(richRecord.getRelatedIds().size()); if (Double.compare(richRecord.getGroupQuality(), 0.0d) == 0 || Double.compare(richRecord.getGroupQuality(), richRecord.getConfidence()) > 0) { richRecord.setGroupQuality(record.getConfidence()); } } } GroupingCallBack(BidiMultiMap<String, String> oldGID2New, AbstractRecordGrouping<T> recordGrouping); @Override void onBeginRecord(Record record); @Override void onMatch(Record record1, Record record2, MatchResult matchResult); @Override void onNewMerge(Record record); @Override void onRemoveMerge(Record record); @Override void onDifferent(Record record1, Record record2, MatchResult matchResult); @Override void onEndRecord(Record record); @Override boolean isInterrupted(); @Override void onBeginProcessing(); @Override void onEndProcessing(); @Override void onSynResult(Record newRecord, Record originalRecord, MatchResult matchResult);  }
@Test public void testOnNewMerge() { GroupingCallBack<Object> groupingCallBack = new GroupingCallBack<>(oldGID2New, recordGrouping); RichRecord record1 = new RichRecord("id1", new Date().getTime(), "source1"); record1.setGroupId("group1"); record1.setMaster(false); record1.setScore(2.0); record1.setMerged(false); record1.getRelatedIds().add("id2"); record1.getRelatedIds().add("id3"); record1.setGroupQuality(0.0); record1.setConfidence(0.5); groupingCallBack.onNewMerge(record1); Assert.assertEquals("The master of record1 should be true", true, record1.isMaster()); Assert.assertEquals("The score of record1 should be 1.0", "1.0", "" + record1.getScore()); Assert.assertEquals("The merged of record1 should be true", true, record1.isMerged()); Assert.assertEquals("The GrpSize of record1 should be 2", 2, record1.getGrpSize()); Assert.assertEquals("The GroupQuality of record1 should be 0.5", "0.5", "" + record1.getGroupQuality()); record1 = new RichRecord("id1", new Date().getTime(), "source1"); record1.setMaster(false); record1.setScore(2.0); record1.setMerged(false); record1.getRelatedIds().add("id2"); record1.getRelatedIds().add("id3"); record1.setGroupQuality(0.0); record1.setConfidence(0.5); groupingCallBack.onNewMerge(record1); Assert.assertEquals("The master of record1 should be true", true, record1.isMaster()); Assert.assertEquals("The score of record1 should be 1.0", "1.0", "" + record1.getScore()); Assert.assertEquals("The merged of record1 should be false", false, record1.isMerged()); Assert.assertEquals("The GrpSize of record1 should be 0", 0, record1.getGrpSize()); Assert.assertEquals("The GroupQuality of record1 should be 0.0", "0.0", "" + record1.getGroupQuality()); record1 = new RichRecord("id1", new Date().getTime(), "source1"); record1.setGroupId("group1"); record1.setMaster(false); record1.setScore(2.0); record1.setMerged(false); record1.getRelatedIds().add("id2"); record1.getRelatedIds().add("id3"); record1.setGroupQuality(0.1); record1.setConfidence(0.5); groupingCallBack.onNewMerge(record1); Assert.assertEquals("The master of record1 should be true", true, record1.isMaster()); Assert.assertEquals("The score of record1 should be 1.0", "1.0", "" + record1.getScore()); Assert.assertEquals("The merged of record1 should be true", true, record1.isMerged()); Assert.assertEquals("The GrpSize of record1 should be 2", 2, record1.getGrpSize()); Assert.assertEquals("The GroupQuality of record1 should be 0.1", "0.1", "" + record1.getGroupQuality()); }