Tree-like Structure
<p>I have the following classes:</p>

<pre><code>public  class Model {
    protected String name;
    protected ArrayList&lt;Model&gt; children;

    public Model(){
        children = new ArrayList&lt;Model&gt;();
    }

    public void addChild(Model node) {
        children.add(node);       
    }
    //other code here
}


public class cPackage extends Model{
    public cPackage() {
        super();
    }

    //other code here
}


public class cClass extends Model{
    public cClass() {
        super();
    }
    //other code here
}

public class cMethod extends Model{
    public cMethod() {
        super();
    }
    //other code here
}

public void tryme(Object[] objs){
    String values = (String)objs[0];
    Model root = null;

    astNode = ax.getDeclaringNodeInProject(handles, bindings);

    if(astNode instanceof TypeDeclaration){
        TypeDeclaration  cl = (TypeDeclaration)astNode;
        root = new cClass();
        root.setName(cl.getName().getFullyQualifiedName());
    }else if(astNode instanceof MethodDeclaration){
        MethodDeclaration me = (MethodDeclaration)astNode;
        root = new cMethod();
        List mod =  me.parameters();
        String vars ="";
        ...
        root.setName(me.getName().getFullyQualifiedName() + "(" + vars + ")");
    }

    Model currentNode = null;
    Model prevNode = root;

    for(int i = 1 ; i &lt; objs.length; i++){
        if(astNode instanceof PackageDeclaration){
            PackageDeclaration pka = (PackageDeclaration)astNode;
            p8.setName(pka.getFullyQualifiedName());
            if(currentNode == null) {
                currentNode = p8;
                prevNode.addChild(currentNode);
            }
            prevNode = currentNode;
        }else if(astNode instanceof MethodDeclaration){
            MethodDeclaration me = (MethodDeclaration)astNode;
            ...
            m8.setName(me.getName().getFullyQualifiedName() + "(" + vars + ")");

            if(currentNode == null) {
                currentNode = m8;
                prevNode.addChild(currentNode);
            }
            prevNode = currentNode;
        }else if(astNode instanceof TypeDeclaration){
            TypeDeclaration  cl = (TypeDeclaration)astNode;
            c8.setName(cl.getName().getFullyQualifiedName());
            if(currentNode == null) {
                currentNode = c8;
                prevNode.addChild(currentNode);
            }
            prevNode = currentNode;
        }
    }
}
</code></pre>

<p>Sorry if there are missing  "{" or "}". What i am trying to do here is i have a data from the server like these:</p>

<pre><code>[School Chair  Table Chalk]

...

[Apple Peer Mango Melon]
</code></pre>

<p>all in arrays. I want to build something like a tree-like structure whereby reading from the left :</p>

<p>Each element will be de parent of the element that follows it. I am looping through the data to do it. For example i want to get something like:</p>

<pre><code>+School
      Chair
          Table
              Chalk


+Apple
     Peer
         Mango
             Melon
</code></pre>

<p>But when i run the above code i get only the first two elements like:</p>

<pre><code>+School
      Chair



+Apple
     Peer
</code></pre>

<p>and the following elements don't show up.</p>

<p>Can someone help me where am doing wrong.</p>

<p>Thanks.</p>
