Range { public boolean isInRange(Object obj) { if (getStart() != null) { if (isInclusiveStart()) { if (ObjectUtils.compare(getStart(), obj) > 0) { return false; } } else { if (ObjectUtils.compare(getStart(), obj) >= 0) { return false; } } } if (getEnd() != null) { if (isInclusiveEnd()) { if (ObjectUtils.compare(obj, getEnd()) > 0) { return false; } } else { if (ObjectUtils.compare(obj, getEnd()) >= 0) { return false; } } } return true; } Range(T start, boolean inclusiveStart, T end, boolean inclusiveEnd); T getStart(); boolean isInclusiveStart(); T getEnd(); boolean isInclusiveEnd(); boolean isInRange(Object obj); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testIsInRange() throws Exception { IdRange range = new IdRange("b", "c"); assertTrue(range.isInRange("b")); assertTrue(range.isInRange("ba")); assertFalse(range.isInRange("c")); range = new IdRange(null, "c"); assertTrue(range.isInRange("b")); assertFalse(range.isInRange("c")); range = new IdRange("b", null); assertFalse(range.isInRange("az")); assertTrue(range.isInRange("b")); range = new IdRange("b", true, "c", true); assertTrue(range.isInRange("b")); assertTrue(range.isInRange("ba")); assertTrue(range.isInRange("c")); range = new IdRange("b", false, "c", false); assertFalse(range.isInRange("b")); assertTrue(range.isInRange("ba")); assertFalse(range.isInRange("c")); range = new IdRange("b", true, "c", false); assertTrue(range.isInRange("b")); assertTrue(range.isInRange("ba")); assertFalse(range.isInRange("c")); range = new IdRange("b", false, "c", true); assertFalse(range.isInRange("b")); assertTrue(range.isInRange("ba")); assertTrue(range.isInRange("c")); }