コード例 #1
0
  @Test
  public void builds_comparator_from_unary_function() throws Exception {
    final List<String> strings = asList("CCC", "A", "BB");
    strings.sort(Comparators.from(String::length));

    assertThat(strings, is(asList("A", "BB", "CCC")));
  }
コード例 #2
0
  @Test
  public void builds_comparator_from_binary_function() throws Exception {
    final List<oo<String, Integer>> stringsWithLengths =
        asList(oo("CCC", 3), oo("A", 1), oo("BB", 2));

    stringsWithLengths.sort(Comparators.from((String string, Integer length) -> length));

    assertThat(stringsWithLengths, is(asList(oo("A", 1), oo("BB", 2), oo("CCC", 3))));
  }