@Test public void testSortBySeverity() { Message e1 = Message.newError("e1", "E1"); Message e2 = Message.newError("e2", "E2"); Message e3 = Message.newError("e3", "E3"); Message w1 = Message.newWarning("w1", "W1"); Message w2 = Message.newWarning("w2", "W2"); Message i1 = Message.newInfo("i1", "I1"); Message i2 = Message.newInfo("i2", "I2"); MessageList unsortedMessageList = new MessageList(i2, e1, w1, e3, i1, e2, w2); MessageList sortedMessageList = new MessageList(e1, e3, e2, w1, w2, i2, i1); MessageList actualMessageList = unsortedMessageList.sortBySeverity(); assertThat(actualMessageList, is(equalTo(sortedMessageList))); }
public MessageList sortBySeverity() { return messages.stream() .sorted(Comparator.comparing(Message::getSeverity).reversed()) .collect(collector()); }
MessageList implements Serializable, Iterable<Message> { public MessageList sortBySeverity() { return messages.stream() .sorted(Comparator.comparing(Message::getSeverity).reversed()) .collect(collector()); } }
MessageList implements Serializable, Iterable<Message> { public MessageList sortBySeverity() { return messages.stream() .sorted(Comparator.comparing(Message::getSeverity).reversed()) .collect(collector()); } MessageList(@NonNull Message... messages); }
MessageList implements Serializable, Iterable<Message> { public MessageList sortBySeverity() { return messages.stream() .sorted(Comparator.comparing(Message::getSeverity).reversed()) .collect(collector()); } MessageList(@NonNull Message... messages); void add(Message message); void add(@CheckForNull MessageList messageList); boolean isEmpty(); int size(); Message getMessage(int index); Optional<Message> getFirstMessage(Severity errorLevel); Optional<Message> getMessageByCode(@CheckForNull String code); MessageList getMessagesByCode(@CheckForNull String code); Optional<Severity> getSeverity(); String getText(); boolean containsErrorMsg(); MessageList getMessagesFor(Object object); MessageList getMessagesFor(Object object, @CheckForNull String property); MessageList getMessagesFor(Object object, @CheckForNull String property, int index); MessageList getMessagesByMarker(@CheckForNull ValidationMarker marker); MessageList getMessagesByMarker(Predicate<ValidationMarker> markerPredicate); MessageList sortBySeverity(); Optional<Message> getMessageWithHighestSeverity(); @Override Iterator<Message> iterator(); void clear(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); Stream<Message> stream(); static Collector<Message, ?, MessageList> collector(); }
MessageList implements Serializable, Iterable<Message> { public MessageList sortBySeverity() { return messages.stream() .sorted(Comparator.comparing(Message::getSeverity).reversed()) .collect(collector()); } MessageList(@NonNull Message... messages); void add(Message message); void add(@CheckForNull MessageList messageList); boolean isEmpty(); int size(); Message getMessage(int index); Optional<Message> getFirstMessage(Severity errorLevel); Optional<Message> getMessageByCode(@CheckForNull String code); MessageList getMessagesByCode(@CheckForNull String code); Optional<Severity> getSeverity(); String getText(); boolean containsErrorMsg(); MessageList getMessagesFor(Object object); MessageList getMessagesFor(Object object, @CheckForNull String property); MessageList getMessagesFor(Object object, @CheckForNull String property, int index); MessageList getMessagesByMarker(@CheckForNull ValidationMarker marker); MessageList getMessagesByMarker(Predicate<ValidationMarker> markerPredicate); MessageList sortBySeverity(); Optional<Message> getMessageWithHighestSeverity(); @Override Iterator<Message> iterator(); void clear(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); Stream<Message> stream(); static Collector<Message, ?, MessageList> collector();  }