Strings { public static String trimLeadingSegments(String string, char separator, int segmentCount) { if (string == null) { return null; } List<String> segments = ImmutableList.copyOf(Splitter.on(separator).split(string)); if (segments.isEmpty() || !segments.get(0).isEmpty()) { throw new IllegalArgumentException("String must start with the separator character"); } segments = segments.subList(1, segments.size()); if (segments.size() < segmentCount) { return string; } String trimmedString = Joiner.on(separator).join(segments.subList(segmentCount, segments.size())); if (!trimmedString.startsWith("" + separator)) { trimmedString = separator + trimmedString; } return trimmedString; }  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 testTrim() { assertEquals(trimLeadingSegments("/a/b/c", '/', 0), "/a/b/c"); assertEquals(trimLeadingSegments("/a/b/c", '/', 1), "/b/c"); assertEquals(trimLeadingSegments("/a/b/c", '/', 2), "/c"); }