@Test public void testComparator() { List<CrossVrfEdgeId> ordered = ImmutableList.of( new CrossVrfEdgeId("a", "a"), new CrossVrfEdgeId("a", "b"), new CrossVrfEdgeId("a", "c"), new CrossVrfEdgeId("b", "a")); for (int i = 0; i < ordered.size(); i++) { for (int j = 0; j < ordered.size(); j++) { assertThat( Integer.signum(ordered.get(i).compareTo(ordered.get(j))), equalTo(Integer.signum(i - j))); } } }
@Override public int compareTo(CrossVrfEdgeId o) { return Comparator.comparing(CrossVrfEdgeId::getFromVrf) .thenComparing(CrossVrfEdgeId::getToRib) .compare(this, o); }
CrossVrfEdgeId implements Comparable<CrossVrfEdgeId> { @Override public int compareTo(CrossVrfEdgeId o) { return Comparator.comparing(CrossVrfEdgeId::getFromVrf) .thenComparing(CrossVrfEdgeId::getToRib) .compare(this, o); } }
CrossVrfEdgeId implements Comparable<CrossVrfEdgeId> { @Override public int compareTo(CrossVrfEdgeId o) { return Comparator.comparing(CrossVrfEdgeId::getFromVrf) .thenComparing(CrossVrfEdgeId::getToRib) .compare(this, o); } CrossVrfEdgeId(String fromVrf, String toRib); }
CrossVrfEdgeId implements Comparable<CrossVrfEdgeId> { @Override public int compareTo(CrossVrfEdgeId o) { return Comparator.comparing(CrossVrfEdgeId::getFromVrf) .thenComparing(CrossVrfEdgeId::getToRib) .compare(this, o); } CrossVrfEdgeId(String fromVrf, String toRib); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override int compareTo(CrossVrfEdgeId o); @Override String toString(); }
CrossVrfEdgeId implements Comparable<CrossVrfEdgeId> { @Override public int compareTo(CrossVrfEdgeId o) { return Comparator.comparing(CrossVrfEdgeId::getFromVrf) .thenComparing(CrossVrfEdgeId::getToRib) .compare(this, o); } CrossVrfEdgeId(String fromVrf, String toRib); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override int compareTo(CrossVrfEdgeId o); @Override String toString();  }