use of org.apache.xpath.axes.AxesWalker in project j2objc by google.
the class RedundentExprEliminator method countSteps.
/**
* Count the steps in a given location path.
*
* @param lpi The location path iterator that owns the steps.
* @return The number of steps in the given location path.
*/
protected int countSteps(LocPathIterator lpi) {
if (lpi instanceof WalkingIterator) {
WalkingIterator wi = (WalkingIterator) lpi;
AxesWalker aw = wi.getFirstWalker();
int count = 0;
while (null != aw) {
count++;
aw = aw.getNextWalker();
}
return count;
} else
return 1;
}
use of org.apache.xpath.axes.AxesWalker in project j2objc by google.
the class RedundentExprEliminator method createIteratorFromSteps.
/**
* Create a new WalkingIterator from the steps in another WalkingIterator.
*
* @param wi The iterator from where the steps will be taken.
* @param numSteps The number of steps from the first to copy into the new
* iterator.
* @return The new iterator.
*/
protected WalkingIterator createIteratorFromSteps(final WalkingIterator wi, int numSteps) {
WalkingIterator newIter = new WalkingIterator(wi.getPrefixResolver());
try {
AxesWalker walker = (AxesWalker) wi.getFirstWalker().clone();
newIter.setFirstWalker(walker);
walker.setLocPathIterator(newIter);
for (int i = 1; i < numSteps; i++) {
AxesWalker next = (AxesWalker) walker.getNextWalker().clone();
walker.setNextWalker(next);
next.setLocPathIterator(newIter);
walker = next;
}
walker.setNextWalker(null);
} catch (CloneNotSupportedException cnse) {
throw new WrappedRuntimeException(cnse);
}
return newIter;
}
use of org.apache.xpath.axes.AxesWalker in project robovm by robovm.
the class RedundentExprEliminator method stepsEqual.
/**
* Compare a given number of steps between two iterators, to see if they are equal.
*
* @param iter1 The first iterator to compare.
* @param iter2 The second iterator to compare.
* @param numSteps The number of steps to compare.
* @return true If the given number of steps are equal.
*
*/
protected boolean stepsEqual(WalkingIterator iter1, WalkingIterator iter2, int numSteps) {
AxesWalker aw1 = iter1.getFirstWalker();
AxesWalker aw2 = iter2.getFirstWalker();
for (int i = 0; (i < numSteps); i++) {
if ((null == aw1) || (null == aw2))
return false;
if (!aw1.deepEquals(aw2))
return false;
aw1 = aw1.getNextWalker();
aw2 = aw2.getNextWalker();
}
assertion((null != aw1) || (null != aw2), "Total match is incorrect!");
return true;
}
Aggregations