More generic fixes in gnu.xml.xpath.*.

ChangeLog:

2008-06-22  Andrew John Hughes  <[EMAIL PROTECTED]>

        * gnu/xml/xpath/Expr.java,
        * gnu/xml/xpath/FloorFunction.java,
        * gnu/xml/xpath/Function.java,
        * gnu/xml/xpath/FunctionCall.java,
        * gnu/xml/xpath/NamespaceUriFunction.java,
        * gnu/xml/xpath/ParenthesizedExpr.java,
        * gnu/xml/xpath/Root.java,
        * gnu/xml/xpath/Selector.java,
        * gnu/xml/xpath/Steps.java:
        Genericised.

-- 
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/xml/xpath/Expr.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/xpath/Expr.java,v
retrieving revision 1.8
diff -u -u -r1.8 Expr.java
--- gnu/xml/xpath/Expr.java     22 Jun 2008 19:43:00 -0000      1.8
+++ gnu/xml/xpath/Expr.java     22 Jun 2008 21:08:42 -0000
@@ -285,7 +285,7 @@
    * empty string is returned. If the argument is omitted, it defaults to a
    * node-set with the context node as its only member.
    */
-  public static String _namespace_uri(Node context, Collection nodeSet)
+  public static String _namespace_uri(Node context, Collection<Node> nodeSet)
   {
     if (nodeSet == null || nodeSet.isEmpty())
       return "";
@@ -329,11 +329,11 @@
   /**
    * Returns the first node in the set in document order.
    */
-  static Node firstNode(Collection nodeSet)
+  static Node firstNode(Collection<Node> nodeSet)
   {
-    List list = new ArrayList(nodeSet);
+    List<Node> list = new ArrayList<Node>(nodeSet);
     Collections.sort(list, documentOrderComparator);
-    return (Node) list.get(0);
+    return list.get(0);
   }
 
   /* -- 4.2 String Functions -- */
Index: gnu/xml/xpath/FloorFunction.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/xpath/FloorFunction.java,v
retrieving revision 1.3
diff -u -u -r1.3 FloorFunction.java
--- gnu/xml/xpath/FloorFunction.java    9 Jul 2005 20:38:35 -0000       1.3
+++ gnu/xml/xpath/FloorFunction.java    22 Jun 2008 21:08:42 -0000
@@ -54,9 +54,9 @@
 
   final Expr arg;
 
-  FloorFunction(List args)
+  FloorFunction(List<Expr> args)
   {
-    this((Expr) args.get(0));
+    this(args.get(0));
   }
 
   FloorFunction(Expr arg)
@@ -64,6 +64,7 @@
     this.arg = arg;
   }
 
+  @Override
   public Object evaluate(Node context, int pos, int len)
   {
     Object val = arg.evaluate(context, pos, len);
Index: gnu/xml/xpath/Function.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/xpath/Function.java,v
retrieving revision 1.2
diff -u -u -r1.2 Function.java
--- gnu/xml/xpath/Function.java 2 Jul 2005 20:32:22 -0000       1.2
+++ gnu/xml/xpath/Function.java 22 Jun 2008 21:08:42 -0000
@@ -51,7 +51,7 @@
   /**
    * Sets the list of expressions to evaluate as parameter values.
    */
-  void setArguments(List args);
+  void setArguments(List<Expr> args);
 
 }
 
Index: gnu/xml/xpath/FunctionCall.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/xpath/FunctionCall.java,v
retrieving revision 1.5
diff -u -u -r1.5 FunctionCall.java
--- gnu/xml/xpath/FunctionCall.java     28 Apr 2008 19:52:33 -0000      1.5
+++ gnu/xml/xpath/FunctionCall.java     22 Jun 2008 21:08:42 -0000
@@ -60,20 +60,24 @@
 
   final XPathFunctionResolver resolver;
   final String name;
-  final List args;
+  final List<Expr> args;
 
   public FunctionCall(XPathFunctionResolver resolver, String name)
   {
-    this(resolver, name, Collections.EMPTY_LIST);
+    this(resolver, name, null);
   }
 
-  public FunctionCall(XPathFunctionResolver resolver, String name, List args)
+  public FunctionCall(XPathFunctionResolver resolver, String name, List<Expr> 
args)
   {
     this.resolver = resolver;
     this.name = name;
-    this.args = args;
+    if (args == null)
+      this.args = Collections.emptyList();
+    else
+      this.args = args;
   }
 
