RADateRanges { public int findIndex(long time) { for (int i = 0; i < dateRanges.length; i++) { long[] dateRange = dateRanges[i]; if (time >= dateRange[0] && time < dateRange[1]) { return i; } } return -1; } private  RADateRanges(long[][] dateRanges); static RADateRanges create(String dateRangesString); int findIndex(long time); String format(long time); String formatStart(int index); String formatEnd(int index); static final DateFormat dateFormat; }
@Test public void testfindIndex() throws Exception { RADateRanges dateRanges = RADateRanges.create("2010-01-01:2010-01-10,2010-01-11:2010-01-20"); long a = 1263168000000L; assertEquals(0, dateRanges.findIndex(a - 2)); assertEquals(0, dateRanges.findIndex(a - 1)); assertEquals(1, dateRanges.findIndex(a)); assertEquals(1, dateRanges.findIndex(a + 1)); assertEquals(1, dateRanges.findIndex(a + 2)); }