public static boolean applyMethod(Set<String> excludeMethods,
Set<String> includeMethods,
String method) {
// quick check to see if any actual pattern matching is needed
boolean needsPatternMatch = false;
Iterator quickIter = includeMethods.iterator();
for (String incMeth : includeMethods) {
if (!"*".equals(incMeth) && incMeth.contains("*")) {
needsPatternMatch = true;
}
}
for (String incMeth : excludeMethods) {
if (!"*".equals(incMeth) && incMeth.contains("*")) {
needsPatternMatch = true;
}
}
// this section will try to honor the original logic, while
// still allowing for wildcards later
if (!needsPatternMatch && (includeMethods.contains("*") || includeMethods.size() == 0) ) {
if (excludeMethods != null
&& excludeMethods.contains(method)
&& !includeMethods.contains(method) ) {
return false;
}
}
// test the methods using pattern matching
WildcardHelper wildcard = new WildcardHelper();
String methodCopy ;
if (method == null ) { // no method specified
methodCopy = "";
}
else {
methodCopy = new String(method);
}
for (String pattern : includeMethods) {
if (pattern.contains("*")) {
int[] compiledPattern = wildcard.compilePattern(pattern);
HashMap< String,String > matchedPatterns = new HashMap< String, String >();
boolean matches = wildcard.match(matchedPatterns, methodCopy, compiledPattern);
if (matches) {
return true; // run it, includeMethods takes precedence
}
}
else {
if (pattern.equals(methodCopy)) {
return true; // run it, includeMethods takes precedence
}
}
}
if (excludeMethods.contains("*") ) {
return false;
}
// CHECK ME: Previous implementation used include method
for ( String pattern : excludeMethods) {
if (pattern.contains("*")) {
int[] compiledPattern = wildcard.compilePattern(pattern);
HashMap< String,String > matchedPatterns = new HashMap< String, String >();
boolean matches = wildcard.match(matchedPatterns, methodCopy, compiledPattern);
if (matches) {
// if found, and wasn't included earlier, don't run it
return false;
}
}
else {
if (pattern.equals(methodCopy)) {
// if found, and wasn't included earlier, don't run it
return false;
}
}
}
// default fall-back from before changes
return includeMethods.size() == 0 || includeMethods.contains(method) || includeMethods.contains("*");
}
Static method to decide if the specified method should be
apply (not filtered) depending on the set of excludeMethods and
includeMethods .
-
includeMethods takes precedence over excludeMethods
Note: Supports wildcard listings in includeMethods/excludeMethods |