Skip to content

Commit

Permalink
add method to get snapshot urgently
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed May 4, 2024
1 parent 6d89ad1 commit 1d83b6a
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,8 @@ public SnapshotAgent(DataHolder<T> holder) {
@Override
protected Runnable getRunnable() {
return () -> {
Stream<DataSnapshot<T>> stream = holder.getEntryMap().entrySet().stream()
.map(entry -> new DataSnapshot<>(entry.getKey(), entry.getValue().getValue()))
.filter(snapshot -> filters.stream().allMatch(filter -> filter.test(snapshot)));
if (comparator != null) {
stream = stream.sorted(Comparator.<DataSnapshot<T>, T>comparing(snapshot -> snapshot.value, comparator).reversed());
}
List<DataSnapshot<T>> list = stream.collect(Collectors.toList());
topSnapshot.set(list);
List<DataSnapshot<T>> list = getUrgentSnapshot();
topSnapshot.set(getUrgentSnapshot());

Map<UUID, Integer> map = IntStream.range(0, list.size())
.boxed()
Expand All @@ -48,6 +42,16 @@ public void stop() {
indexMap.set(Collections.emptyMap());
}

public List<DataSnapshot<T>> getUrgentSnapshot() {
Stream<DataSnapshot<T>> stream = holder.getEntryMap().entrySet().stream()
.map(entry -> new DataSnapshot<>(entry.getKey(), entry.getValue().getValue()))
.filter(snapshot -> filters.stream().allMatch(filter -> filter.test(snapshot)));
if (comparator != null) {
stream = stream.sorted(Comparator.<DataSnapshot<T>, T>comparing(snapshot -> snapshot.value, comparator).reversed());
}
return stream.collect(Collectors.toList());
}

public List<DataSnapshot<T>> getSnapshot() {
return topSnapshot.get();
}
Expand Down

0 comments on commit 1d83b6a

Please sign in to comment.