NameMatchUtil { public static boolean nameMatch(String regex, String name) { if (regex == null || regex.length() == 0 || name == null || name.length() == 0) return false; do { int i = regex.indexOf('|'); if (i < 0) return doSingleNameMatch(regex, name); if (doSingleNameMatch(regex.substring(0, i), name)) return true; regex = regex.substring(i + 1); } while (true); }  static boolean nameMatch(String regex, String name);  }
@Test public void nameMatchUtilTest() { Assert.assertTrue(nameMatch("abc*", "abcx")); Assert.assertTrue(nameMatch("ghi*jkl", "ghixxjkl")); Assert.assertTrue(nameMatch("*mn", "xmn")); Assert.assertTrue(nameMatch("abc*|def*|ghi*jkl|*mn", "abcd")); Assert.assertTrue(nameMatch("abc*|def*|ghi*jkl|*mn", "def")); Assert.assertTrue(nameMatch("abc*|def*|ghi*jkl|*mn", "ghixxjkl")); Assert.assertTrue(nameMatch("abc*|def*|ghi*jkl|*mn", "ghixxjkl")); Assert.assertTrue(nameMatch("abc*|def*|ghi*jkl|*mn", "mn")); Assert.assertFalse(nameMatch("abc*|def*|ghi*jkl|*mn", "abd")); Assert.assertFalse(nameMatch("abc*|def*|ghi*jkl|*mn", "de")); Assert.assertFalse(nameMatch("abc*|def*|ghi*jkl|*mn", "ghxxkl")); Assert.assertFalse(nameMatch("abc*|def*|ghi*jkl|*mn", "n")); }