943,786 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3217
  • Java RSS
Nov 24th, 2008
0

Tree interface for ArrayList

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dixi is offline Offline
2 posts
since Nov 2008
Nov 24th, 2008
0

Re: Tree interface for ArrayList

Click to Expand / Collapse  Quote originally posted by dixi ...

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
Reputation Points: 935
Solved Threads: 356
Nearly a Posting Maven
stultuske is online now Online
2,493 posts
since Jan 2007
Nov 25th, 2008
0

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();

}
Reputation Points: 9
Solved Threads: 2
Light Poster
AlbertPi is offline Offline
33 posts
since Nov 2008
Dec 1st, 2008
0

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dixi is offline Offline
2 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: pls help w/ this
Next Thread in Java Forum Timeline: How to make a Splash Screen





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC