From c460996e75df489d6bbcb732763c10d01e62516f Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Thu, 30 Oct 2014 12:20:21 +0000 Subject: [PATCH] Statement unnecessarily nested within else clause. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1635471 13f79535-47bb-0310-9956-ffa450edef68 --- .../trie/AbstractPatriciaTrie.java | 89 ++++++++----------- 1 file changed, 36 insertions(+), 53 deletions(-) diff --git a/src/main/java/org/apache/commons/collections4/trie/AbstractPatriciaTrie.java b/src/main/java/org/apache/commons/collections4/trie/AbstractPatriciaTrie.java index e8c99049b..b79b7d084 100644 --- a/src/main/java/org/apache/commons/collections4/trie/AbstractPatriciaTrie.java +++ b/src/main/java/org/apache/commons/collections4/trie/AbstractPatriciaTrie.java @@ -609,9 +609,8 @@ abstract class AbstractPatriciaTrie extends AbstractBitwiseTrie { TrieEntry nextEntry(final TrieEntry node) { if (node == null) { return firstEntry(); - } else { - return nextEntryImpl(node.predecessor, node, null); } + return nextEntryImpl(node.predecessor, node, null); } /** @@ -787,9 +786,8 @@ abstract class AbstractPatriciaTrie extends AbstractBitwiseTrie { final TrieEntry entry = lastEntry(); if (entry != null) { return entry.getKey(); - } else { - throw new NoSuchElementException(); } + throw new NoSuchElementException(); } public K nextKey(final K key) { @@ -800,9 +798,8 @@ abstract class AbstractPatriciaTrie extends AbstractBitwiseTrie { if (entry != null) { final TrieEntry nextEntry = nextEntry(entry); return nextEntry != null ? nextEntry.getKey() : null; - } else { - return null; } + return null; } public K previousKey(final K key) { @@ -813,9 +810,8 @@ abstract class AbstractPatriciaTrie extends AbstractBitwiseTrie { if (entry != null) { final TrieEntry prevEntry = previousEntry(entry); return prevEntry != null ? prevEntry.getKey() : null; - } else { - return null; } + return null; } public OrderedMapIterator mapIterator() { @@ -889,13 +885,12 @@ abstract class AbstractPatriciaTrie extends AbstractBitwiseTrie { // If data in root, and more after -- return it. if (size() > 1) { return nextEntry(root); - } else { // If no more after, no higher entry. - return null; } - } else { - // Root is empty & we want something after empty, return first. - return firstEntry(); + // If no more after, no higher entry. + return null; } + // Root is empty & we want something after empty, return first. + return firstEntry(); } final TrieEntry found = getNearestEntryForKey(key, lengthInBits); @@ -956,9 +951,8 @@ abstract class AbstractPatriciaTrie extends AbstractBitwiseTrie { if (lengthInBits == 0) { if (!root.isEmpty()) { return root; - } else { - return firstEntry(); } + return firstEntry(); } final TrieEntry found = getNearestEntryForKey(key, lengthInBits); @@ -978,9 +972,8 @@ abstract class AbstractPatriciaTrie extends AbstractBitwiseTrie { } else if (KeyAnalyzer.isNullBitKey(bitIndex)) { if (!root.isEmpty()) { return root; - } else { - return firstEntry(); } + return firstEntry(); } else if (KeyAnalyzer.isEqualBitKey(bitIndex)) { return found; } @@ -1054,9 +1047,8 @@ abstract class AbstractPatriciaTrie extends AbstractBitwiseTrie { if (lengthInBits == 0) { if (!root.isEmpty()) { return root; - } else { - return null; } + return null; } final TrieEntry found = getNearestEntryForKey(key, lengthInBits); @@ -1076,9 +1068,8 @@ abstract class AbstractPatriciaTrie extends AbstractBitwiseTrie { } else if (KeyAnalyzer.isNullBitKey(bitIndex)) { if (!root.isEmpty()) { return root; - } else { - return null; } + return null; } else if (KeyAnalyzer.isEqualBitKey(bitIndex)) { return found; } @@ -1199,34 +1190,29 @@ abstract class AbstractPatriciaTrie extends AbstractBitwiseTrie { if (start.predecessor.right == start) { if (isValidUplink(start.predecessor.left, start.predecessor)) { return start.predecessor.left; - } else { - return followRight(start.predecessor.left); - } - } else { - TrieEntry node = start.predecessor; - while (node.parent != null && node == node.parent.left) { - node = node.parent; - } - - if (node.parent == null) { // can be null if we're looking up root. - return null; - } - - if (isValidUplink(node.parent.left, node.parent)) { - if (node.parent.left == root) { - if (root.isEmpty()) { - return null; - } else { - return root; - } - - } else { - return node.parent.left; - } - } else { - return followRight(node.parent.left); } + return followRight(start.predecessor.left); } + TrieEntry node = start.predecessor; + while (node.parent != null && node == node.parent.left) { + node = node.parent; + } + + if (node.parent == null) { // can be null if we're looking up root. + return null; + } + + if (isValidUplink(node.parent.left, node.parent)) { + if (node.parent.left == root) { + if (root.isEmpty()) { + return null; + } + return root; + + } + return node.parent.left; + } + return followRight(node.parent.left); } /** @@ -1240,9 +1226,8 @@ abstract class AbstractPatriciaTrie extends AbstractBitwiseTrie { final TrieEntry parentOfSubtree) { if (node == null) { return firstEntry(); - } else { - return nextEntryImpl(node.predecessor, node, parentOfSubtree); } + return nextEntryImpl(node.predecessor, node, parentOfSubtree); } /** @@ -1805,9 +1790,8 @@ abstract class AbstractPatriciaTrie extends AbstractBitwiseTrie { final int ret = getKeyAnalyzer().compare(key, fromKey); if (fromInclusive || forceInclusive) { return ret >= 0; - } else { - return ret > 0; } + return ret > 0; } /** @@ -1820,9 +1804,8 @@ abstract class AbstractPatriciaTrie extends AbstractBitwiseTrie { final int ret = getKeyAnalyzer().compare(key, toKey); if (toInclusive || forceInclusive) { return ret <= 0; - } else { - return ret < 0; } + return ret < 0; } /**