AbstractNodeItem: replace manual null checks with @NonNull

This commit is contained in:
Paul Campbell 2016-08-22 08:52:42 +01:00
parent d99fcdcebe
commit b2130442e5

View file

@ -1,5 +1,7 @@
package net.kemitix.node; package net.kemitix.node;
import lombok.NonNull;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -65,10 +67,7 @@ abstract class AbstractNodeItem<T> implements Node<T> {
* @return an {@link Optional} containing the child node if found * @return an {@link Optional} containing the child node if found
*/ */
@Override @Override
public Optional<Node<T>> findChild(final T child) { public Optional<Node<T>> findChild(@NonNull final T child) {
if (child == null) {
throw new NullPointerException("child");
}
return children.stream().filter(node -> { return children.stream().filter(node -> {
final Optional<T> d = node.getData(); final Optional<T> d = node.getData();
return d.isPresent() && d.get().equals(child); return d.isPresent() && d.get().equals(child);
@ -102,10 +101,7 @@ abstract class AbstractNodeItem<T> implements Node<T> {
* @return the child or null * @return the child or null
*/ */
@Override @Override
public Optional<Node<T>> findInPath(final List<T> path) { public Optional<Node<T>> findInPath(@NonNull final List<T> path) {
if (path == null) {
throw new NullPointerException("path");
}
if (path.size() > 0) { if (path.size() > 0) {
Optional<Node<T>> found = findChild(path.get(0)); Optional<Node<T>> found = findChild(path.get(0));
if (found.isPresent()) { if (found.isPresent()) {
@ -119,10 +115,7 @@ abstract class AbstractNodeItem<T> implements Node<T> {
} }
@Override @Override
public Optional<Node<T>> findChildByName(final String named) { public Optional<Node<T>> findChildByName(@NonNull final String named) {
if (named == null) {
throw new NullPointerException("name");
}
return children.stream() return children.stream()
.filter(n -> n.getName().equals(named)) .filter(n -> n.getName().equals(named))
.findAny(); .findAny();