Re: Is There a Java Class for this Kind of Data Structure?
"Hal Vaughan" <hal@thresholddigital.com> wrote in message
news:u66dnRSX-8EIaAjbnZ2dnUVZ_hCdnZ2d@comcast.com...
I think if I weren't self taught, I'd know the terms to describe what I'm
trying to do and might even know what kind of class to look for in the
Java
API. I'm hoping there's a Java class that will do what I need to do. I
think it's some kind of tree structure, but I've only heard the term
used
and what I found (like TreeMap) doesn't seem to do what I need. Any
info I
find on Trees, though, seems to go back to JTree and I don't need a GUI
for
this.
I have a number of data tables and many of them have dependent tables
based
on matching certain criteria. These dependent tables often have other
dependent tables. There is no limit to the levels of dependents and to
the
number of dependents for each table, but in reality, I doubt any would
go
deeper than 5-6 levels.
I have a list of the main tables and each table has its own list of its
immediate dependents (isn't the correct term children?) and, of course,
each child has a list of its own children and so on.
Yes, children is the correct term.
This has worked fine so far, but if a main table is modified, I need to
update all the tables that depend on it, no matter how many levels
removed.
There are more details I don't want to go into, but what I'd like to do
is
have one structure that a main table has access to that is a list of all
the dependent tables. I can't use a regular list for this because I
need
for all the tables at one level to be listed at that level. I was
thinking
of something like a LinkedList of LinkedLists.
In Java, there's an interface called "List", and from the
program-behaviour point of view, it doesn't really matter whether the List
interface is implemented via an ArrayList or a LinkedList or some other
type of List. The term "regular list" is ambiguous and it's unclear what
you are referring to by it (an easy way to clear ambiguity is to post your
source code, since the meaning of the Java language is very precisely
defined -- see http://www.physci.org/codes/sscce.html)
In other words, a LinkedList does not do anything above and beyond
what a plain List can do, so replacing whatever you've got now iwth a
LinkedList is almost guaranteed to not solve your problem.
For instance, the main table would be the first item in the main
LinkedList.
The 2nd item would be a LinkedList of all it's children and the 3rd item
would be a another LinkedList of all the grandchilren and so on.
If the first element of your list is of type "MainTable", and the
second element of your list is of type "LinkedList", then you've got a
heterogenous list, and they're a big pain to work with.
Yes, I can do this with lists of lists, but isn't here some kind of tree
or
other kind of branching list that will do this?
When you wrote...
I have a list of the main tables and each table has its own list of its
immediate dependents (isn't the correct term children?) and, of course,
each child has a list of its own children and so on.
... you demonstrated that you already have a tree implemented. So I
don't think your problem is "how do I add a tree data structure somewhere
in my program?" because you've already done so. I think your problem is
more that you haven't actually identified what your problem is.
You write that you want to "update all the tables that depend on it,
no matter how many levels removed", so why don't you go ahead and do that?
What is it about your current data structure that is preventing you from
being able to write code which does exactly what you want?
- Oliver