DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Tree interface for ArrayList (http://www.daniweb.com/forums/thread159223.html)

dixi Nov 24th, 2008 7:07 am
Tree interface for ArrayList
 
Hi! I'm trying to define a list of objects that could be a binary tree or a Processtrees.
The binary tree is already defined and works fine, don't worry about it.

A Processtree is a binary tree generated by a Process, a Process is defined by a Name and a State

Processtree looks like this:

Class Processtree{
String ProcessName;
String StateName;
Binary tree ProcTree;
}

So I think that I don't need to worry about the Processtree, but I need to define a list of objects that could be a Binary tree or a Processtree.
The Processtree implementation may change, so I think I should define a common Tree interface and make Processtree and Binary tree implement it, but I don't know if I could define an ArrayList of this Tree..
I'm new to java, thanks in advance

stultuske Nov 24th, 2008 7:22 am
Re: Tree interface for ArrayList
 
Quote:

Originally Posted by dixi (Post 743343)

Class Processtree{
String ProcessName;
String StateName;
Binary tree ProcTree;
}

So I think that I don't need to worry about the Processtree

if this is all the code you have in Processtree, you might want to worry though.
a better approach is to declare all your variables there private and to use getters and setters to get or manipulate their values

AlbertPi Nov 25th, 2008 12:17 pm
Re: Tree interface for ArrayList
 
You can implement a common tree interface based on your current BTree class then you can have two options, First, you code PTree from common tree or Second you can inherit BTree to code your PTree if PTree is a kind of "Binary" tree.

The following is a tree interface:

interface CommonTree <T> {
public T getData();
public int getNodes();
public boolean IsEmpty();
public void Clear();

}

dixi Dec 1st, 2008 4:55 am
Re: Tree interface for ArrayList
 
PTree is a kind of Binary tree so your Second solution works fine, but now my boss wants me to create a List of objects that can be a Binary tree or what he calls a Forest:
Forest{
NameProc
Array[s1,s2,...sn] of Binary tree
}

So I need to create a list that looks like this: BT-F-F-BT-F...
where BT is the Binary tree and F is a Forest.
Each forest is defined by the process name and an array of binary trees, the array is indexed by the states s1,..sn that are the states of the process, each state generates a different Binary tree..
This array is not the problem because I think I can use a map, but I don't know how to create a list of objects that are so different, could that be possible to create a list of binary trees and Forests using an interface?
Any help please


All times are GMT -4. The time now is 2:39 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC