Example #1
0
 /**
  * Return the value associated with the first pattern that the string matches, or the specified
  * default value if none, considering only patterns whose associated value is less than or equal
  * to maxPri.
  */
 public int getMatch(String str, int dfault, int maxPri) {
   Perl5Matcher matcher = RegexpUtil.getMatcher();
   for (Map.Entry<Pattern, Integer> ent : patternMap.entrySet()) {
     if (ent.getValue() <= maxPri) {
       Pattern pat = ent.getKey();
       if (matcher.contains(str, pat)) {
         log.debug2("getMatch(" + str + "): " + ent.getValue());
         return ent.getValue();
       }
     }
   }
   log.debug2("getMatch(" + str + "): default: " + dfault);
   return dfault;
 }
Example #2
0
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append("[pm: ");
   if (patternMap.isEmpty()) {
     sb.append("EMPTY");
   } else {
     for (Iterator<Map.Entry<Pattern, Integer>> iter = patternMap.entrySet().iterator();
         iter.hasNext(); ) {
       Map.Entry<Pattern, Integer> ent = iter.next();
       sb.append("[");
       sb.append(ent.getKey().getPattern());
       sb.append(": ");
       sb.append(ent.getValue());
       sb.append("]");
       if (iter.hasNext()) {
         sb.append(", ");
       }
     }
   }
   sb.append("]");
   return sb.toString();
 }