1 package de.juplo.kafka.chatroom.domain;
4 import lombok.RequiredArgsConstructor;
6 import java.time.LocalDateTime;
7 import java.util.LinkedList;
10 import java.util.stream.Stream;
13 @RequiredArgsConstructor
17 private final UUID id;
19 private final String name;
20 private final List<Message> messages = new LinkedList<>();
22 synchronized public Message addMessage(
24 LocalDateTime timestamp,
28 Message message = new Message(id, (long)messages.size(), timestamp, user, text);
29 messages.add(message);
33 public Stream<Message> getMessages(long firstMessage)
35 return messages.stream().filter(message -> message.getSerialNumber() >= firstMessage);