Skip to content

Commit ac8700f

Browse files
tomekl007pivovarit
authored andcommitted
Bael 850 (eugenp#1744)
* BAEL-850 ConcurentskipLIst * BAEL-850 formatting * BAEL-850 Formatting * spring 5 work * SetTest refactor (eugenp#1724) * BAEL-850 use lambda * BAEL-850 no need to casting
1 parent 2bebf73 commit ac8700f

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

‎core-java/src/main/java/com/baeldung/concurrent/skiplist/EventWindowSort.java‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,25 @@
44
import java.util.Comparator;
55
import java.util.concurrent.ConcurrentNavigableMap;
66
import java.util.concurrent.ConcurrentSkipListMap;
7-
import java.util.function.ToLongFunction;
87

98
public class EventWindowSort {
10-
private final ConcurrentSkipListMap<ZonedDateTime, String> events = new ConcurrentSkipListMap<>(Comparator.comparingLong(new ToLongFunction<ZonedDateTime>() {
11-
@Override
12-
public long applyAsLong(ZonedDateTime value) {
13-
return value
14-
.toInstant()
15-
.toEpochMilli();
16-
}
17-
}));
9+
private final ConcurrentSkipListMap<ZonedDateTime, String> events
10+
= new ConcurrentSkipListMap<>(Comparator.comparingLong(value -> value.toInstant().toEpochMilli()));
1811

1912
public void acceptEvent(Event event) {
2013
events.put(event.getEventTime(), event.getContent());
2114
}
2215

2316
public ConcurrentNavigableMap<ZonedDateTime, String> getEventsFromLastMinute() {
2417
return events.tailMap(ZonedDateTime
25-
.now()
26-
.minusMinutes(1));
18+
.now()
19+
.minusMinutes(1));
2720
}
2821

2922
public ConcurrentNavigableMap<ZonedDateTime, String> getEventsOlderThatOneMinute() {
3023
return events.headMap(ZonedDateTime
31-
.now()
32-
.minusMinutes(1));
24+
.now()
25+
.minusMinutes(1));
3326
}
3427

3528
}

0 commit comments

Comments
 (0)