@Test public void testEmptyTrie2WithSize1() { UrlTrie trie = new UrlTrie(_property, new ArrayList<String>()); UrlTriePostOrderIterator iterator = new UrlTriePostOrderIterator(trie, 1); Assert.assertFalse(iterator.hasNext()); }
@Override public boolean hasNext() { if (_toReturn != null) { return true; } while (!_unprocessed.isEmpty() || !isStoppingNode(_currentNode)) { if (!isStoppingNode(_currentNode)) { _unprocessed.push(_currentNode); _currentPrefixSb.append(_currentNode.getValue()); Map.Entry<Character, UrlTrieNode> next = _currentNode.children.firstEntry(); if (next == null) { _currentNode = null; } else { _currentNode = next.getValue(); } } else { UrlTrieNode peekNode = _unprocessed.peek(); if (_currentNode != null || peekNode.children.isEmpty() || peekNode.children.lastEntry().getValue() == _lastVisited) { if (_currentNode != null) { _toReturn = _currentNode; } else { _toReturn = _unprocessed.pop(); _currentPrefixSb.setLength(_currentPrefixSb.length() - 1); } UrlTrieNode parent = _unprocessed.peek(); if (parent == null) { return true; } Map.Entry<Character, UrlTrieNode> sibling = parent.children.higherEntry(_toReturn.getValue()); if (sibling == null) { _currentNode = null; } else { _currentNode = sibling.getValue(); } return true; } else { _currentNode = peekNode; } } } if (_lastVisited == null && _currentNode.getSize() > 0) { _toReturn = _currentNode; return true; } return false; }
UrlTriePostOrderIterator implements Iterator<Pair<String, UrlTrieNode>> { @Override public boolean hasNext() { if (_toReturn != null) { return true; } while (!_unprocessed.isEmpty() || !isStoppingNode(_currentNode)) { if (!isStoppingNode(_currentNode)) { _unprocessed.push(_currentNode); _currentPrefixSb.append(_currentNode.getValue()); Map.Entry<Character, UrlTrieNode> next = _currentNode.children.firstEntry(); if (next == null) { _currentNode = null; } else { _currentNode = next.getValue(); } } else { UrlTrieNode peekNode = _unprocessed.peek(); if (_currentNode != null || peekNode.children.isEmpty() || peekNode.children.lastEntry().getValue() == _lastVisited) { if (_currentNode != null) { _toReturn = _currentNode; } else { _toReturn = _unprocessed.pop(); _currentPrefixSb.setLength(_currentPrefixSb.length() - 1); } UrlTrieNode parent = _unprocessed.peek(); if (parent == null) { return true; } Map.Entry<Character, UrlTrieNode> sibling = parent.children.higherEntry(_toReturn.getValue()); if (sibling == null) { _currentNode = null; } else { _currentNode = sibling.getValue(); } return true; } else { _currentNode = peekNode; } } } if (_lastVisited == null && _currentNode.getSize() > 0) { _toReturn = _currentNode; return true; } return false; } }
UrlTriePostOrderIterator implements Iterator<Pair<String, UrlTrieNode>> { @Override public boolean hasNext() { if (_toReturn != null) { return true; } while (!_unprocessed.isEmpty() || !isStoppingNode(_currentNode)) { if (!isStoppingNode(_currentNode)) { _unprocessed.push(_currentNode); _currentPrefixSb.append(_currentNode.getValue()); Map.Entry<Character, UrlTrieNode> next = _currentNode.children.firstEntry(); if (next == null) { _currentNode = null; } else { _currentNode = next.getValue(); } } else { UrlTrieNode peekNode = _unprocessed.peek(); if (_currentNode != null || peekNode.children.isEmpty() || peekNode.children.lastEntry().getValue() == _lastVisited) { if (_currentNode != null) { _toReturn = _currentNode; } else { _toReturn = _unprocessed.pop(); _currentPrefixSb.setLength(_currentPrefixSb.length() - 1); } UrlTrieNode parent = _unprocessed.peek(); if (parent == null) { return true; } Map.Entry<Character, UrlTrieNode> sibling = parent.children.higherEntry(_toReturn.getValue()); if (sibling == null) { _currentNode = null; } else { _currentNode = sibling.getValue(); } return true; } else { _currentNode = peekNode; } } } if (_lastVisited == null && _currentNode.getSize() > 0) { _toReturn = _currentNode; return true; } return false; } UrlTriePostOrderIterator(UrlTrie trie, int stoppingSize); }
UrlTriePostOrderIterator implements Iterator<Pair<String, UrlTrieNode>> { @Override public boolean hasNext() { if (_toReturn != null) { return true; } while (!_unprocessed.isEmpty() || !isStoppingNode(_currentNode)) { if (!isStoppingNode(_currentNode)) { _unprocessed.push(_currentNode); _currentPrefixSb.append(_currentNode.getValue()); Map.Entry<Character, UrlTrieNode> next = _currentNode.children.firstEntry(); if (next == null) { _currentNode = null; } else { _currentNode = next.getValue(); } } else { UrlTrieNode peekNode = _unprocessed.peek(); if (_currentNode != null || peekNode.children.isEmpty() || peekNode.children.lastEntry().getValue() == _lastVisited) { if (_currentNode != null) { _toReturn = _currentNode; } else { _toReturn = _unprocessed.pop(); _currentPrefixSb.setLength(_currentPrefixSb.length() - 1); } UrlTrieNode parent = _unprocessed.peek(); if (parent == null) { return true; } Map.Entry<Character, UrlTrieNode> sibling = parent.children.higherEntry(_toReturn.getValue()); if (sibling == null) { _currentNode = null; } else { _currentNode = sibling.getValue(); } return true; } else { _currentNode = peekNode; } } } if (_lastVisited == null && _currentNode.getSize() > 0) { _toReturn = _currentNode; return true; } return false; } UrlTriePostOrderIterator(UrlTrie trie, int stoppingSize); @Override boolean hasNext(); @Override Pair<String, UrlTrieNode> next(); @Override void remove(); }
UrlTriePostOrderIterator implements Iterator<Pair<String, UrlTrieNode>> { @Override public boolean hasNext() { if (_toReturn != null) { return true; } while (!_unprocessed.isEmpty() || !isStoppingNode(_currentNode)) { if (!isStoppingNode(_currentNode)) { _unprocessed.push(_currentNode); _currentPrefixSb.append(_currentNode.getValue()); Map.Entry<Character, UrlTrieNode> next = _currentNode.children.firstEntry(); if (next == null) { _currentNode = null; } else { _currentNode = next.getValue(); } } else { UrlTrieNode peekNode = _unprocessed.peek(); if (_currentNode != null || peekNode.children.isEmpty() || peekNode.children.lastEntry().getValue() == _lastVisited) { if (_currentNode != null) { _toReturn = _currentNode; } else { _toReturn = _unprocessed.pop(); _currentPrefixSb.setLength(_currentPrefixSb.length() - 1); } UrlTrieNode parent = _unprocessed.peek(); if (parent == null) { return true; } Map.Entry<Character, UrlTrieNode> sibling = parent.children.higherEntry(_toReturn.getValue()); if (sibling == null) { _currentNode = null; } else { _currentNode = sibling.getValue(); } return true; } else { _currentNode = peekNode; } } } if (_lastVisited == null && _currentNode.getSize() > 0) { _toReturn = _currentNode; return true; } return false; } UrlTriePostOrderIterator(UrlTrie trie, int stoppingSize); @Override boolean hasNext(); @Override Pair<String, UrlTrieNode> next(); @Override void remove();  }