-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: bartlomiej.zylinski <[email protected]>
- Loading branch information
Showing
15 changed files
with
969 additions
and
212 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package otter.jet.store; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import otter.jet.reader.ReadMessage; | ||
|
||
import java.util.ArrayDeque; | ||
import java.util.Deque; | ||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
public class DefaultMessageStore implements MessageStore { | ||
|
||
private final Deque<ReadMessage> messages = new ArrayDeque<>(); | ||
private final int limit; | ||
|
||
public DefaultMessageStore(@Value("${read.store.limit:1000}") int limit) { | ||
this.limit = limit; | ||
} | ||
|
||
public void add(ReadMessage message) { | ||
if (messages.size() >= limit) { | ||
messages.removeLast(); | ||
} | ||
messages.addFirst(message); | ||
} | ||
|
||
public List<ReadMessage> filter(Filters filters, int page, int size) { | ||
return filter(filters.toPredicate(), page, size); | ||
} | ||
|
||
private List<ReadMessage> filter(Predicate<ReadMessage> predicate, int page, int size) { | ||
return messages.stream() | ||
.filter(predicate) | ||
.skip((long) page * size) | ||
.limit(size) | ||
.toList(); | ||
} | ||
|
||
|
||
|
||
} |
Oops, something went wrong.