1 16 17 package org.springframework.util; 18 19 26 public abstract class PatternMatchUtils { 27 28 35 public static boolean simpleMatch(String pattern, String str) { 36 if (ObjectUtils.nullSafeEquals(pattern, str) || "*".equals(pattern)) { 37 return true; 38 } 39 if (pattern == null || str == null) { 40 return false; 41 } 42 if (pattern.startsWith("*") && pattern.endsWith("*") && 43 str.indexOf(pattern.substring(1, pattern.length() - 1)) != -1) { 44 return true; 45 } 46 if (pattern.startsWith("*") && str.endsWith(pattern.substring(1, pattern.length()))) { 47 return true; 48 } 49 if (pattern.endsWith("*") && str.startsWith(pattern.substring(0, pattern.length() - 1))) { 50 return true; 51 } 52 return false; 53 } 54 55 62 public static boolean simpleMatch(String [] patterns, String str) { 63 if (patterns != null) { 64 for (int i = 0; i < patterns.length; i++) { 65 if (simpleMatch(patterns[i], str)) { 66 return true; 67 } 68 } 69 } 70 return false; 71 } 72 73 } 74 | Popular Tags |