You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ra...@apache.org on 2008/12/23 21:39:37 UTC

svn commit: r729099 - /commons/proper/digester/trunk/src/java/org/apache/commons/digester/RulesBase.java

Author: rahul
Date: Tue Dec 23 12:39:37 2008
New Revision: 729099

URL: http://svn.apache.org/viewvc?rev=729099&view=rev
Log:
Use generics and for-each.

Modified:
    commons/proper/digester/trunk/src/java/org/apache/commons/digester/RulesBase.java

Modified: commons/proper/digester/trunk/src/java/org/apache/commons/digester/RulesBase.java
URL: http://svn.apache.org/viewvc/commons/proper/digester/trunk/src/java/org/apache/commons/digester/RulesBase.java?rev=729099&r1=729098&r2=729099&view=diff
==============================================================================
--- commons/proper/digester/trunk/src/java/org/apache/commons/digester/RulesBase.java (original)
+++ commons/proper/digester/trunk/src/java/org/apache/commons/digester/RulesBase.java Tue Dec 23 12:39:37 2008
@@ -22,7 +22,6 @@
 
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 
 
@@ -61,7 +60,7 @@
      * Each value is a List containing the Rules for that pattern, in the
      * order that they were orginally registered.
      */
-    protected HashMap cache = new HashMap();
+    protected HashMap<String, List<Rule>> cache = new HashMap<String, List<Rule>>();
 
 
     /**
@@ -82,7 +81,7 @@
      * The set of registered Rule instances, in the order that they were
      * originally registered.
      */
-    protected ArrayList rules = new ArrayList();
+    protected ArrayList<Rule> rules = new ArrayList<Rule>();
 
 
     // ------------------------------------------------------------- Properties
@@ -107,10 +106,8 @@
     public void setDigester(Digester digester) {
 
         this.digester = digester;
-        Iterator items = rules.iterator();
-        while (items.hasNext()) {
-            Rule item = (Rule) items.next();
-            item.setDigester(digester);
+        for (Rule rule : rules) {
+            rule.setDigester(digester);
         }
 
     }
@@ -159,9 +156,9 @@
         }
         
         
-        List list = (List) cache.get(pattern);
+        List<Rule> list = cache.get(pattern);
         if (list == null) {
-            list = new ArrayList();
+            list = new ArrayList<Rule>();
             cache.put(pattern, list);
         }
         list.add(rule);
@@ -198,7 +195,7 @@
      *
      * @deprecated Call match(namespaceURI,pattern) instead.
      */
-    public List match(String pattern) {
+    public List<Rule> match(String pattern) {
 
         return (match(null, pattern));
 
@@ -216,16 +213,14 @@
      *  or <code>null</code> to match regardless of namespace URI
      * @param pattern Nesting pattern to be matched
      */
-    public List match(String namespaceURI, String pattern) {
+    public List<Rule> match(String namespaceURI, String pattern) {
 
         // List rulesList = (List) this.cache.get(pattern);
-        List rulesList = lookup(namespaceURI, pattern);
+        List<Rule> rulesList = lookup(namespaceURI, pattern);
         if ((rulesList == null) || (rulesList.size() < 1)) {
             // Find the longest key, ie more discriminant
             String longKey = "";
-            Iterator keys = this.cache.keySet().iterator();
-            while (keys.hasNext()) {
-                String key = (String) keys.next();
+            for (String key : cache.keySet()) {
                 if (key.startsWith("*/")) {
                     if (pattern.equals(key.substring(2)) ||
                         pattern.endsWith(key.substring(1))) {
@@ -239,7 +234,7 @@
             }
         }
         if (rulesList == null) {
-            rulesList = new ArrayList();
+            rulesList = new ArrayList<Rule>();
         }
         return (rulesList);
 
@@ -253,7 +248,7 @@
      * in the order originally registered through the <code>add()</code>
      * method.
      */
-    public List rules() {
+    public List<Rule> rules() {
 
         return (this.rules);
 
@@ -272,10 +267,10 @@
      *  select matching rules regardless of namespace URI
      * @param pattern Pattern to be matched
      */
-    protected List lookup(String namespaceURI, String pattern) {
+    protected List<Rule> lookup(String namespaceURI, String pattern) {
 
         // Optimize when no namespace URI is specified
-        List list = (List) this.cache.get(pattern);
+        List<Rule> list = this.cache.get(pattern);
         if (list == null) {
             return (null);
         }
@@ -284,10 +279,8 @@
         }
 
         // Select only Rules that match on the specified namespace URI
-        ArrayList results = new ArrayList();
-        Iterator items = list.iterator();
-        while (items.hasNext()) {
-            Rule item = (Rule) items.next();
+        ArrayList<Rule> results = new ArrayList<Rule>();
+        for (Rule item : list) {
             if ((namespaceURI.equals(item.getNamespaceURI())) ||
                     (item.getNamespaceURI() == null)) {
                 results.add(item);