@Test public void testCycleReferenceCompare() { List<Comparator> comparators = new ArrayList<Comparator>(); comparators.add(new SimpleComparator()); comparators.add(new MapComparator()); comparators.add(new ObjectComparator()); IntegratedComparator comparator = new IntegratedComparator(comparators); Map<String, String> extensions = new HashMap<String, String>(); extensions.put("name", "sandbox-repeater"); extensions.put("version", "1.0.0"); IntegratedCompareDO left = IntegratedCompareDO.builder() .name("sandbox") .character('s') .extentions(extensions) .salary(10000.0D) .count(10) .localDateTime(LocalDateTime.now()) .money(new BigDecimal(10000.0)) .student(Student.builder() .name("YueBing") .age(29) .school("Peking University") .build()) .build(); IntegratedCompareDO right = IntegratedCompareDO.builder() .name("repeater") .character('t') .extentions(extensions) .salary(10000.1D) .count(12) .localDateTime(LocalDateTime.now()) .money(new BigDecimal(10000.0)) .student(Student.builder() .name("YueBing") .age(29) .school("Tsinghua university") .build()) .build(); left.setParent(right); right.setParent(left); CompareResult result = comparator.compare(left, right); Assert.assertNotEquals(result, null); Assert.assertTrue(result.hasDifference()); Assert.assertEquals(result.getDifferences().size(), 10); }
@Override public CompareResult compare(Object left, Object right) { tryClear(); List<Path> paths = new ArrayList<Path>(0); try { dispatch(left, right, paths); } catch (Exception e) { addDifference(left, right, Difference.Type.COMPARE_ERR, paths); } return new CompareResult(left, right, differences); }
IntegratedComparator implements Comparable { @Override public CompareResult compare(Object left, Object right) { tryClear(); List<Path> paths = new ArrayList<Path>(0); try { dispatch(left, right, paths); } catch (Exception e) { addDifference(left, right, Difference.Type.COMPARE_ERR, paths); } return new CompareResult(left, right, differences); } }
IntegratedComparator implements Comparable { @Override public CompareResult compare(Object left, Object right) { tryClear(); List<Path> paths = new ArrayList<Path>(0); try { dispatch(left, right, paths); } catch (Exception e) { addDifference(left, right, Difference.Type.COMPARE_ERR, paths); } return new CompareResult(left, right, differences); } IntegratedComparator(List<Comparator> comparators); }
IntegratedComparator implements Comparable { @Override public CompareResult compare(Object left, Object right) { tryClear(); List<Path> paths = new ArrayList<Path>(0); try { dispatch(left, right, paths); } catch (Exception e) { addDifference(left, right, Difference.Type.COMPARE_ERR, paths); } return new CompareResult(left, right, differences); } IntegratedComparator(List<Comparator> comparators); void dispatch(Object left, Object right, List<Path> paths); @Override CompareResult compare(Object left, Object right); void addDifference(Object left, Object right, Difference.Type type, List<Path> paths); List<Path> declarePath(List<Path> paths, int index); List<Path> declarePath(List<Path> paths, String key); }
IntegratedComparator implements Comparable { @Override public CompareResult compare(Object left, Object right) { tryClear(); List<Path> paths = new ArrayList<Path>(0); try { dispatch(left, right, paths); } catch (Exception e) { addDifference(left, right, Difference.Type.COMPARE_ERR, paths); } return new CompareResult(left, right, differences); } IntegratedComparator(List<Comparator> comparators); void dispatch(Object left, Object right, List<Path> paths); @Override CompareResult compare(Object left, Object right); void addDifference(Object left, Object right, Difference.Type type, List<Path> paths); List<Path> declarePath(List<Path> paths, int index); List<Path> declarePath(List<Path> paths, String key);  }