change getChildren return type (#1674)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Ratan Rai Sur 5 years ago committed by GitHub
parent 3c9e54bdab
commit 5000dbf789
  1. 4
      ethereum/trie/src/main/java/tech/pegasys/pantheon/ethereum/trie/BranchNode.java
  2. 4
      ethereum/trie/src/main/java/tech/pegasys/pantheon/ethereum/trie/ExtensionNode.java
  3. 5
      ethereum/trie/src/main/java/tech/pegasys/pantheon/ethereum/trie/LeafNode.java
  4. 2
      ethereum/trie/src/main/java/tech/pegasys/pantheon/ethereum/trie/Node.java
  5. 5
      ethereum/trie/src/main/java/tech/pegasys/pantheon/ethereum/trie/NullNode.java
  6. 2
      ethereum/trie/src/main/java/tech/pegasys/pantheon/ethereum/trie/StoredNode.java
  7. 6
      ethereum/trie/src/main/java/tech/pegasys/pantheon/ethereum/trie/TrieNodeDecoder.java
  8. 2
      ethereum/trie/src/test/java/tech/pegasys/pantheon/ethereum/trie/TrieNodeDecoderTest.java

@ -76,8 +76,8 @@ class BranchNode<V> implements Node<V> {
}
@Override
public Optional<List<Node<V>>> getChildren() {
return Optional.of(Collections.unmodifiableList(children));
public List<Node<V>> getChildren() {
return Collections.unmodifiableList(children);
}
public Node<V> child(final byte index) {

@ -64,8 +64,8 @@ class ExtensionNode<V> implements Node<V> {
}
@Override
public Optional<List<Node<V>>> getChildren() {
return Optional.of(Collections.singletonList(child));
public List<Node<V>> getChildren() {
return Collections.singletonList(child);
}
public Node<V> getChild() {

@ -21,6 +21,7 @@ import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
@ -66,8 +67,8 @@ class LeafNode<V> implements Node<V> {
}
@Override
public Optional<List<Node<V>>> getChildren() {
return Optional.empty();
public List<Node<V>> getChildren() {
return Collections.emptyList();
}
@Override

@ -28,7 +28,7 @@ public interface Node<V> {
Optional<V> getValue();
Optional<List<Node<V>>> getChildren();
List<Node<V>> getChildren();
BytesValue getRlp();

@ -15,6 +15,7 @@ package tech.pegasys.pantheon.ethereum.trie;
import tech.pegasys.pantheon.util.bytes.Bytes32;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
@ -50,8 +51,8 @@ class NullNode<V> implements Node<V> {
}
@Override
public Optional<List<Node<V>>> getChildren() {
return Optional.empty();
public List<Node<V>> getChildren() {
return Collections.emptyList();
}
@Override

@ -65,7 +65,7 @@ class StoredNode<V> implements Node<V> {
}
@Override
public Optional<List<Node<V>>> getChildren() {
public List<Node<V>> getChildren() {
return load().getChildren();
}

@ -57,7 +57,7 @@ public class TrieNodeDecoder {
nodes.add(node);
final List<Node<BytesValue>> toProcess = new ArrayList<>();
node.getChildren().ifPresent(toProcess::addAll);
toProcess.addAll(node.getChildren());
while (!toProcess.isEmpty()) {
final Node<BytesValue> currentNode = toProcess.remove(0);
if (Objects.equals(NullNode.instance(), currentNode)) {
@ -68,7 +68,7 @@ public class TrieNodeDecoder {
if (!currentNode.isReferencedByHash()) {
// If current node is inlined, that means we can process its children
currentNode.getChildren().ifPresent(toProcess::addAll);
toProcess.addAll(currentNode.getChildren());
}
}
@ -140,7 +140,7 @@ public class TrieNodeDecoder {
final Node<BytesValue> nextNode = currentNodes.remove(0);
final List<Node<BytesValue>> children = new ArrayList<>();
nextNode.getChildren().ifPresent(children::addAll);
children.addAll(nextNode.getChildren());
while (!children.isEmpty()) {
Node<BytesValue> child = children.remove(0);
if (Objects.equals(child, NullNode.instance())) {

@ -114,7 +114,7 @@ public class TrieNodeDecoderTest {
assertThat(depth0And1Nodes.get(0).getHash()).isEqualTo(rootNode.getHash());
// Subsequent nodes should be children of root node
List<Bytes32> expectedNodesHashes =
rootNode.getChildren().get().stream()
rootNode.getChildren().stream()
.filter(n -> !Objects.equals(n, NullNode.instance()))
.map(Node::getHash)
.collect(Collectors.toList());

Loading…
Cancel
Save