{Abstract}NodeItem: reduce nested if statements
This commit is contained in:
parent
37247e93bc
commit
9f3aec202a
2 changed files with 22 additions and 24 deletions
|
@ -102,7 +102,9 @@ abstract class AbstractNodeItem<T> implements Node<T> {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Optional<Node<T>> findInPath(@NonNull final List<T> path) {
|
public Optional<Node<T>> findInPath(@NonNull final List<T> path) {
|
||||||
if (path.size() > 0) {
|
if (path.isEmpty()) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
Optional<Node<T>> found = findChild(path.get(0));
|
Optional<Node<T>> found = findChild(path.get(0));
|
||||||
if (found.isPresent()) {
|
if (found.isPresent()) {
|
||||||
if (path.size() > 1) {
|
if (path.size() > 1) {
|
||||||
|
@ -110,7 +112,6 @@ abstract class AbstractNodeItem<T> implements Node<T> {
|
||||||
}
|
}
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,19 +2,15 @@ package net.kemitix.node;
|
||||||
|
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a tree of nodes.
|
* Represents a tree of nodes.
|
||||||
*
|
*
|
||||||
* @author Paul Campbell
|
|
||||||
*
|
|
||||||
* @param <T> the type of data stored in each node
|
* @param <T> the type of data stored in each node
|
||||||
|
*
|
||||||
|
* @author Paul Campbell
|
||||||
*/
|
*/
|
||||||
class NodeItem<T> implements Node<T> {
|
class NodeItem<T> implements Node<T> {
|
||||||
|
|
||||||
|
@ -264,7 +260,9 @@ class NodeItem<T> implements Node<T> {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Optional<Node<T>> findInPath(@NonNull final List<T> path) {
|
public Optional<Node<T>> findInPath(@NonNull final List<T> path) {
|
||||||
if (path.size() > 0) {
|
if (path.isEmpty()) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
Optional<Node<T>> found = findChild(path.get(0));
|
Optional<Node<T>> found = findChild(path.get(0));
|
||||||
if (found.isPresent()) {
|
if (found.isPresent()) {
|
||||||
if (path.size() > 1) {
|
if (path.size() > 1) {
|
||||||
|
@ -272,7 +270,6 @@ class NodeItem<T> implements Node<T> {
|
||||||
}
|
}
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue