@Test public void testCompareTo() { List<Warning> warnings = ImmutableList.of(new Warning("a", null), new Warning("a", "a"), new Warning("a", "b")); assertThat( Lists.reverse(warnings).stream().sorted().collect(Collectors.toList()), equalTo(warnings)); }
@Override public int compareTo(Warning o) { return Comparator.comparing(Warning::getText) .thenComparing(Warning::getTag, Comparator.nullsFirst(String::compareTo)) .compare(this, o); }
Warning implements Serializable, Comparable<Warning> { @Override public int compareTo(Warning o) { return Comparator.comparing(Warning::getText) .thenComparing(Warning::getTag, Comparator.nullsFirst(String::compareTo)) .compare(this, o); } }
Warning implements Serializable, Comparable<Warning> { @Override public int compareTo(Warning o) { return Comparator.comparing(Warning::getText) .thenComparing(Warning::getTag, Comparator.nullsFirst(String::compareTo)) .compare(this, o); } Warning(String text, @Nullable String tag); }
Warning implements Serializable, Comparable<Warning> { @Override public int compareTo(Warning o) { return Comparator.comparing(Warning::getText) .thenComparing(Warning::getTag, Comparator.nullsFirst(String::compareTo)) .compare(this, o); } Warning(String text, @Nullable String tag); @JsonProperty(PROP_TAG) @Nullable String getTag(); @JsonProperty(PROP_TEXT) @Nonnull String getText(); @Override int compareTo(Warning o); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override String toString(); }
Warning implements Serializable, Comparable<Warning> { @Override public int compareTo(Warning o) { return Comparator.comparing(Warning::getText) .thenComparing(Warning::getTag, Comparator.nullsFirst(String::compareTo)) .compare(this, o); } Warning(String text, @Nullable String tag); @JsonProperty(PROP_TAG) @Nullable String getTag(); @JsonProperty(PROP_TEXT) @Nonnull String getText(); @Override int compareTo(Warning o); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override String toString();  }