List of usage examples for java.util.concurrent ConcurrentSkipListSet tailSet
public NavigableSet<E> tailSet(E fromElement, boolean inclusive)
From source file:com.enitalk.configs.DateCache.java
public NavigableSet<DateTime> days(JsonNode tree, String tz, JsonNode teacherNode) { ConcurrentSkipListSet<DateTime> dates = new ConcurrentSkipListSet<>(); Iterator<JsonNode> els = tree.elements(); DateTimeZone dz = DateTimeZone.forID(tz); DateTimeFormatter hour = DateTimeFormat.forPattern("HH:mm").withZone(dz); DateTime today = DateTime.now().millisOfDay().setCopy(0); while (els.hasNext()) { JsonNode el = els.next();// www. j ava2s . c om String day = el.path("day").asText(); boolean plus = today.getDayOfWeek() > days.get(day); if (el.has("start") && el.has("end")) { DateTime start = hour.parseDateTime(el.path("start").asText()).dayOfMonth() .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year() .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0); DateTime end = hour.parseDateTime(el.path("end").asText()).dayOfMonth() .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year() .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0); Hours hours = Hours.hoursBetween(start, end); int hh = hours.getHours() + 1; while (hh-- > 0) { dates.add(start.plusHours(hh).toDateTime(DateTimeZone.UTC)); } } else { List<String> datesAv = jackson.convertValue(el.path("times"), List.class); logger.info("Array of dates {} {}", datesAv, day); datesAv.forEach((String dd) -> { DateTime date = hour.parseDateTime(dd).dayOfMonth().setCopy(today.getDayOfMonth()).monthOfYear() .setCopy(today.getMonthOfYear()).year().setCopy(today.getYear()) .withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0); dates.add(date.toDateTime(DateTimeZone.UTC)); }); } } final TreeSet<DateTime> addWeek = new TreeSet<>(); for (int i = 1; i < 2; i++) { for (DateTime e : dates) { addWeek.add(e.plusWeeks(i)); } } dates.addAll(addWeek); DateTime nowUtc = DateTime.now().toDateTime(DateTimeZone.UTC); nowUtc = nowUtc.plusHours(teacherNode.path("notice").asInt(2)); NavigableSet<DateTime> ss = dates.tailSet(nowUtc, true); return ss; }