/** returns comparator which compares based on length, with shorter ones first (and null before that); * in event of a tie, it uses the toString order */ public static Ordering<String> lengthComparator() { return Ordering.<Integer>natural().onResultOf(StringFunctions.length()).compound(Ordering.<String>natural()).nullsFirst(); }
@Test public static void testLength() { Assert.assertEquals(StringFunctions.length().apply("abc"), (Integer)3); }