Strings { public static int commonPrefixSegments(char separator, Collection<String> strings) { return commonPrefixSegments(separator, strings, 0); }  static int commonPrefixSegments(char separator, Collection<String> strings); static int commonPrefixSegments(char separator, Collection<String> strings, int minSize); static String trimLeadingSegments(String string, char separator, int segmentCount); static int shortestUniquePrefix(Collection<String> strings); static int shortestUniquePrefix(Collection<String> strings, int minSize); static String safeTruncate(String string, int length);  }
@Test public void testCommonSegment() { assertEquals(commonPrefixSegments('/', ImmutableList.<String>of()), 0); assertEquals(commonPrefixSegments('/', of("/")), 1); assertEquals(commonPrefixSegments('/', of("/a")), 1); assertEquals(commonPrefixSegments('/', of("/a", "/a")), 1); assertEquals(commonPrefixSegments('/', of("/a/a/a", "/a/a/a")), 3); assertEquals(commonPrefixSegments('/', of("/a/a/a", "/a/a/b")), 2); assertEquals(commonPrefixSegments('/', of("/a/a/a", "/a/a/a", "/a/a/b")), 2); }
@Test public void testCommonSegmentWithMin() { assertEquals(commonPrefixSegments('/', ImmutableList.<String>of(), 2), 0); assertEquals(commonPrefixSegments('/', of("/"), 0), 1); assertEquals(commonPrefixSegments('/', of("/"), 1), 0); assertEquals(commonPrefixSegments('/', of("/"), 2), 0); assertEquals(commonPrefixSegments('/', of("/a"), 0), 1); assertEquals(commonPrefixSegments('/', of("/a"), 1), 0); assertEquals(commonPrefixSegments('/', of("/a"), 2), 0); assertEquals(commonPrefixSegments('/', of("/a", "/a"), 0), 1); assertEquals(commonPrefixSegments('/', of("/a", "/a"), 1), 0); assertEquals(commonPrefixSegments('/', of("/a", "/a"), 2), 0); assertEquals(commonPrefixSegments('/', of("/a/a/a", "/a/a/a"), 0), 3); assertEquals(commonPrefixSegments('/', of("/a/a/a", "/a/a/a"), 1), 2); assertEquals(commonPrefixSegments('/', of("/a/a/a", "/a/a/a"), 2), 1); assertEquals(commonPrefixSegments('/', of("/a/a/a", "/a/a/a"), 3), 0); assertEquals(commonPrefixSegments('/', of("/a/a/a", "/a/a/a"), 4), 0); assertEquals(commonPrefixSegments('/', of("/a/a/a", "/a/a/b"), 0), 2); assertEquals(commonPrefixSegments('/', of("/a/a/a", "/a/a/b"), 1), 2); assertEquals(commonPrefixSegments('/', of("/a/a/a", "/a/a/b"), 2), 1); assertEquals(commonPrefixSegments('/', of("/a/a/a", "/a/a/b"), 3), 0); assertEquals(commonPrefixSegments('/', of("/a/a/a", "/a/a/b"), 4), 0); assertEquals(commonPrefixSegments('/', of("/a/a/a", "/a/a/a", "/a/a/b"), 0), 2); assertEquals(commonPrefixSegments('/', of("/a/a/a", "/a/a/a", "/a/a/b"), 1), 2); assertEquals(commonPrefixSegments('/', of("/a/a/a", "/a/a/a", "/a/a/b"), 2), 1); assertEquals(commonPrefixSegments('/', of("/a/a/a", "/a/a/a", "/a/a/b"), 3), 0); assertEquals(commonPrefixSegments('/', of("/a/a/a", "/a/a/a", "/a/a/b"), 4), 0); }