* BAEL-850 ConcurentskipLIst

* BAEL-850 formatting

* BAEL-850 Formatting

* spring 5 work

* SetTest refactor (#1724)

* BAEL-850 use lambda

* BAEL-850 no need to casting
This commit is contained in:
Tomasz Lelek 2017-04-27 19:35:22 +02:00 committed by Grzegorz Piwowarek
parent 2bebf73db2
commit ac8700ff65
1 changed files with 6 additions and 13 deletions

View File

@ -4,17 +4,10 @@ import java.time.ZonedDateTime;
import java.util.Comparator;
import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.function.ToLongFunction;
public class EventWindowSort {
private final ConcurrentSkipListMap<ZonedDateTime, String> events = new ConcurrentSkipListMap<>(Comparator.comparingLong(new ToLongFunction<ZonedDateTime>() {
@Override
public long applyAsLong(ZonedDateTime value) {
return value
.toInstant()
.toEpochMilli();
}
}));
private final ConcurrentSkipListMap<ZonedDateTime, String> events
= new ConcurrentSkipListMap<>(Comparator.comparingLong(value -> value.toInstant().toEpochMilli()));
public void acceptEvent(Event event) {
events.put(event.getEventTime(), event.getContent());
@ -22,14 +15,14 @@ public class EventWindowSort {
public ConcurrentNavigableMap<ZonedDateTime, String> getEventsFromLastMinute() {
return events.tailMap(ZonedDateTime
.now()
.minusMinutes(1));
.now()
.minusMinutes(1));
}
public ConcurrentNavigableMap<ZonedDateTime, String> getEventsOlderThatOneMinute() {
return events.headMap(ZonedDateTime
.now()
.minusMinutes(1));
.now()
.minusMinutes(1));
}
}