@Test public void testPredicate() { String pattern = "/test/*"; assertTrue(KvUtils.predicate(pattern, "/test")); assertFalse(KvUtils.predicate(pattern, "/testnotmatched")); assertFalse(KvUtils.predicate(pattern, "/testnotmatched/some")); assertFalse(KvUtils.predicate(pattern, "/testnotmatched/some/")); assertTrue(KvUtils.predicate(pattern, "/test/")); assertTrue(KvUtils.predicate(pattern, "/test/some")); assertTrue(KvUtils.predicate(pattern, "/test/some/another")); assertTrue(KvUtils.predicate(pattern, "/test/some/another")); }
public static boolean predicate(String pattern, String key) { int last = pattern.length(); final int keyLen = key.length(); if(pattern.charAt(last - 1) == '*') { last--; } if(keyLen == last - 1 && pattern.charAt(last - 1) == '/') { last--; } return key.regionMatches(0, pattern, 0, last); }
KvUtils { public static boolean predicate(String pattern, String key) { int last = pattern.length(); final int keyLen = key.length(); if(pattern.charAt(last - 1) == '*') { last--; } if(keyLen == last - 1 && pattern.charAt(last - 1) == '/') { last--; } return key.regionMatches(0, pattern, 0, last); } }
KvUtils { public static boolean predicate(String pattern, String key) { int last = pattern.length(); final int keyLen = key.length(); if(pattern.charAt(last - 1) == '*') { last--; } if(keyLen == last - 1 && pattern.charAt(last - 1) == '/') { last--; } return key.regionMatches(0, pattern, 0, last); }  }
KvUtils { public static boolean predicate(String pattern, String key) { int last = pattern.length(); final int keyLen = key.length(); if(pattern.charAt(last - 1) == '*') { last--; } if(keyLen == last - 1 && pattern.charAt(last - 1) == '/') { last--; } return key.regionMatches(0, pattern, 0, last); }  static boolean predicate(String pattern, String key); static String join(String ... components); static String suffix(String prefix, String path); static String name(String prefix, String path); static String child(String prefix, String path, int childNum); }
KvUtils { public static boolean predicate(String pattern, String key) { int last = pattern.length(); final int keyLen = key.length(); if(pattern.charAt(last - 1) == '*') { last--; } if(keyLen == last - 1 && pattern.charAt(last - 1) == '/') { last--; } return key.regionMatches(0, pattern, 0, last); }  static boolean predicate(String pattern, String key); static String join(String ... components); static String suffix(String prefix, String path); static String name(String prefix, String path); static String child(String prefix, String path, int childNum);  }