| | |
Tree interface for ArrayList
![]() |
•
•
Join Date: Nov 2008
Posts: 2
Reputation:
Solved Threads: 0
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
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
•
•
•
•
Class Processtree{
String ProcessName;
String StateName;
Binary tree ProcTree;
}
So I think that I don't need to worry about the Processtree
a better approach is to declare all your variables there private and to use getters and setters to get or manipulate their values
•
•
Join Date: Nov 2008
Posts: 33
Reputation:
Solved Threads: 2
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();
}
The following is a tree interface:
interface CommonTree <T> {
public T getData();
public int getNodes();
public boolean IsEmpty();
public void Clear();
}
•
•
Join Date: Nov 2008
Posts: 2
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- Source Code that don't work? (Java)
Other Threads in the Java Forum
- Previous Thread: Final Year Project (Chat System)
- Next Thread: Simulation of protocols
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle physics plazmic print problem program programming project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows





