@Test public void compare() throws Exception { assertEquals(Equality.UNKNOWN, new YearComparator("123", null).compare()); assertEquals(Equality.UNKNOWN, new YearComparator("123", "").compare()); assertEquals(Equality.UNKNOWN, new YearComparator("123", " ").compare()); assertEquals(Equality.UNKNOWN, new YearComparator(null, null).compare()); assertEquals(Equality.DIFFERENT, new YearComparator("neunzehn", "1887").compare()); assertEquals(Equality.DIFFERENT, new YearComparator("neunzehn", "3 plus").compare()); assertEquals(Equality.DIFFERENT, new YearComparator("123", "125").compare()); assertEquals(Equality.DIFFERENT, new YearComparator("2001", "1999").compare()); assertEquals(Equality.EQUAL, new YearComparator(" 1678", "1678 ").compare()); assertEquals(Equality.EQUAL, new YearComparator("2001", "2001").compare()); assertEquals(Equality.EQUAL, new YearComparator("2001", "2000").compare()); assertEquals(Equality.EQUAL, new YearComparator("2000", "1999").compare()); assertEquals(Equality.EQUAL, new YearComparator("189", "190").compare()); assertEquals(Equality.EQUAL, new YearComparator("1878", "187?").compare()); assertEquals(Equality.EQUAL, new YearComparator("1878", "1879?").compare()); assertEquals(Equality.EQUAL, new YearComparator("18?8", "1878").compare()); assertEquals(Equality.EQUAL, new YearComparator("187?", "187 ?").compare()); assertEquals(Equality.DIFFERENT, new YearComparator("18??", "1877").compare()); assertEquals(Equality.DIFFERENT, new YearComparator("18??", "18?").compare()); }
public Equality compare() { if (y1 != null && y2 != null) { if (y1.equals(y2)) { return Equality.EQUAL; } try { int yi1 = Integer.parseInt(y1); int yi2 = Integer.parseInt(y2); if (Math.abs(yi1 - yi2) <= 1) { return Equality.EQUAL; } } catch (NumberFormatException e) { if (replacePlaceholders() && y1.equals(y2)) { return Equality.EQUAL; } } return Equality.DIFFERENT; } return Equality.UNKNOWN; }
YearComparator { public Equality compare() { if (y1 != null && y2 != null) { if (y1.equals(y2)) { return Equality.EQUAL; } try { int yi1 = Integer.parseInt(y1); int yi2 = Integer.parseInt(y2); if (Math.abs(yi1 - yi2) <= 1) { return Equality.EQUAL; } } catch (NumberFormatException e) { if (replacePlaceholders() && y1.equals(y2)) { return Equality.EQUAL; } } return Equality.DIFFERENT; } return Equality.UNKNOWN; } }
YearComparator { public Equality compare() { if (y1 != null && y2 != null) { if (y1.equals(y2)) { return Equality.EQUAL; } try { int yi1 = Integer.parseInt(y1); int yi2 = Integer.parseInt(y2); if (Math.abs(yi1 - yi2) <= 1) { return Equality.EQUAL; } } catch (NumberFormatException e) { if (replacePlaceholders() && y1.equals(y2)) { return Equality.EQUAL; } } return Equality.DIFFERENT; } return Equality.UNKNOWN; } YearComparator(String y1, String y2); }
YearComparator { public Equality compare() { if (y1 != null && y2 != null) { if (y1.equals(y2)) { return Equality.EQUAL; } try { int yi1 = Integer.parseInt(y1); int yi2 = Integer.parseInt(y2); if (Math.abs(yi1 - yi2) <= 1) { return Equality.EQUAL; } } catch (NumberFormatException e) { if (replacePlaceholders() && y1.equals(y2)) { return Equality.EQUAL; } } return Equality.DIFFERENT; } return Equality.UNKNOWN; } YearComparator(String y1, String y2); Equality compare(); }
YearComparator { public Equality compare() { if (y1 != null && y2 != null) { if (y1.equals(y2)) { return Equality.EQUAL; } try { int yi1 = Integer.parseInt(y1); int yi2 = Integer.parseInt(y2); if (Math.abs(yi1 - yi2) <= 1) { return Equality.EQUAL; } } catch (NumberFormatException e) { if (replacePlaceholders() && y1.equals(y2)) { return Equality.EQUAL; } } return Equality.DIFFERENT; } return Equality.UNKNOWN; } YearComparator(String y1, String y2); Equality compare();  }