summaryrefslogtreecommitdiff
path: root/libjava/classpath/gnu/xml/xpath/Steps.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/gnu/xml/xpath/Steps.java')
-rw-r--r--libjava/classpath/gnu/xml/xpath/Steps.java61
1 files changed, 34 insertions, 27 deletions
diff --git a/libjava/classpath/gnu/xml/xpath/Steps.java b/libjava/classpath/gnu/xml/xpath/Steps.java
index 9ef6cd35f3d..427fbe20138 100644
--- a/libjava/classpath/gnu/xml/xpath/Steps.java
+++ b/libjava/classpath/gnu/xml/xpath/Steps.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.xml.xpath;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
@@ -56,14 +58,14 @@ public final class Steps
extends Path
{
- final LinkedList path;
+ final LinkedList<Expr> path;
public Steps()
{
- this(new LinkedList());
+ this(new LinkedList<Expr>());
}
- Steps(LinkedList path)
+ Steps(LinkedList<Expr> path)
{
this.path = path;
}
@@ -84,10 +86,8 @@ public final class Steps
if (pos > 0)
{
Pattern left = (Pattern) path.get(pos - 1);
- Iterator j = possibleContexts(right, context).iterator();
- while (j.hasNext())
+ for (Node candidate : possibleContexts(right, context))
{
- Node candidate = (Node) j.next();
if (left.matches(candidate) &&
matches(candidate, pos - 1))
{
@@ -104,12 +104,12 @@ public final class Steps
* Essentially the reverse of Selector.addCandidates.
* The idea is to determine possible context nodes for a match.
*/
- Collection possibleContexts(Pattern pattern, Node context)
+ Collection<Node> possibleContexts(Pattern pattern, Node context)
{
if (pattern instanceof Selector)
{
Selector s = (Selector) pattern;
- Collection candidates = new LinkedHashSet();
+ Collection<Node> candidates = new LinkedHashSet<Node>();
switch (s.axis)
{
case Selector.PARENT:
@@ -157,46 +157,53 @@ public final class Steps
}
return candidates;
}
- return Collections.EMPTY_SET;
+ return Collections.emptySet();
}
+ @Override
public Object evaluate(Node context, int pos, int len)
{
//System.err.println(toString()+" evaluate");
// Left to right
- Iterator i = path.iterator();
- Expr lhs = (Expr) i.next();
+ Iterator<Expr> i = path.iterator();
+ Expr lhs = i.next();
Object val = lhs.evaluate(context, pos, len);
//System.err.println("\tevaluate "+lhs+" = "+val);
while (val instanceof Collection && i.hasNext())
{
Path rhs = (Path) i.next();
- val = rhs.evaluate(context, (Collection) val);
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> nodes = (Collection<Node>) val;
+ val = rhs.evaluate(context, nodes);
//System.err.println("\tevaluate "+rhs+" = "+val);
}
return val;
}
- Collection evaluate(Node context, Collection ns)
+ @Override
+ Collection<Node> evaluate(Node context, Collection<Node> ns)
{
// Left to right
- Iterator i = path.iterator();
- Expr lhs = (Expr) i.next();
+ Iterator<Expr> i = path.iterator();
+ Expr lhs = i.next();
if (lhs instanceof Path)
{
ns = ((Path) lhs).evaluate(context, ns);
}
else
{
- Set acc = new LinkedHashSet();
+ Set<Node> acc = new LinkedHashSet<Node>();
int pos = 1, len = ns.size();
- for (Iterator j = ns.iterator(); j.hasNext(); )
+ for (Node node : ns)
{
- Node node = (Node) j.next();
Object ret = lhs.evaluate(node, pos++, len);
if (ret instanceof Collection)
{
- acc.addAll((Collection) ret);
+ /* Suppression is safe, as we know context produces Collection<Node> */
+ @SuppressWarnings("unchecked")
+ Collection<Node> nodes = (Collection<Node>) ret;
+ acc.addAll(nodes);
}
}
ns = acc;
@@ -212,19 +219,19 @@ public final class Steps
public Expr clone(Object context)
{
int len = path.size();
- LinkedList path2 = new LinkedList();
+ LinkedList<Expr> path2 = new LinkedList<Expr>();
for (int i = 0; i < len; i++)
{
- path2.add(((Expr) path.get(i)).clone(context));
+ path2.add(path.get(i).clone(context));
}
return new Steps(path2);
}
public boolean references(QName var)
{
- for (Iterator i = path.iterator(); i.hasNext(); )
+ for (Iterator<Expr> i = path.iterator(); i.hasNext(); )
{
- if (((Expr) i.next()).references(var))
+ if (i.next().references(var))
{
return true;
}
@@ -234,16 +241,16 @@ public final class Steps
public String toString()
{
- StringBuffer buf = new StringBuffer();
- Iterator i = path.iterator();
- Expr expr = (Expr) i.next();
+ CPStringBuilder buf = new CPStringBuilder();
+ Iterator<Expr> i = path.iterator();
+ Expr expr = i.next();
if (!(expr instanceof Root))
{
buf.append(expr);
}
while (i.hasNext())
{
- expr = (Expr) i.next();
+ expr = i.next();
buf.append('/');
buf.append(expr);
}