StringUtil extends com.liferay.gradle.util.StringUtil { public static String getCommonPrefix(char separator, String... strings) { String firstString = strings[0]; int index = 0; boolean match = true; while (match) { int nextIndex = firstString.indexOf(separator, index + 1); if (nextIndex == -1) { break; } for (int i = 1; i < strings.length; i++) { if (!firstString.regionMatches( index, strings[i], index, nextIndex - index + 1)) { match = false; break; } } if (match) { index = nextIndex; } } if (index == 0) { return null; } return firstString.substring(0, index); }  static String getCommonPrefix(char separator, String... strings);  }
@Test public void testGetCommonPrefix() { Assert.assertEquals( "/home/user1/tmp", StringUtil.getCommonPrefix( '/', "/home/user1/tmp/coverage/test", "/home/user1/tmp/covert/operator", "/home/user1/tmp/coven/members")); Assert.assertNull( StringUtil.getCommonPrefix('/', "/dir1/tmp", "/dir2/tmp")); }
@Test public void testGetCommonPrefixWindows() { Assert.assertEquals( "C:/home/user1/tmp", StringUtil.getCommonPrefix( '/', "C:/home/user1/tmp/coverage/test", "C:/home/user1/tmp/covert/operator", "C:/home/user1/tmp/coven/members")); Assert.assertNull( StringUtil.getCommonPrefix('/', "C:/dir1/tmp", "D:/dir2/tmp")); }