Updated to use Stream
import org.terasology.rendering.nui.widgets.UIText;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
/**
* The chat console widget
@@ -91,14 +93,9 @@ public void initialise() {
history.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
- StringBuilder messageList = new StringBuilder();
- for (Iterator<Message> it = console.getMessages(CoreMessageType.CHAT, CoreMessageType.NOTIFICATION).iterator(); it.hasNext();) {
- messageList.append(it.next().getMessage());
- if (it.hasNext()) {
- messageList.append(Console.NEW_LINE);
- }
- }
- return messageList.toString();
+ Iterable<Message> messageIterable = console.getMessages(CoreMessageType.CHAT, CoreMessageType.NOTIFICATION);
+ Stream<Message> messageStream = StreamSupport.stream(messageIterable.spliterator(), false);
+ return messageStream.map(Message::getMessage).collect(Collectors.joining(Console.NEW_LINE));
}
});
}
