package gnu.xml.xpath;
+import gnu.java.lang.CPStringBuilder;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
*/
final Test[] tests;
- public Selector(int axis, List tests)
+ public Selector(int axis, List<? extends Test> tests)
{
this.axis = axis;
int len = tests.size();
return count;
}
+
+ @Override
public Object evaluate(Node context, int pos, int len)
{
- Set acc = new LinkedHashSet();
+ Set<Node> acc = new LinkedHashSet<Node>();
addCandidates(context, acc);
- List candidates = new ArrayList(acc);
- List ret = filterCandidates(candidates, false);
+ List<Node> candidates = new ArrayList<Node>(acc);
+ List<Node> ret = filterCandidates(candidates, false);
return ret;
}
- Collection evaluate(Node context, Collection ns)
+ Collection<Node> evaluate(Node context, Collection<Node> ns)
{
- Set acc = new LinkedHashSet();
- for (Iterator i = ns.iterator(); i.hasNext(); )
- addCandidates((Node) i.next(), acc);
- List candidates = new ArrayList(acc);
- List ret = filterCandidates(candidates, true);
+ Set<Node> acc = new LinkedHashSet<Node>();
+ for (Iterator<Node> i = ns.iterator(); i.hasNext(); )
+ addCandidates(i.next(), acc);
+ List<Node> candidates = new ArrayList<Node>(acc);
+ List<Node> ret = filterCandidates(candidates, true);
return ret;
}
/**
* Filter the given list of candidates according to the node tests.
*/
- List filterCandidates(List candidates, boolean cascade)
+ List<Node> filterCandidates(List<Node> candidates, boolean cascade)
{
int len = candidates.size();
int tlen = tests.length;
for (int j = 0; j < tlen && len > 0; j++)
{
Test test = tests[j];
- List successful = new ArrayList(len);
+ List<Node> successful = new ArrayList<Node>(len);
for (int i = 0; i < len; i++)
{
- Node node = (Node) candidates.get(i);
+ Node node = candidates.get(i);
if (cascade)
{
// Documents and DocumentFragments should be considered
return candidates;
}
- void addCandidates(Node context, Collection candidates)
+ void addCandidates(Node context, Collection<Node> candidates)
{
// Build list of candidates
switch (axis)
}
}
- void addChildNodes(Node context, Collection acc, boolean recurse)
+ void addChildNodes(Node context, Collection<Node> acc, boolean recurse)
{
Node child = context.getFirstChild();
while (child != null)
}
}
- void addParentNode(Node context, Collection acc, boolean recurse)
+ void addParentNode(Node context, Collection<Node> acc, boolean recurse)
{
Node parent = (context.getNodeType() == Node.ATTRIBUTE_NODE) ?
((Attr) context).getOwnerElement() : context.getParentNode();
}
}
- void addFollowingNodes(Node context, Collection acc, boolean recurse)
+ void addFollowingNodes(Node context, Collection<Node> acc, boolean recurse)
{
if (context != null && recurse)
addChildNodes(context, acc, true);
}
}
- void addPrecedingNodes(Node context, Collection acc, boolean recurse)
+ void addPrecedingNodes(Node context, Collection<Node> acc, boolean recurse)
{
Node cur = (context.getNodeType() == Node.ATTRIBUTE_NODE) ? null :
context.getPreviousSibling();
}
}
- void addAttributes(Node context, Collection acc)
+ void addAttributes(Node context, Collection<Node> acc)
{
NamedNodeMap attrs = context.getAttributes();
if (attrs != null)
}
}
- void addNamespaceAttributes(Node context, Collection acc)
+ void addNamespaceAttributes(Node context, Collection<Node> acc)
{
NamedNodeMap attrs = context.getAttributes();
if (attrs != null)
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);
public String toString()
{
- StringBuffer buf = new StringBuffer();
+ CPStringBuilder buf = new CPStringBuilder();
switch (axis)
{
case ANCESTOR: