Skip to content

Commit

Permalink
code style
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Jul 27, 2024
1 parent c7f54cb commit 78811a1
Show file tree
Hide file tree
Showing 19 changed files with 330 additions and 126 deletions.
47 changes: 29 additions & 18 deletions src/main/java/org/htmlunit/xpath/NodeSetDTM.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ public int nextNode() {
@Override
public int previousNode() {

if (!m_cacheNodes)
throw new RuntimeException(
XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_ITERATE, null));
if (!m_cacheNodes) {
throw new RuntimeException(
XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_ITERATE, null));
}

if ((m_next - 1) > 0) {
m_next--;
Expand All @@ -179,12 +180,17 @@ public boolean isFresh() {
@Override
public void runTo(final int index) {

if (!m_cacheNodes)
throw new RuntimeException(
XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_INDEX, null));
if (!m_cacheNodes) {
throw new RuntimeException(
XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_INDEX, null));
}

if ((index >= 0) && (m_next < m_firstFree)) m_next = index;
else m_next = m_firstFree - 1;
if ((index >= 0) && (m_next < m_firstFree)) {
m_next = index;
}
else {
m_next = m_firstFree - 1;
}
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -282,7 +288,9 @@ public void addNodeInDocOrder(final int node, final boolean test, final XPathCon
}
}

if (!foundit) addElement(node);
if (!foundit) {
addElement(node);
}
}

// checkDups();
Expand Down Expand Up @@ -348,9 +356,10 @@ public int getCurrentPos() {
@Override
public void setCurrentPos(final int i) {

if (!m_cacheNodes)
throw new RuntimeException(
XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_INDEX, null));
if (!m_cacheNodes) {
throw new RuntimeException(
XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NODESETDTM_CANNOT_INDEX, null));
}

