Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Dec 8, 2023
1 parent 510f5f4 commit 9c03c0c
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 40 deletions.
8 changes: 2 additions & 6 deletions src/main/java/org/htmlunit/xpath/NodeSetDTM.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ public void addNodes(DTMIterator iterator) {
* @throws RuntimeException thrown if this NodeSetDTM is not of a mutable type.
*/
public void addNodeInDocOrder(int node, boolean test, XPathContext support) {
int insertIndex = -1;

if (test) {

// This needs to do a binary search, but a binary search
Expand All @@ -268,12 +266,10 @@ public void addNodeInDocOrder(int node, boolean test, XPathContext support) {
}

if (i != -2) {
insertIndex = i + 1;

insertElementAt(node, insertIndex);
insertElementAt(node, i + 1);
}
} else {
insertIndex = this.size();
int insertIndex = this.size();

boolean foundit = false;

Expand Down
8 changes: 0 additions & 8 deletions src/main/java/org/htmlunit/xpath/XPathContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,19 @@ public XPathContext() {
public XPathContext(boolean recursiveVarContext) {
m_prefixResolvers.push(null);
m_currentNodes.push(DTM.NULL);
m_currentExpressionNodes.push(DTM.NULL);
}

/** Reset for new run. */
public void reset() {
m_dtmManager = DTMManager.newInstance();

m_axesIteratorStack.removeAllElements();
m_currentExpressionNodes.removeAllElements();
m_currentNodes.removeAllElements();
m_predicatePos.removeAllElements();
m_prefixResolvers.removeAllElements();

m_prefixResolvers.push(null);
m_currentNodes.push(DTM.NULL);
m_currentExpressionNodes.push(DTM.NULL);
}

// =================================================
Expand Down Expand Up @@ -195,13 +192,11 @@ public final int getCurrentNode() {
*/
public final void pushCurrentNodeAndExpression(int cn) {
m_currentNodes.push(cn);
m_currentExpressionNodes.push(cn);
}

/** Set the current context node. */
public final void popCurrentNodeAndExpression() {
m_currentNodes.pop();
m_currentExpressionNodes.pop();
}

/**
Expand All @@ -218,9 +213,6 @@ public final void popCurrentNode() {
m_currentNodes.pop();
}

/** A stack of the current sub-expression nodes. */
private final Stack<Integer> m_currentExpressionNodes = new Stack<>();

private final Stack<Integer> m_predicatePos = new Stack<>();

public final int getPredicatePos() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ public int getAxis() {
public boolean deepEquals(Expression expr) {
if (!super.deepEquals(expr)) return false;

if (m_axis != ((DescendantIterator) expr).m_axis) return false;

return true;
return m_axis == ((DescendantIterator) expr).m_axis;
}
}
4 changes: 1 addition & 3 deletions src/main/java/org/htmlunit/xpath/axes/OneStepIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ public int getAxis() {
public boolean deepEquals(Expression expr) {
if (!super.deepEquals(expr)) return false;

if (m_axis != ((OneStepIterator) expr).m_axis) return false;

return true;
return m_axis == ((OneStepIterator) expr).m_axis;
}
}
3 changes: 1 addition & 2 deletions src/main/java/org/htmlunit/xpath/axes/WalkerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,6 @@ private static StepPattern createDefaultStepPattern(final Compiler compiler, fin

final int stepType = compiler.getOp(opPos);

int whatToShow = compiler.getWhatToShow(opPos);
StepPattern ai = null;
final int axis;

Expand Down Expand Up @@ -859,7 +858,7 @@ private static StepPattern createDefaultStepPattern(final Compiler compiler, fin
new Object[] {Integer.toString(stepType)}));
}
if (null == ai) {
whatToShow = compiler.getWhatToShow(opPos); // %REVIEW%
int whatToShow = compiler.getWhatToShow(opPos); // %REVIEW%
ai =
new StepPattern(
whatToShow, compiler.getStepNS(opPos), compiler.getStepLocalName(opPos), axis);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/htmlunit/xpath/compiler/OpMapVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class OpMapVector {
protected int[] m_map; // IntStack is trying to see this directly

/** Position where size of array is kept */
protected int m_lengthPos = 0;
protected int m_lengthPos;

/** Size of array */
protected int m_mapSize;
Expand All @@ -41,7 +41,6 @@ public class OpMapVector {
* @param blocksize Size of block to allocate
*/
public OpMapVector(int blocksize, int increaseSize, int lengthPos) {

m_blocksize = increaseSize;
m_mapSize = blocksize;
m_lengthPos = lengthPos;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/htmlunit/xpath/compiler/XPathParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.htmlunit.xpath.res.XPATHMessages;
import org.htmlunit.xpath.xml.utils.PrefixResolver;

import java.util.Objects;

/**
* Tokenizes and parses XPath expressions. This should really be named XPathParserImpl, and may be
* renamed in the future.
Expand Down Expand Up @@ -209,7 +211,7 @@ public ErrorListener getErrorListener() {
* current token matches the string, else false.
*/
final boolean tokenIs(String s) {
return (m_token != null) ? (m_token.equals(s)) : (s == null);
return Objects.equals(m_token, s);
}

/**
Expand Down Expand Up @@ -259,7 +261,7 @@ private boolean lookahead(String s, int n) {
if ((m_queueMark + n) <= m_ops.getTokenQueueSize()) {
String lookahead = (String) m_ops.m_tokenQueue.get(m_queueMark + (n - 1));

isToken = (lookahead != null) ? lookahead.equals(s) : (s == null);
isToken = Objects.equals(lookahead, s);
} else {
isToken = null == s;
}
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/org/htmlunit/xpath/functions/FuncId.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,16 @@ private List<String> getNodesByID(
boolean mayBeMore) {

if (null != refval) {
String ref = null;
// DOMHelper dh = xctxt.getDOMHelper();
StringTokenizer tokenizer = new StringTokenizer(refval);
boolean hasMore = tokenizer.hasMoreTokens();
DTM dtm = xctxt.getDTM(docContext);

while (hasMore) {
ref = tokenizer.nextToken();
String ref = tokenizer.nextToken();
hasMore = tokenizer.hasMoreTokens();

if ((null != usedrefs) && usedrefs.contains(ref)) {
ref = null;

continue;
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/htmlunit/xpath/functions/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ public void callVisitors(XPathVisitor visitor) {
/** {@inheritDoc} */
@Override
public boolean deepEquals(Expression expr) {
if (!isSameClass(expr)) return false;

return true;
return isSameClass(expr);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/htmlunit/xpath/patterns/StepPattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public StepPattern getRelativePathPattern() {
/**
* Set the list of predicate expressions for this pattern step.
*
* @return List of expression objects.
* @return Array of expression objects.
*/
public Expression[] getPredicates() {
return m_predicates;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,10 +854,8 @@ public boolean isEqualNode(Node arg) {

if (getNodeValue() == null) {
return arg.getNodeValue() == null;
} else if (!getNodeValue().equals(arg.getNodeValue())) {
return false;
}
return true;
return getNodeValue().equals(arg.getNodeValue());
}

/** {@inheritDoc} */
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/org/htmlunit/xpath/AbstractXPathTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ public void assertGetByXpathException(
Exception exception =
Assertions.assertThrows(
RuntimeException.class,
() -> {
XPathHelper.getByXPath(doc, xPath, null, false);
});
() -> XPathHelper.getByXPath(doc, xPath, null, false));
Assertions.assertEquals(exMsg, exception.getMessage());
Assertions.assertEquals(exCauseMsg, exception.getCause().getMessage());
}
Expand Down

0 comments on commit 9c03c0c

Please sign in to comment.