commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skitch...@apache.org
Subject cvs commit: jakarta-commons/digester/src/java/org/apache/commons/digester ExtendedBaseRules.java
Date Fri, 07 May 2004 01:21:14 GMT
skitching    2004/05/06 18:21:14

  Modified:    digester/src/java/org/apache/commons/digester
                        ExtendedBaseRules.java
  Log:
  Patch for bug #28486. Also avoid multiple calls to startsWith and endsWith
  as requested by Robert Donkin.
  
  Revision  Changes    Path
  1.14      +24 -9     jakarta-commons/digester/src/java/org/apache/commons/digester/ExtendedBaseRules.java
  
  Index: ExtendedBaseRules.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/ExtendedBaseRules.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ExtendedBaseRules.java	8 Apr 2004 06:11:36 -0000	1.13
  +++ ExtendedBaseRules.java	7 May 2004 01:21:14 -0000	1.14
  @@ -254,6 +254,8 @@
   
           // Find the longest key, ie more discriminant
           String longKey = "";
  +        int longKeyLength = 0;
  +        
           Iterator keys = this.cache.keySet().iterator();
           while (keys.hasNext()) {
               String key = (String) keys.next();
  @@ -268,18 +270,22 @@
   
                       
               // don't need to check exact matches
  -            if (key.startsWith("*/") || (isUniversal && key.endsWith("/*"))) {
  +            boolean wildcardMatchStart = key.startsWith("*/");
  +            boolean wildcardMatchEnd = key.endsWith("/*");
  +            if (wildcardMatchStart || (isUniversal && wildcardMatchEnd)) {
   
                   boolean parentMatched = false;
                   boolean basicMatched = false;
                   boolean ancesterMatched = false;
  -                if (key.endsWith("/?")) {
  +                
  +                boolean parentMatchEnd = key.endsWith("/?");
  +                if (parentMatchEnd) {
                       // try for a parent match
                       parentMatched = parentMatch(key, pattern, parentPattern);
   
  -                } else if (key.endsWith("/*")) {
  +                } else if (wildcardMatchEnd) {
                       // check for ancester match
  -                    if (key.startsWith("*/")) {
  +                    if (wildcardMatchStart) {
                           String patternBody = key.substring(2, key.length() - 2);
                           if (pattern.endsWith(patternBody)) {
                               ancesterMatched = true;
  @@ -317,16 +323,25 @@
                       } else {
                           if (!ignoreBasicMatches) {
                               // ensure that all parent matches are SHORTER
  -                            // than rules with same level of matching
  +                            // than rules with same level of matching.
  +                            //
  +                            // the calculations below don't work for universal
  +                            // matching, but we don't care because in that case
  +                            // this if-stmt is not entered.
                               int keyLength = key.length();
  -                            if (parentMatched || ancesterMatched) {
  -                                keyLength--;
  +                            if (wildcardMatchStart) {
  +                                --keyLength;
  +                            }
  +                            if (wildcardMatchEnd) {
  +                                --keyLength;
  +                            } else if (parentMatchEnd) {
  +                                --keyLength;
                               }
   
  -
  -                            if (keyLength > longKey.length()) {
  +                            if (keyLength > longKeyLength) {
                                   rulesList = (List) this.cache.get(key);
                                   longKey = key;
  +                                longKeyLength = keyLength;
                               }
                           }
                       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message