package ru.job4j.simpleTree;

import java.util.*;

public abstract class Tree<E extends Comparable<E>> implements SimpleTree<E> {

    Node<E> root;

    public Tree(E value) {
        this.root = new Node<>(value);
    }

    @Override
    public boolean add(E parent, E child) {
        if (root.equals(parent)) {
            root.add(new Node<>(child));
        } else {
            root = new Node<>(parent);
            root.add(new Node<>(child));
         }
        return true;
    }

    @Override
    public Optional findBy(E value) {
        Optional<Node<E>> rsl = Optional.empty();
        Queue<Node<E>> data = new LinkedList<>();
        data.offer(this.root);
        while (!data.isEmpty()) {
            Node<E> el = data.poll();
            if (el.eqValue(value)) {
                rsl = Optional.of(el);
                break;
            }
            for (Node<E> child : el.leaves()) {
                data.offer(child);
            }
        }
        return rsl;
    }
}
@@ -294,23 +294,16 @@
 root
-.equals(parent)
+ == null
 ) %7B%0A
@@ -376,33 +376,32 @@
     
-root = new Node%3C%3E
+if (root.eqValue
 (parent)
 ;%0A  
@@ -396,18 +396,46 @@
 (parent)
-;%0A
+) %7B%0A%0A            %7D else %7B%0A    
         
@@ -464,24 +464,37 @@
 %3E(child));%0A 
+           %7D%0A
         %7D%0A  

task #1711