Boa noite galera, Estou dando inicio ao estudo de otimizações de código, mas estou com um problema em otimizar um código de um amigo q me pediu ajuda...
ele não gostou da quantidade de Ifs em um dos métodos, achei meio tosco tb, olhei, pensei algumas coisas mas nada q tenha ficado bom.
pensei em criar uma interface, mas como é uma recursividade achei q não iria funcionar
tem como alguém ai dar um help?
public class Node {
   private Integer data;
   private Node left;
   private Node right;
   public Node (Integer value) {
       data = value;
       left = null;
       right = null;
   }
   public Integer getData () {
       return data;
   }
   public Node getRight () {
       return right;
   }
   public Node getLeft () {
       return left;
   }
   public Node insert (Node node) {
       if (data > node.getData()) {
           if (isLeaf(left)) {
               left = node;
           } else {
               left.insert(node);
           }
       } else if (data < node.getData()) {
           if (isLeaf(right)) {
               right = node;
           } else {
               right.insert(node);
           }
       } else {
           return this; // I won't insert repeated values into the tree'
       }
       return this;
   }
   public Boolean isOrdered () {
       try {
           return (( isLeaf(left)  || (isBiggerThanLeft()   && left.isOrdered() )) &&
                   ( isLeaf(right) || (isSmallerThanRight() && right.isOrdered())) );
       } catch (Exception e) {
           System.out.println (e.toString());
           System.out.println ("Node: " + data + " - Left: " + isLeaf(left) + " - Right: " + isLeaf(right));
           return false;
       }
   }
   private Boolean isLeaf(Node node) {
       return node == null;
   }
   private Boolean isBiggerThanLeft() {
       return (isLeaf(left) || (data > left.getData()));
   }
   private Boolean isSmallerThanRight() {
       return (isLeaf(right) || (data < right.getData()));
   }
   public void print() {
       if (!isLeaf(left)) {
           left.print();
       }
       System.out.println(data);
       if (!isLeaf(right)) {
           right.print();
       }
    }
}