m_next = i;
}
Expand All @@ -359,8 +368,9 @@ public void setCurrentPos(final int i) {
@Override
public int getCurrentNode() {

if (!m_cacheNodes)
throw new RuntimeException("This NodeSetDTM can not do indexing or counting functions!");
if (!m_cacheNodes) {
throw new RuntimeException("This NodeSetDTM can not do indexing or counting functions!");
}

final int saved = m_next;
// because nextNode always increments
Expand All @@ -386,10 +396,11 @@ public int getCurrentNode() {
@Override
public void setShouldCacheNodes(final boolean b) {

if (!isFresh())
throw new RuntimeException(
XPATHMessages.createXPATHMessage(
XPATHErrorResources.ER_CANNOT_CALL_SETSHOULDCACHENODE, null));
if (!isFresh()) {
throw new RuntimeException(
XPATHMessages.createXPATHMessage(
XPATHErrorResources.ER_CANNOT_CALL_SETSHOULDCACHENODE, null));
}
m_cacheNodes = b;
}

Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/htmlunit/xpath/XPathContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ public void reset() {
* @return A non-null ErrorListener reference.
*/
public final ErrorListener getErrorListener() {
if (null != m_errorListener) return m_errorListener;
if (null != m_errorListener) {
return m_errorListener;
}

if (null == m_defaultErrorListener) {
m_defaultErrorListener = new org.htmlunit.xpath.xml.utils.DefaultErrorHandler();
Expand All @@ -133,9 +135,10 @@ public final ErrorListener getErrorListener() {
* @param listener A non-null ErrorListener reference.
*/
public void setErrorListener(final ErrorListener listener) throws IllegalArgumentException {
if (listener == null)
throw new IllegalArgumentException(
XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, null));
if (listener == null) {
throw new IllegalArgumentException(
XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, null));
}
m_errorListener = listener;
}

Expand Down
31 changes: 23 additions & 8 deletions src/main/java/org/htmlunit/xpath/axes/LocPathIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ public void setRoot(final int context, final Object environment) {
m_currentContextNode = context; // only if top level?

// Yech, shouldn't have to do this. -sb
if (null == m_prefixResolver) m_prefixResolver = xctxt.getNamespaceContext();
if (null == m_prefixResolver) {
m_prefixResolver = xctxt.getNamespaceContext();
}

m_lastFetched = DTM.NULL;
m_foundLast = false;
Expand Down Expand Up @@ -225,11 +227,15 @@ public int getLength() {
// If we have already calculated the length, and the current predicate
// is the first predicate, then return the length. We don't cache
// the anything but the length of the list to the first predicate.
if (-1 != m_length && isPredicateTest && m_predicateIndex < 1) return m_length;
if (-1 != m_length && isPredicateTest && m_predicateIndex < 1) {
return m_length;
}

// I'm a bit worried about this one, since it doesn't have the
// checks found above. I suspect it's fine. -sb
if (m_foundLast) return m_pos;
if (m_foundLast) {
return m_pos;
}

// Create a clone, and count from the current position to the end
// of the list, not taking into account the current predicate and
Expand Down Expand Up @@ -260,7 +266,9 @@ public int getLength() {
pos++;
}

if (isPredicateTest && m_predicateIndex < 1) m_length = pos;
if (isPredicateTest && m_predicateIndex < 1) {
m_length = pos;
}

return pos;
}
Expand Down Expand Up @@ -357,7 +365,9 @@ protected int returnNextNode(final int nextNode) {

m_lastFetched = nextNode;

if (DTM.NULL == nextNode) m_foundLast = true;
if (DTM.NULL == nextNode) {
m_foundLast = true;
}

return nextNode;
}
Expand All @@ -372,15 +382,20 @@ public int getCurrentNode() {
@Override
public void runTo(final int index) {

if (m_foundLast || ((index >= 0) && (index <= getCurrentPos()))) return;
if (m_foundLast || ((index >= 0) && (index <= getCurrentPos()))) {
return;
}

if (-1 == index) {
while (DTM.NULL != nextNode())
while (DTM.NULL != nextNode()) {
;
}
}
else {
while (DTM.NULL != nextNode()) {
if (getCurrentPos() >= index) break;
if (getCurrentPos() >= index) {
break;
}
}
}
}
Expand Down
41 changes: 30 additions & 11 deletions src/main/java/org/htmlunit/xpath/axes/NodeSequence.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,16 @@ public void setRoot(final int nodeHandle, final Object environment) {
m_dtmMgr = xctxt.getDTMManager();
m_iter.setRoot(nodeHandle, environment);
if (!m_iter.isDocOrdered()) {
if (!hasCache()) setShouldCacheNodes(true);
if (!hasCache()) {
setShouldCacheNodes(true);
}
runTo(-1);
m_next = 0;
}
}
else assertion(false, "Can not setRoot on a non-iterated NodeSequence!");
else {
assertion(false, "Can not setRoot on a non-iterated NodeSequence!");
}
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -236,7 +240,9 @@ else if (cacheComplete() || (-1 != m_last) || (null == m_iter)) {
}
}

if (null == m_iter) return DTM.NULL;
if (null == m_iter) {
return DTM.NULL;
}

final int next = m_iter.nextNode();
if (DTM.NULL != next) {
Expand All @@ -247,10 +253,14 @@ else if (cacheComplete() || (-1 != m_last) || (null == m_iter)) {
}
else {
final int insertIndex = addNodeInDocOrder(next);
if (insertIndex >= 0) m_next++;
if (insertIndex >= 0) {
m_next++;
}
}
}
else m_next++;
else {
m_next++;
}
}
else {
// We have exhausted the iterator, and if there is a cache
Expand Down Expand Up @@ -285,7 +295,9 @@ public int previousNode() {
/** {@inheritDoc} */
@Override
public void detach() {
if (null != m_iter) m_iter.detach();
if (null != m_iter) {
m_iter.detach();
}
super.detach();
}

Expand Down Expand Up @@ -321,7 +333,9 @@ public void setShouldCacheNodes(final boolean b) {
setVector(new NodeVector());
}
}
else setVector(null);
else {
setVector(null);
}
}

/** {@inheritDoc} */
Expand All @@ -335,8 +349,9 @@ public int getCurrentPos() {
public void runTo(final int index) {
if (-1 == index) {
final int pos = m_next;
while (DTM.NULL != nextNode())
while (DTM.NULL != nextNode()) {
;
}
m_next = pos;
}
else if (m_next == index) {
Expand All @@ -345,13 +360,15 @@ else if (hasCache() && m_next < getVector().size()) {
m_next = index;
}
else if ((null == getVector()) && (index < m_next)) {
while ((m_next >= index) && DTM.NULL != previousNode())
while ((m_next >= index) && DTM.NULL != previousNode()) {
;
}
}
else {
while ((m_next < index) && DTM.NULL != nextNode())
while ((m_next < index) && DTM.NULL != nextNode()) {
;
}
}
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -414,7 +431,9 @@ public DTMIterator cloneWithReset() throws CloneNotSupportedException {
@Override
public Object clone() throws CloneNotSupportedException {
final NodeSequence clone = (NodeSequence) super.clone();
if (null != m_iter) clone.m_iter = (DTMIterator) m_iter.clone();
if (null != m_iter) {
clone.m_iter = (DTMIterator) m_iter.clone();
}

return clone;
}
Expand Down
Loading

0 comments on commit 78811a1

Please sign in to comment.