CRCRHandler extends AbstractChainOfResponsibilityHandler { public Object getLongestResult(Object result) { Object finalResult = StringUtils.EMPTY; SubDataSet dataSet = (SubDataSet) this.getHandlerParameter().getDataset(); List<Integer> dataSetIndex = dataSet.getDataSetIndex(); for (Integer rowNum : dataSetIndex) { String targetName = this.getHandlerParameter().getTargetColumn().getName(); Object targetInputData = this.getHandlerParameter().getInputData(rowNum, targetName); if (needFillColumn(targetInputData, targetName)) { targetInputData = this.getHandlerParameter().getInputData(rowNum, handlerParameter.getFillColumn()); } if (isUnexpectedValue(targetInputData)) { continue; } if (result.equals(targetInputData)) { continue; } long finalResultCPCount = finalResult.toString().codePoints().count(); long targetInputDataCPCount = targetInputData.toString().codePoints().count(); if (finalResultCPCount < targetInputDataCPCount) { finalResult = targetInputData; } } return finalResult; } CRCRHandler(HandlerParameter handlerParameter); @Override void handleRequest(Object inputData, int rowNum); @Override void handleRequest(); @Override CRCRHandler getSuccessor(); @Override AbstractChainOfResponsibilityHandler linkSuccessor(AbstractChainOfResponsibilityHandler nextHandler); SurvivedResult getSurvivedRowNum(); boolean isValidResult(); Object getLongestResult(Object result); Object getNonDuplicatedResult(Object result); boolean isMissionCompleted();  }
@Test public void testGetLongestResult() { Column col1 = new Column("city1", "String"); Column col2 = new Column("city2", "String"); Column col3 = new Column("city3", "String"); Column col4 = new Column("city4", "String"); List<Column> columns = new ArrayList<>(); columns.add(col1); columns.add(col2); columns.add(col3); columns.add(col4); DataSet dataset = new DataSet(columns); Record record1 = new Record(); record1.setId(1); Attribute att1 = new Attribute(record1, col1, "value1"); Attribute att2 = new Attribute(record1, col2, "value2"); Attribute att3 = new Attribute(record1, col2, "value33"); Attribute att4 = new Attribute(record1, col2, "value4"); record1.putAttribute("city1", att1); record1.putAttribute("city2", att2); record1.putAttribute("city3", att3); record1.putAttribute("city4", att4); col1.putAttribute(record1, att1); col2.putAttribute(record1, att2); col3.putAttribute(record1, att3); col4.putAttribute(record1, att4); Record record2 = new Record(); record2.setId(2); att1 = new Attribute(record2, col1, "value11"); att2 = new Attribute(record2, col2, null); att3 = new Attribute(record2, col2, "value3"); att4 = new Attribute(record2, col2, "value4"); record2.putAttribute("city1", att1); record2.putAttribute("city2", att2); record2.putAttribute("city3", att3); record2.putAttribute("city4", att4); col1.putAttribute(record2, att1); col2.putAttribute(record2, att2); col3.putAttribute(record2, att3); col4.putAttribute(record2, att4); dataset.getRecordList().add(record1); dataset.getRecordList().add(record2); HandlerParameter createHandlerParameter = this.createHandlerParameter(null); createHandlerParameter.setTarColumn(col1); List<Integer> conflictIndex = new ArrayList<>(); conflictIndex.add(0); conflictIndex.add(1); createHandlerParameter.setDataset(new SubDataSet(dataset, conflictIndex)); CRCRHandler crcr1 = new CRCRHandler(createHandlerParameter); Object longestResult = crcr1.getLongestResult("value"); Assert.assertEquals("The result of logest value should be value11", "value11", longestResult.toString()); longestResult = crcr1.getLongestResult("value11"); Assert.assertEquals("The result of logest value should be value1", "value1", longestResult.toString()); createHandlerParameter.setRefColumn(col2); createHandlerParameter.setTarColumn(col2); createHandlerParameter.setFillColumn("city1"); longestResult = crcr1.getLongestResult("value"); Assert.assertEquals("The result of logest value should be value11", "value11", longestResult.toString()); createHandlerParameter = this.createHandlerParameter(RuleDefinition.Function.ExcludeValues.getAction()); createHandlerParameter.setTarColumn(col1); conflictIndex = new ArrayList<>(); conflictIndex.add(0); conflictIndex.add(1); createHandlerParameter.setDataset(new SubDataSet(dataset, conflictIndex)); crcr1 = new CRCRHandler(createHandlerParameter); longestResult = crcr1.getLongestResult("value"); Assert.assertEquals("The result of logest value should be value1", "value1", longestResult.toString()); }