+  @Override
   public Object evaluate(Node context, int pos, int len)
   {
     if (resolver != null)
@@ -94,7 +98,7 @@
               }
             else
               {
-                List values = new ArrayList(arity);
+                List<Object> values = new ArrayList<Object>(arity);
                 for (int i = 0; i < arity; i++)
                   {
                     Expr arg = (Expr) args.get(i);
@@ -119,10 +123,10 @@
   public Expr clone(Object context)
   {
     int len = args.size();
-    List args2 = new ArrayList(len);
+    List<Expr> args2 = new ArrayList<Expr>(len);
     for (int i = 0; i < len; i++)
       {
-        args2.add(((Expr) args.get(i)).clone(context));
+        args2.add(args.get(i).clone(context));
       }
     XPathFunctionResolver r = resolver;
     if (context instanceof XPathFunctionResolver)
@@ -134,9 +138,9 @@
 
   public boolean references(QName var)
   {
-    for (Iterator i = args.iterator(); i.hasNext(); )
+    for (Iterator<Expr> i = args.iterator(); i.hasNext(); )
       {
-        if (((Expr) i.next()).references(var))
+        if (i.next().references(var))
           {
             return true;
           }
Index: gnu/xml/xpath/NamespaceUriFunction.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/xpath/NamespaceUriFunction.java,v
retrieving revision 1.4
diff -u -u -r1.4 NamespaceUriFunction.java
--- gnu/xml/xpath/NamespaceUriFunction.java     11 Jan 2006 22:05:45 -0000      
1.4
+++ gnu/xml/xpath/NamespaceUriFunction.java     22 Jun 2008 21:08:42 -0000
@@ -59,9 +59,9 @@
 
   final Expr arg;
 
-  NamespaceUriFunction(List args)
+  NamespaceUriFunction(List<Expr> args)
   {
-    this(args.size() > 0 ? (Expr) args.get(0) : null);
+    this(args.size() > 0 ? args.get(0) : null);
   }
   
   NamespaceUriFunction(Expr arg)
@@ -69,11 +69,12 @@
     this.arg = arg;
   }
 
+  @Override @SuppressWarnings("unchecked")
   public Object evaluate(Node context, int pos, int len)
   {
     Object val = (arg == null) ? Collections.singleton(context) :
         arg.evaluate(context, pos, len);
-    return _namespace_uri(context, (Collection) val);
+    return _namespace_uri(context, (Collection<Node>) val);
   }
 
   public Expr clone(Object context)
Index: gnu/xml/xpath/ParenthesizedExpr.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/xpath/ParenthesizedExpr.java,v
retrieving revision 1.3
diff -u -u -r1.3 ParenthesizedExpr.java
--- gnu/xml/xpath/ParenthesizedExpr.java        9 Jul 2005 20:38:36 -0000       
1.3
+++ gnu/xml/xpath/ParenthesizedExpr.java        22 Jun 2008 21:08:42 -0000
@@ -60,12 +60,13 @@
     this.expr = expr;
   }
 
+  @Override
   public Object evaluate(Node context, int pos, int len)
   {
     Object ret = expr.evaluate(context, pos, len);
     if (ret instanceof Collection)
       {
-        List list = new ArrayList((Collection) ret);
+        List<Node> list = new ArrayList<Node>((Collection<Node>) ret);
         Collections.sort(list, documentOrderComparator);
         ret = list;
       }
Index: gnu/xml/xpath/Root.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/xpath/Root.java,v
retrieving revision 1.3
diff -u -u -r1.3 Root.java
--- gnu/xml/xpath/Root.java     9 Jul 2005 20:38:36 -0000       1.3
+++ gnu/xml/xpath/Root.java     22 Jun 2008 21:08:42 -0000
@@ -39,6 +39,8 @@
 
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Set;
+
 import javax.xml.namespace.QName;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
@@ -59,12 +61,14 @@
 
   public Object evaluate(Node context, int pos, int len)
   {
-    return evaluate(context, Collections.EMPTY_SET);
+    Set<Node> emptySet = Collections.emptySet();
+    return evaluate(context, emptySet);
   }
 
-  Collection evaluate(Node context, Collection ns)
+  @Override
+  Collection<Node> evaluate(Node context, Collection<Node> ns)
   {
-    Document doc = (context instanceof Document) ? (Document) context :
+    Node doc = (context instanceof Document) ? context :
       context.getOwnerDocument();
     return Collections.singleton(doc);
   }
Index: gnu/xml/xpath/Selector.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/xpath/Selector.java,v
retrieving revision 1.10
diff -u -u -r1.10 Selector.java
--- gnu/xml/xpath/Selector.java 22 Jun 2008 19:43:01 -0000      1.10
+++ gnu/xml/xpath/Selector.java 22 Jun 2008 21:08:42 -0000
@@ -190,7 +190,7 @@
     return ret;
   }
 
-  Collection evaluate(Node context, Collection<Node> ns)
+  Collection<Node> evaluate(Node context, Collection<Node> ns)
   {
     Set<Node> acc = new LinkedHashSet<Node>();
     for (Iterator<Node> i = ns.iterator(); i.hasNext(); )
@@ -417,7 +417,7 @@
   public Expr clone(Object context)
   {
     int len = tests.length;
-    List tests2 = new ArrayList(len);
+    List<Test> tests2 = new ArrayList<Test>(len);
     for (int i = 0; i < len; i++)
       tests2.add(tests[i].clone(context));
     return new Selector(axis, tests2);
Index: gnu/xml/xpath/Steps.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/xml/xpath/Steps.java,v
retrieving revision 1.5
diff -u -u -r1.5 Steps.java
--- gnu/xml/xpath/Steps.java    22 Jun 2008 19:43:01 -0000      1.5
+++ gnu/xml/xpath/Steps.java    22 Jun 2008 21:08:42 -0000
@@ -160,7 +160,7 @@
     return Collections.emptySet();
   }
 
-  @Override
+  @Override @SuppressWarnings("unchecked")
   public Object evaluate(Node context, int pos, int len)
   {
     //System.err.println(toString()+" evaluate");
@@ -172,13 +172,13 @@
     while (val instanceof Collection && i.hasNext())
       {
         Path rhs = (Path) i.next();
-        val = rhs.evaluate(context, (Collection) val);
+        val = rhs.evaluate(context, (Collection<Node>) val);
         //System.err.println("\tevaluate "+rhs+" = "+val);
       }
     return val;
   }
 
-  @Override
+  @Override @SuppressWarnings("unchecked")
   Collection<Node> evaluate(Node context, Collection<Node> ns)
   {
     // Left to right

Reply via email to