@Override
    public boolean eval(Map<String, Object> context) {
      Object fieldVal = this.fieldAcsr.get(context);
      String expr = this.exprExdr.expandString(context);
      Pattern pattern;
      try {
        pattern = compiler.compile(expr);
      } catch (MalformedPatternException e) {
        String errMsg = "Error in evaluation in if-regexp in screen: " + e.toString();
        Debug.logError(e, errMsg, module);
        throw new IllegalArgumentException(errMsg);
      }

      String fieldString = null;
      try {
        fieldString =
            (String)
                ObjectType.simpleTypeConvert(
                    fieldVal,
                    "String",
                    null,
                    (TimeZone) context.get("timeZone"),
                    (Locale) context.get("locale"),
                    true);
      } catch (GeneralException e) {
        Debug.logError(e, "Could not convert object to String, using empty String", module);
      }
      // always use an empty string by default
      if (fieldString == null) fieldString = "";

      return matcher.matches(fieldString, pattern);
    }
Esempio n. 2
0
 /** Convert specific starting hand to HoldemAtomicGroup object.
     @param groupSpec starting hand (e.g., AhKd, 8h3s)
 */
 public HoldemAtomicGroup(String groupSpec) {
   myspec = groupSpec;
   myhands = new HashSet();
   Perl5Compiler compiler = new Perl5Compiler();
   Perl5Matcher matcher = new Perl5Matcher();
   Pattern atomicPattern;
   try {
     atomicPattern = compiler.compile
       ("^([AKQJT98765432])([shdc])([AKQJT98765432])([shdc])$");
   } catch (MalformedPatternException e) {
     throw new RuntimeException("BUG: " + e.toString());
   }
   MatchResult result;
   if (matcher.matches(groupSpec, atomicPattern)) {
     result = matcher.getMatch();
     int rank1 = Deck.parseRank(result.group(1));
     int suit1 = Deck.parseSuit(result.group(2));
     int rank2 = Deck.parseRank(result.group(3));
     int suit2 = Deck.parseSuit(result.group(4));
     addAtomic(rank1, suit1, rank2, suit2);
   } else {
     throw new IllegalArgumentException("unable to parse groupSpec: " +
                                        groupSpec);
   }
 }