Skip to content

Commit

Permalink
Filtering duplicate messages
Browse files Browse the repository at this point in the history
Signed-off-by: Sönke Küper <soenkekueper@gmx.de>
  • Loading branch information
soenkekueper committed Oct 14, 2021
1 parent bfca390 commit b97ca2a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ private static StringType mapMessages(final @Nullable List<Message> messages) {
final String messageTexts = messages //
.stream()//
.filter((Message message) -> message.getC() != null) //
.map((Message message) -> MessageCodes.getMessage(message.getC())) //
.map(Message::getC) //
.distinct() //
.map(MessageCodes::getMessage) //
.filter((String messageText) -> !messageText.isEmpty()) //
.collect(Collectors.joining(" - "));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,28 @@ public void testMessages() {
doTestEventAttribute("messages", null, (Event e) -> e.getM().addAll(messages), messages,
new StringType(expectedTwoMessages), EventType.DEPARTURE, true);
}

@Test
public void testFilterDuplicateMessages() {
String expectedOneMessage = "andere Reihenfolge der Wagen - technische Störung am Zug - Zug verkehrt richtig gereiht";
List<Message> messages = new ArrayList<>();
Message m1 = new Message();
m1.setC(80);
messages.add(m1);
Message m2 = new Message();
m2.setC(80);
messages.add(m2);
Message m3 = new Message();
m3.setC(36);
messages.add(m3);
Message m4 = new Message();
m4.setC(80);
messages.add(m4);
Message m5 = new Message();
m5.setC(84);
messages.add(m5);

doTestEventAttribute("messages", null, (Event e) -> e.getM().addAll(messages), messages,
new StringType(expectedOneMessage), EventType.DEPARTURE, true);
}
}

0 comments on commit b97ca2a

Please sign in to comment.