package net.acomputerdog.core.tree;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class Branch<T> {
    private final Branch<T> parent;
    private final Set<Branch<T>> branches = new HashSet<Branch<T>>();
    private final Set<Leaf<T>> leaves = new HashSet<Leaf<T>>();
    private final Tree<T> tree;

    public Branch(Tree<T> tree, Branch<T> parent) {
        this.parent = parent;
        this.tree = tree;
    }

    public boolean isRoot() {
        return parent == null;
    }

    public Branch getParent() {
        return parent;
    }

    public Set<Branch<T>> getBranches() {
        return Collections.unmodifiableSet(branches);
    }

    public Set<Leaf<T>> getLeaves() {
        return Collections.unmodifiableSet(leaves);
    }

    public int getNumBranches() {
        return branches.size();
    }

    public int getNumLeaves() {
        return leaves.size();
    }

    public void addBranch(Branch<T> branch) {
        branches.add(branch);
    }

    public void addLeaf(Leaf<T> leaf) {
        leaves.add(leaf);
    }

    public Tree<T> getTree() {
        return tree;
    }
}

@@ -77,22 +77,25 @@
 va.util.
-HashSe
+LinkedLis
 t;%0Aimpor
@@ -106,18 +106,19 @@
 va.util.
-Se
+Lis
 t;%0A%0Apubl
@@ -192,18 +192,19 @@
 e final 
-Se
+Lis
 t%3CBranch
@@ -223,22 +223,25 @@
 s = new 
-HashSe
+LinkedLis
 t%3CBranch
@@ -266,18 +266,19 @@
 e final 
-Se
+Lis
 t%3CLeaf%3CT
@@ -297,14 +297,17 @@
 new 
-HashSe
+LinkedLis
 t%3CLe
@@ -605,18 +605,19 @@
  public 
-Se
+Lis
 t%3CBranch
@@ -676,18 +676,19 @@
 difiable
-Se
+Lis
 t(branch
@@ -710,18 +710,19 @@
  public 
-Se
+Lis
 t%3CLeaf%3CT
@@ -781,10 +781,11 @@
 able
-Se
+Lis
 t(le

Fix branches being mixed in Tree structure