This patch completes the generification of gnu.xml.xpath.*. ChangeLog:
2008-06-22 Andrew John Hughes <[EMAIL PROTECTED]> * gnu/xml/xpath/ContainsFunction.java, * gnu/xml/xpath/CountFunction.java, * gnu/xml/xpath/EqualityExpr.java, * gnu/xml/xpath/Expr.java, * gnu/xml/xpath/IdFunction.java, * gnu/xml/xpath/LocalNameFunction.java, * gnu/xml/xpath/NameFunction.java, * gnu/xml/xpath/ParenthesizedExpr.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/ContainsFunction.java =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/ContainsFunction.java,v retrieving revision 1.3 diff -u -u -r1.3 ContainsFunction.java --- gnu/xml/xpath/ContainsFunction.java 9 Jul 2005 20:38:35 -0000 1.3 +++ gnu/xml/xpath/ContainsFunction.java 22 Jun 2008 22:19:14 -0000 @@ -54,9 +54,9 @@ final Expr arg1; final Expr arg2; - ContainsFunction(List args) + ContainsFunction(List<Expr> args) { - this((Expr) args.get(0), (Expr) args.get(1)); + this(args.get(0), args.get(1)); } ContainsFunction(Expr arg1, Expr arg2) @@ -65,6 +65,7 @@ this.arg2 = arg2; } + @Override public Object evaluate(Node context, int pos, int len) { Object val1 = arg1.evaluate(context, pos, len); Index: gnu/xml/xpath/CountFunction.java =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/CountFunction.java,v retrieving revision 1.3 diff -u -u -r1.3 CountFunction.java --- gnu/xml/xpath/CountFunction.java 9 Jul 2005 20:38:35 -0000 1.3 +++ gnu/xml/xpath/CountFunction.java 22 Jun 2008 22:19:14 -0000 @@ -54,9 +54,9 @@ final Expr arg; - CountFunction(List args) + CountFunction(List<Expr> args) { - this((Expr) args.get(0)); + this(args.get(0)); } CountFunction(Expr arg) @@ -64,10 +64,11 @@ this.arg = arg; } + @Override @SuppressWarnings("unchecked") public Object evaluate(Node context, int pos, int len) { Object val = arg.evaluate(context, pos, len); - return new Double((double) ((Collection) val).size()); + return new Double((double) ((Collection<Node>) val).size()); } public Expr clone(Object context) Index: gnu/xml/xpath/EqualityExpr.java =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/EqualityExpr.java,v retrieving revision 1.4 diff -u -u -r1.4 EqualityExpr.java --- gnu/xml/xpath/EqualityExpr.java 9 Jul 2005 20:38:35 -0000 1.4 +++ gnu/xml/xpath/EqualityExpr.java 22 Jun 2008 22:19:15 -0000 @@ -62,6 +62,7 @@ this.invert = invert; } + @Override public Object evaluate(Node context, int pos, int len) { boolean val = evaluateImpl(context, pos, len); @@ -75,6 +76,7 @@ } } + @SuppressWarnings("unchecked") private boolean evaluateImpl(Node context, int pos, int len) { Object left = lhs.evaluate(context, pos, len); @@ -90,19 +92,17 @@ boolean frns = right instanceof Collection; if (flns && frns) { - Collection lns = (Collection) left; - Collection rns = (Collection) right; + Collection<Node> lns = (Collection<Node>) left; + Collection<Node> rns = (Collection<Node>) right; if (lns.isEmpty()) { return false; } boolean all = true; - for (Iterator i = lns.iterator(); i.hasNext(); ) - { - Node ltest = (Node) i.next(); - for (Iterator j = rns.iterator(); j.hasNext(); ) - { - Node rtest = (Node) j.next(); + for (Node ltest : lns) + { + for (Node rtest : rns) + { if (ltest == rtest || ltest.equals(rtest)) { // much shorter @@ -138,13 +138,12 @@ boolean frn = right instanceof Double; if ((flns && frn) || (frns && fln)) { - Collection ns = flns ? (Collection) left : (Collection) right; + Collection<Node> ns = flns ? (Collection<Node>) left : (Collection<Node>) right; double n = fln ? ((Double) left).doubleValue() : ((Double) right).doubleValue(); boolean all = true; - for (Iterator i = ns.iterator(); i.hasNext(); ) + for (Node test : ns) { - Node test = (Node) i.next(); double nn = _number(context, stringValue(test)); if (nn == n) { @@ -171,12 +170,11 @@ boolean frs = right instanceof String; if ((flns && frs) || (frns && fls)) { - Collection ns = flns ? (Collection) left : (Collection) right; + Collection<Node> ns = flns ? (Collection<Node>) left : (Collection<Node>) right; String s = fls ? (String) left : (String) right; boolean all = true; - for (Iterator i = ns.iterator(); i.hasNext(); ) + for (Node test : ns) { - Node test = (Node) i.next(); if (stringValue(test).equals(s)) { if (!invert) @@ -202,7 +200,7 @@ boolean frb = right instanceof Boolean; if ((flns && frb) || (frns && flb)) { - Collection ns = flns ? (Collection) left : (Collection) right; + Collection<Node> ns = flns ? (Collection<Node>) left : (Collection<Node>) right; boolean b = flb ? ((Boolean) left).booleanValue() : ((Boolean) right).booleanValue(); return _boolean(context, ns) == b; Index: gnu/xml/xpath/Expr.java =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/Expr.java,v retrieving revision 1.9 diff -u -u -r1.9 Expr.java --- gnu/xml/xpath/Expr.java 22 Jun 2008 21:21:11 -0000 1.9 +++ gnu/xml/xpath/Expr.java 22 Jun 2008 22:19:15 -0000 @@ -86,14 +86,14 @@ static class ExprNodeSet implements NodeList { - private ArrayList list; + private ArrayList<Node> list; - ExprNodeSet(Collection collection) + ExprNodeSet(Collection<Node> collection) { if (collection instanceof ArrayList) - list = (ArrayList) collection; + list = (ArrayList<Node>) collection; else - list = new ArrayList(collection); + list = new ArrayList<Node>(collection); } public int getLength() @@ -105,7 +105,7 @@ { try { - return (Node) list.get(index); + return list.get(index); } catch (ArrayIndexOutOfBoundsException e) { @@ -115,6 +115,7 @@ } + @SuppressWarnings("unchecked") public Object evaluate(Object item, QName returnType) throws XPathExpressionException { @@ -143,14 +144,14 @@ { if (ret instanceof Collection) { - Collection ns = (Collection) ret; + Collection<Node> ns = (Collection<Node>) ret; switch (ns.size()) { case 0: ret = null; break; case 1: - ret = (Node) ns.iterator().next(); + ret = ns.iterator().next(); break; default: throw new XPathExpressionException("multiple nodes in node-set"); @@ -168,7 +169,7 @@ throw new XPathExpressionException("return value is not a node-set"); } if (ret != null) - ret = new ExprNodeSet((Collection) ret); + ret = new ExprNodeSet((Collection<Node>) ret); } } return ret; @@ -231,15 +232,16 @@ * same document as the context node that have a unique ID equal to any of * the tokens in the list. */ - public static Collection _id(Node context, Object object) + @SuppressWarnings("unchecked") + public static Collection<Node> _id(Node context, Object object) { - Set ret = new HashSet(); + Set<Node> ret = new HashSet<Node>(); if (object instanceof Collection) { - Collection nodeSet = (Collection) object; - for (Iterator i = nodeSet.iterator(); i.hasNext(); ) + Collection<Node> nodeSet = (Collection<Node>) object; + for (Iterator<Node> i = nodeSet.iterator(); i.hasNext(); ) { - String string = stringValue((Node) i.next()); + String string = stringValue(i.next()); ret.addAll(_id (context, string)); } } @@ -268,7 +270,7 @@ * an 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 _local_name(Node context, Collection nodeSet) + public static String _local_name(Node context, Collection<Node> nodeSet) { if (nodeSet == null || nodeSet.isEmpty()) return ""; @@ -310,7 +312,7 @@ * string is returned. If the argument it omitted, it defaults to a * node-set with the context node as its only member. */ - public static String _name(Node context, Collection nodeSet) + public static String _name(Node context, Collection<Node> nodeSet) { if (nodeSet == null || nodeSet.isEmpty()) return ""; @@ -341,6 +343,7 @@ /** * Implementation of the XPath <code>string</code> function. */ + @SuppressWarnings("unchecked") public static String _string(Node context, Object object) { if (object == null) @@ -389,7 +392,7 @@ } if (object instanceof Collection) { - Collection nodeSet = (Collection) object; + Collection<Node> nodeSet = (Collection<Node>) object; if (nodeSet.isEmpty()) { return ""; @@ -405,6 +408,7 @@ /** * Implementation of the XPath <code>boolean</code> function. */ + @SuppressWarnings("unchecked") public static boolean _boolean(Node context, Object object) { if (object instanceof Boolean) @@ -424,7 +428,7 @@ } if (object instanceof Collection) { - return ((Collection) object).size() != 0; + return ((Collection<Node>) object).size() != 0; } return false; // TODO user defined types } @@ -434,6 +438,7 @@ /** * Implementation of the XPath <code>number</code> function. */ + @SuppressWarnings("unchecked") public static double _number(Node context, Object object) { if (object == null) @@ -451,7 +456,7 @@ if (object instanceof Collection) { // Convert node-set to string - object = stringValue((Collection) object); + object = stringValue((Collection<Node>) object); } if (object instanceof String) { @@ -471,12 +476,12 @@ /** * Computes the XPath string-value of the specified node-set. */ - public static String stringValue(Collection nodeSet) + public static String stringValue(Collection<Node> nodeSet) { CPStringBuilder buf = new CPStringBuilder(); - for (Iterator i = nodeSet.iterator(); i.hasNext(); ) + for (Iterator<Node> i = nodeSet.iterator(); i.hasNext(); ) { - buf.append(stringValue((Node) i.next())); + buf.append(stringValue(i.next())); } return buf.toString(); } Index: gnu/xml/xpath/IdFunction.java =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/IdFunction.java,v retrieving revision 1.4 diff -u -u -r1.4 IdFunction.java --- gnu/xml/xpath/IdFunction.java 22 Jun 2008 19:43:00 -0000 1.4 +++ gnu/xml/xpath/IdFunction.java 22 Jun 2008 22:19:15 -0000 @@ -72,10 +72,11 @@ this.arg = arg; } + @SuppressWarnings("unchecked") public boolean matches(Node context) { Object ret = evaluate(context, 1, 1); - return !((Collection) ret).isEmpty(); + return !((Collection<Node>) ret).isEmpty(); } @Override Index: gnu/xml/xpath/LocalNameFunction.java =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/LocalNameFunction.java,v retrieving revision 1.5 diff -u -u -r1.5 LocalNameFunction.java --- gnu/xml/xpath/LocalNameFunction.java 22 Jun 2008 19:43:00 -0000 1.5 +++ gnu/xml/xpath/LocalNameFunction.java 22 Jun 2008 22:19:15 -0000 @@ -69,12 +69,12 @@ this.arg = arg; } - @Override + @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 _local_name(context, (Collection) val); + Collection<Node> val = (arg == null) ? Collections.singleton(context) : + (Collection<Node>) arg.evaluate(context, pos, len); + return _local_name(context, val); } public Expr clone(Object context) Index: gnu/xml/xpath/NameFunction.java =================================================================== RCS file: /sources/classpath/classpath/gnu/xml/xpath/NameFunction.java,v retrieving revision 1.5 diff -u -u -r1.5 NameFunction.java --- gnu/xml/xpath/NameFunction.java 22 Jun 2008 19:43:00 -0000 1.5 +++ gnu/xml/xpath/NameFunction.java 22 Jun 2008 22:19:15 -0000 @@ -77,12 +77,12 @@ this.arg = arg; } - @Override + @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 _name(context, (Collection) val); + return _name(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.4 diff -u -u -r1.4 ParenthesizedExpr.java --- gnu/xml/xpath/ParenthesizedExpr.java 22 Jun 2008 21:21:11 -0000 1.4 +++ gnu/xml/xpath/ParenthesizedExpr.java 22 Jun 2008 22:19:15 -0000 @@ -60,7 +60,7 @@ this.expr = expr; } - @Override + @Override @SuppressWarnings("unchecked") public Object evaluate(Node context, int pos, int len) { Object ret = expr.evaluate(context, pos, len);