Ejemplo n.º 1
0
 boolean hasRequiredCharacterMix(String str) {
   // Must have at least 3 of: upper alpha, lower alpha, numeric, special
   int cnt = 0;
   Perl5Matcher matcher = RegexpUtil.getMatcher();
   for (Pattern pat : charPats) {
     if (matcher.contains(str, pat)) {
       cnt++;
     }
   }
   return cnt >= 3;
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
 /**
  * Return true if the regexp pattern is found to occur in the input string.
  *
  * @param input the input string
  * @param p the pattern
  */
 public static boolean regexp(String input, String p) {
   try {
     Pattern pattern = compiler.compile(p);
     return sMatcher.contains(input, pattern);
   } catch (MalformedPatternException e) {
     // We should probably print something to a debug log or something to mention that the pattern
     // we tested
     // threw an error and probably has some bogus regexp syntax.
     return false;
   }
 }
Ejemplo n.º 4
0
 /** Parse a string of the form [x1,y1},[x2,y2},...,[xN,yN} into a list of Points ([int,int]) */
 public static List<Point> parseString(String str) throws NumberFormatException {
   if (StringUtil.isNullString(str)) {
     throw new IllegalArgumentException("Must supply non-empty string");
   }
   ArrayList<Point> res = new ArrayList<Point>();
   Perl5Matcher matcher = RegexpUtil.getMatcher();
   while (matcher.contains(str, ONE_POINT_PAT)) {
     MatchResult matchResult = matcher.getMatch();
     String xstr = matchResult.group(1);
     String ystr = matchResult.group(2);
     str = matchResult.group(3);
     try {
       int x = Integer.parseInt(xstr);
       int y = Integer.parseInt(ystr);
       res.add(new Point(x, y));
     } catch (NumberFormatException e) {
       throw new IllegalArgumentException("bad point [" + xstr + "," + ystr + "] in " + str);
     }
   }
   res.trimToSize();
   return res;
 }
Ejemplo n.º 5
0
 public static boolean isMatches(String strQuery, String strPattern) {
   return matcher.matches(strQuery, PatternUtils.getPattern(strPattern));
 }