JSONExtractor { Predicate<String> filterFileLogBtwDate(String startDate, String endDate) { return (String aLong) -> { Matcher matcher = groupMatchers(aLong); if (!matcher.find()) { return false; } String startDateFrmFileName = matcher.group(1); String endDateFrmFileName = matcher.group(3); LocalDate end = LocalDate.parse(endDateFrmFileName); LocalDate start = LocalDate.parse(startDateFrmFileName); LocalDate instantStartDT; LocalDate instantStartET; instantStartDT = getFirstDayOfMonth(startDate); instantStartET = getLastDayOfMonth(endDate); boolean startRange = (instantStartDT.isBefore(start) || instantStartDT.equals(start)) && (instantStartET.isAfter(start) || instantStartET.equals(start)); boolean endRange = (instantStartDT.isBefore(end) || instantStartDT.equals(end)) && (instantStartET.isAfter(end) || instantStartDT.equals(end)); return startRange || endRange; }; }  List<UsageStatistic> loadStatisticOf(String date); Map<String, List<UsageStatistic>> getAllUserUsageStatistic(String date); List<UsageStatistic> getUsageStatisticsSince(String startDate); Map<String, List<UsageStatistic>> getAllUserUsageBetween(String startDate, String endDate); Map<String, List<UsageStatistic>> getAllDateUsageBetween(String startDate, String endDate); Map<String, List<UsageStatistic>> getAllQueueUsageBetween(String startDate, String endDate); UsageStatistic getSingleStatistic(String jobId, String date); List<UsageStatistic> getSingleUserStatistic(String userName, String date); List<UsageStatistic> getSingleUserUsageBetween(String user, String startDate, String endDate); List<UsageStatistic> getSingleUserUsageInYear(String user, String year); List<UsageStatistic> getSingleUserUsageInYearMonth(String user, String year, String month); List<UsageStatistic> getSingleUserUsageYearMonthDay(String user, String year, String month,
                                                               String day);  }
@Test public void testSingleDateTimePredicate() { Predicate<String> stringPredicate = jsonExtractor.filterFileLogBtwDate("2016-12-20"); assertTrue(stringPredicate.test("2016-12-01_To_2016-12-31.json")); assertTrue(stringPredicate.test("2016-12-10_To_2016-12-31.json")); assertFalse(stringPredicate.test("2017-12-10_To_2016-12-31.json")); }
@Test public void testBetweenDateTimePredicate() { List<String> fileName = Arrays.asList( "calvalus-reporting-2014-12-01_to_2014-12-31.json", "calvalus-reporting-2015-03-01_To_2015-01-31.json", "calvalus-reporting-2016-11-01_To_2016-11-30.json", "calvalus-reporting-2016-03-01_To_2016-03-31.json", "calvalus-reporting-2017-09-01_To_2017-12-31.json", "calvalus-reporting-2016-12-01_To_2016-12-31.json", "calvalus-reporting-2018-06-01_To_2018-06-30.json", "calvalus-reporting-2019-07-01_To_2019-07-31.json", "calvalus-reporting-2022-12-01_To_2022-12-31.json"); Predicate<String> stringPredicate = jsonExtractor.filterFileLogBtwDate("2016-12-02", "2016-12-12"); List<String> collectFileBtwn = fileName.stream().filter(stringPredicate).collect(Collectors.toList()); Assert.assertThat(collectFileBtwn.size(), is(1)); Predicate<String> stringPredicateRange = jsonExtractor.filterFileLogBtwDate("2016-12-20", "2022-12-12"); List<String> collectBtwn = fileName.stream().filter(stringPredicateRange).collect(Collectors.toList()); Assert.assertThat(collectBtwn.size(), is(5)); }