Bael 850 (#1744)
* 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:
parent
2bebf73db2
commit
ac8700ff65
|
@ -4,17 +4,10 @@ import java.time.ZonedDateTime;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.concurrent.ConcurrentNavigableMap;
|
import java.util.concurrent.ConcurrentNavigableMap;
|
||||||
import java.util.concurrent.ConcurrentSkipListMap;
|
import java.util.concurrent.ConcurrentSkipListMap;
|
||||||
import java.util.function.ToLongFunction;
|
|
||||||
|
|
||||||
public class EventWindowSort {
|
public class EventWindowSort {
|
||||||
private final ConcurrentSkipListMap<ZonedDateTime, String> events = new ConcurrentSkipListMap<>(Comparator.comparingLong(new ToLongFunction<ZonedDateTime>() {
|
private final ConcurrentSkipListMap<ZonedDateTime, String> events
|
||||||
@Override
|
= new ConcurrentSkipListMap<>(Comparator.comparingLong(value -> value.toInstant().toEpochMilli()));
|
||||||
public long applyAsLong(ZonedDateTime value) {
|
|
||||||
return value
|
|
||||||
.toInstant()
|
|
||||||
.toEpochMilli();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
public void acceptEvent(Event event) {
|
public void acceptEvent(Event event) {
|
||||||
events.put(event.getEventTime(), event.getContent());
|
events.put(event.getEventTime(), event.getContent());
|
||||||
|
@ -22,14 +15,14 @@ public class EventWindowSort {
|
||||||
|
|
||||||
public ConcurrentNavigableMap<ZonedDateTime, String> getEventsFromLastMinute() {
|
public ConcurrentNavigableMap<ZonedDateTime, String> getEventsFromLastMinute() {
|
||||||
return events.tailMap(ZonedDateTime
|
return events.tailMap(ZonedDateTime
|
||||||
.now()
|
.now()
|
||||||
.minusMinutes(1));
|
.minusMinutes(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConcurrentNavigableMap<ZonedDateTime, String> getEventsOlderThatOneMinute() {
|
public ConcurrentNavigableMap<ZonedDateTime, String> getEventsOlderThatOneMinute() {
|
||||||
return events.headMap(ZonedDateTime
|
return events.headMap(ZonedDateTime
|
||||||
.now()
|
.now()
|
||||||
.minusMinutes(1));
|
.minusMinutes(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue