A second patch to fix the remaining warnings from
the regex code.

ChangeLog:

2008-05-10  Andrew John Hughes  <[EMAIL PROTECTED]>

        * gnu/java/util/regex/RE.java:
        Switch to use generic ArrayLists.
        * gnu/java/util/regex/REMatchEnumeration.java:
        Make the enumeration implementation generic.
        * gnu/java/util/regex/RETokenLookBehind.java:
        Remove unused variables.

-- 
Andrew :)

Support Free Java!
Contribute to GNU Classpath and the OpenJDK
http://www.gnu.org/software/classpath
http://openjdk.java.net
PGP Key: 94EFD9D8 (http://subkeys.pgp.net)
Fingerprint = F8EF F1EA 401E 2E60 15FA  7927 142C 2591 94EF D9D8
Index: gnu/java/util/regex/RE.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/java/util/regex/RE.java,v
retrieving revision 1.7
diff -u -r1.7 RE.java
--- gnu/java/util/regex/RE.java 5 May 2008 20:58:07 -0000       1.7
+++ gnu/java/util/regex/RE.java 9 May 2008 22:57:23 -0000
@@ -41,10 +41,12 @@
 
 import java.io.InputStream;
 import java.io.Serializable;
+
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Locale;
 import java.util.PropertyResourceBundle;
 import java.util.ResourceBundle;
-import java.util.Vector;
 
 /**
  * RE provides the user interface for compiling and matching regular
@@ -364,7 +366,7 @@
     int pLength = pattern.length;
 
     numSubs = 0; // Number of subexpressions in this token.
-    Vector branches = null;
+    ArrayList<REToken> branches = null;
 
     // linked list of tokens (sort of -- some closed loops can exist)
     firstToken = lastToken = null;
@@ -388,7 +390,6 @@
 
     // Buffer a token so we can create a TokenRepeated, etc.
     REToken currentToken = null;
-    char ch;
     boolean quot = false;
 
     // Saved syntax and flags.
@@ -451,9 +452,9 @@
        minimumLength = 0;
        maximumLength = 0;
        if (branches == null) {
-           branches = new Vector();
+           branches = new ArrayList<REToken>();
        }
-       branches.addElement(theBranch);
+       branches.add(theBranch);
        firstToken = lastToken = currentToken = null;
       }
       
@@ -1105,7 +1106,7 @@
     addToken(currentToken);
       
     if (branches != null) {
-       branches.addElement(new 
RE(firstToken,lastToken,numSubs,subIndex,minimumLength, maximumLength));
+       branches.add(new 
RE(firstToken,lastToken,numSubs,subIndex,minimumLength, maximumLength));
        branches.trimToSize(); // compact the Vector
        minimumLength = 0;
        maximumLength = 0;
@@ -1139,8 +1140,8 @@
 
        boolean insens = ((cflags & REG_ICASE) > 0);
        boolean insensUSASCII = ((cflags & REG_ICASE_USASCII) > 0);
-       Vector options = new Vector();
-       Vector addition = new Vector();
+       final ArrayList<REToken> options = new ArrayList<REToken>();
+       ArrayList<Object> addition = new ArrayList<Object>();
        boolean additionAndAppeared = false;
        final int RETURN_AT_AND = 0x01;
        boolean returnAtAndOperator = ((pflags & RETURN_AT_AND) != 0);
@@ -1170,7 +1171,7 @@
            if ((ch = pattern[index]) == ']') {
              RETokenChar t = new RETokenChar(subIndex,lastChar,insens);
              if (insensUSASCII) t.unicodeAware = false;
-             options.addElement(t);
+             options.add(t);
              lastChar = '-';
            } else {
              if ((ch == '\\') && 
syntax.get(RESyntax.RE_BACKSLASH_ESCAPE_IN_LISTS)) {
@@ -1182,7 +1183,7 @@
              }
              RETokenRange t = new RETokenRange(subIndex,lastChar,ch,insens);
              if (insensUSASCII) t.unicodeAware = false;
-             options.addElement(t);
+             options.add(t);
              lastChar = 0; lastCharIsSet = false;
              index++;
            }
@@ -1228,17 +1229,17 @@
            if (lastCharIsSet) {
              RETokenChar t = new RETokenChar(subIndex,lastChar,insens);
              if (insensUSASCII) t.unicodeAware = false;
-             options.addElement(t);
+             options.add(t);
            }
            
            if (posixID != -1) {
              RETokenPOSIX t = new RETokenPOSIX(subIndex,posixID,insens,negate);
              if (insensUSASCII) t.unicodeAware = false;
-             options.addElement(t);
+             options.add(t);
            } else if (np != null) {
              RETokenNamedProperty t = 
getRETokenNamedProperty(subIndex,np,insens,index);
              if (insensUSASCII) t.unicodeAware = false;
-             options.addElement(t);
+             options.add(t);
            } else if (asciiEscIsSet) {
              lastChar = asciiEsc; lastCharIsSet = true;
            } else {
@@ -1252,13 +1253,13 @@
            if (posixId != -1) {
              RETokenPOSIX t = new RETokenPOSIX(subIndex,posixId,insens,false);
              if (insensUSASCII) t.unicodeAware = false;
-             options.addElement(t);
+             options.add(t);
            }
          } else if ((ch == '[') && (syntax.get(RESyntax.RE_NESTED_CHARCLASS))) 
{
                ParseCharClassResult result = parseCharClass(
                    subIndex, pattern, index, pLength, cflags, syntax, 0);
-               addition.addElement(result.token);
-               addition.addElement("|");
+               addition.add(result.token);
+               addition.add("|");
                index = result.index;
          } else if ((ch == '&') &&
                     (syntax.get(RESyntax.RE_NESTED_CHARCLASS)) &&
@@ -1266,7 +1267,7 @@
                if (returnAtAndOperator) {
                    ParseCharClassResult result = new ParseCharClassResult(); 
                    options.trimToSize();
-                   if (additionAndAppeared) addition.addElement("&");
+                   if (additionAndAppeared) addition.add("&");
                    if (addition.size() == 0) addition = null;
                    result.token = new RETokenOneOf(subIndex,
                        options, addition, negative);
@@ -1281,8 +1282,8 @@
                // So, "&&[a-b][k-m]" will be stored in the Vecter
                // addition in this order:
                //     Boolean.FALSE, [a-b], "|", [k-m], "|", "&"
-               if (additionAndAppeared) addition.addElement("&");
-               addition.addElement(Boolean.FALSE);
+               if (additionAndAppeared) addition.add("&");
+               addition.add(Boolean.FALSE);
                additionAndAppeared = true;
 
                // The part on which "&&" operates may be either
@@ -1296,8 +1297,8 @@
                    ParseCharClassResult result = parseCharClass(
                        subIndex, pattern, index+1, pLength, cflags, syntax,
                        RETURN_AT_AND);
-                   addition.addElement(result.token);
-                   addition.addElement("|");
+                   addition.add(result.token);
+                   addition.add("|");
                    // If the method returned at the next "&&", it is OK.
                    // Otherwise we have eaten the mark of the end of this
                    // character list "]".  In this case we must give back
@@ -1309,7 +1310,7 @@
            if (lastCharIsSet) {
              RETokenChar t = new RETokenChar(subIndex,lastChar,insens);
              if (insensUSASCII) t.unicodeAware = false;
-             options.addElement(t);
+             options.add(t);
            }
            lastChar = ch; lastCharIsSet = true;
          }
@@ -1320,13 +1321,13 @@
        if (lastCharIsSet) {
          RETokenChar t = new RETokenChar(subIndex,lastChar,insens);
          if (insensUSASCII) t.unicodeAware = false;
-         options.addElement(t);
+         options.add(t);
        }
           
        ParseCharClassResult result = new ParseCharClassResult(); 
        // Create a new RETokenOneOf
        options.trimToSize();
-       if (additionAndAppeared) addition.addElement("&");
+       if (additionAndAppeared) addition.add("&");
        if (addition.size() == 0) addition = null;
        result.token = new RETokenOneOf(subIndex,options, addition, negative);
        result.index = index;
@@ -1644,10 +1645,10 @@
 
   // this has been changed since 1.03 to be non-overlapping matches
   private REMatch[] getAllMatchesImpl(CharIndexed input, int index, int 
eflags) {
-    Vector all = new Vector();
+    List<REMatch> all = new ArrayList<REMatch>();
     REMatch m = null;
     while ((m = getMatchImpl(input,index,eflags,null)) != null) {
-      all.addElement(m);
+      all.add(m);
       index = m.getEndIndex();
       if (m.end[0] == 0) {   // handle pathological case of zero-length match
        index++;
@@ -1657,9 +1658,7 @@
       }
       if (!input.isValid()) break;
     }
-    REMatch[] mset = new REMatch[all.size()];
-    all.copyInto(mset);
-    return mset;
+    return all.toArray(new REMatch[all.size()]);
   }
   
     /* Implements abstract method REToken.match() */
Index: gnu/java/util/regex/REMatchEnumeration.java
===================================================================
RCS file: 
/sources/classpath/classpath/gnu/java/util/regex/REMatchEnumeration.java,v
retrieving revision 1.2
diff -u -r1.2 REMatchEnumeration.java
--- gnu/java/util/regex/REMatchEnumeration.java 5 May 2008 20:58:07 -0000       
1.2
+++ gnu/java/util/regex/REMatchEnumeration.java 9 May 2008 22:57:23 -0000
@@ -69,17 +69,18 @@
  * 
  * @author <A HREF="mailto:[EMAIL PROTECTED]">Wes Biggs</A> 
  */
-public class REMatchEnumeration implements Enumeration, Serializable {
+public class REMatchEnumeration 
+  implements Enumeration<REMatch>, Serializable {
   private static final int YES = 1;
   private static final int MAYBE = 0;
   private static final int NO = -1;
   
   private int more;
   private REMatch match;
-  private RE expr;
-  private CharIndexed input;
-  private int eflags;
-    private int index;
+  private final RE expr;
+  private final CharIndexed input;
+  private final int eflags;
+  private int index;
 
   // Package scope constructor is used by RE.getMatchEnumeration()
   REMatchEnumeration(RE expr, CharIndexed input, int index, int eflags) {
@@ -118,20 +119,14 @@
   }
 
   /** Returns the next match in the input text. */
-  public Object nextElement() throws NoSuchElementException {
-    return nextMatch();
-  }
-
-  /** 
-   * Returns the next match in the input text. This method is provided
-   * for convenience to avoid having to explicitly cast the return value
-   * to class REMatch.
-   */
-  public REMatch nextMatch() throws NoSuchElementException {
-    if (hasMoreElements()) {
+  public REMatch nextElement() 
+    throws NoSuchElementException 
+  {
+    if (hasMoreElements()) 
+      {
        more = (input.isValid()) ? MAYBE : NO;
        return match;
-    }
+      }
     throw new NoSuchElementException();
   }
 }
Index: gnu/java/util/regex/RETokenLookBehind.java
===================================================================
RCS file: 
/sources/classpath/classpath/gnu/java/util/regex/RETokenLookBehind.java,v
retrieving revision 1.2
diff -u -r1.2 RETokenLookBehind.java
--- gnu/java/util/regex/RETokenLookBehind.java  5 May 2008 20:58:08 -0000       
1.2
+++ gnu/java/util/regex/RETokenLookBehind.java  9 May 2008 22:57:23 -0000
@@ -62,8 +62,6 @@
     int max = re.getMaximumLength();
     CharIndexed behind = input.lookBehind(mymatch.index, max);
     REMatch trymatch = (REMatch)mymatch.clone();
-    REMatch trymatch1 = (REMatch)mymatch.clone();
-    REMatch newMatch = null;
     int diff = behind.length() - input.length();
     int curIndex = trymatch.index + diff;
     trymatch.index = 0;

Reply via email to