@Test public void test_durationsMatched() { List<int[]> durations = Lists.newArrayList( new int[]{2*60, 7*60}, new int[]{9*60, 17*60}); RangerTimeOfDayMatcher matcher = new RangerTimeOfDayMatcher(); Object[][] input = new Object[][] { { 1, false }, { 2, true }, { 3, true }, { 7, true }, { 8, false }, {9, true }, {10, true }, {16, true}, {17, true}, {18, false }, {23, false }, }; for (Object[] data : input) { int hour = (int)data[0]; boolean matchExpected = (boolean)data[1]; boolean result = matcher.durationMatched(durations, hour, 0); if (matchExpected) { Assert.assertTrue("" + hour, result); } else { Assert.assertFalse("" + hour, result); } } }
boolean durationMatched(List<int[]> durations, int hourOfDay, int minutes) { for (int[] aDuration : durations) { int start = aDuration[0]; int end = aDuration[1]; int minutesOfDay = hourOfDay*60 + minutes; if(start < end) { if (start <= minutesOfDay && minutesOfDay <= end) { return true; } } else { if(start <= minutesOfDay || minutesOfDay <= end) { return true; } } } return false; }
RangerTimeOfDayMatcher extends RangerAbstractConditionEvaluator { boolean durationMatched(List<int[]> durations, int hourOfDay, int minutes) { for (int[] aDuration : durations) { int start = aDuration[0]; int end = aDuration[1]; int minutesOfDay = hourOfDay*60 + minutes; if(start < end) { if (start <= minutesOfDay && minutesOfDay <= end) { return true; } } else { if(start <= minutesOfDay || minutesOfDay <= end) { return true; } } } return false; } }
RangerTimeOfDayMatcher extends RangerAbstractConditionEvaluator { boolean durationMatched(List<int[]> durations, int hourOfDay, int minutes) { for (int[] aDuration : durations) { int start = aDuration[0]; int end = aDuration[1]; int minutesOfDay = hourOfDay*60 + minutes; if(start < end) { if (start <= minutesOfDay && minutesOfDay <= end) { return true; } } else { if(start <= minutesOfDay || minutesOfDay <= end) { return true; } } } return false; }  }
RangerTimeOfDayMatcher extends RangerAbstractConditionEvaluator { boolean durationMatched(List<int[]> durations, int hourOfDay, int minutes) { for (int[] aDuration : durations) { int start = aDuration[0]; int end = aDuration[1]; int minutesOfDay = hourOfDay*60 + minutes; if(start < end) { if (start <= minutesOfDay && minutesOfDay <= end) { return true; } } else { if(start <= minutesOfDay || minutesOfDay <= end) { return true; } } } return false; }  @Override void init(); @Override boolean isMatched(RangerAccessRequest request); @Override String toString(); }
RangerTimeOfDayMatcher extends RangerAbstractConditionEvaluator { boolean durationMatched(List<int[]> durations, int hourOfDay, int minutes) { for (int[] aDuration : durations) { int start = aDuration[0]; int end = aDuration[1]; int minutesOfDay = hourOfDay*60 + minutes; if(start < end) { if (start <= minutesOfDay && minutesOfDay <= end) { return true; } } else { if(start <= minutesOfDay || minutesOfDay <= end) { return true; } } } return false; }  @Override void init(); @Override boolean isMatched(RangerAccessRequest request); @Override String toString();  }