I am modeling a power subsystem in Java. A simple SQLite database contains a set of Line Replaceable Units (LRUs) and the connections between them. I am writing a Power Model API to simplify queries of the data store, using DDD patterns and repositories.
I am seeking an appropriate Java collection to model the query results. There are some special cases in a LRU connection stream that have to be modeled:
The inclusion of #3 above has led me to think about returning query results from the API as a tree. But the only tree I've found in java.util is a TreeMap key-value paired red-black tree, which doesn't seem appropriate (or I can't think of an appropriate abstraction for modeling power streams with it.) I've also been considering a LinkedHashSet, but I'm not convinced it is appropriate either. It's not clear to me how a node in this structure would point to downstream nodes.
I'm not concerned about efficiency in time or space at this point. My API just has to work by supplying power connection information to external clients (i.e., the Presentation Tier of a Java-based Power Monitoring & Control app.) There are also no restrictions on the use of open source data types/libraries.
In general computer science parlance, what I'm really seeking is a Directed-Acyclic-Graph (DAG).
Is there an implementation of that for Java? Am I correct that a DAG is appropriate for my scenario?
I don't know if it can help but take a look at JGraphT.
As you can see if regarding the "related" questions, similar questions were already asked. And no, Java does not have a general-purpose graph/tree/DAG data type (if we don't count Swing's TreeModel).
Make your own one.
Here is an example (readonly) interface:
interface Node<N extends Node<N,E>, E extends Edge<N,E>> {
public Set<E> outgoingEdges();
public Set<E> ingoingEdges();
}
interface Edge<N extends Node<N,E>, E extends Edge<N,E>> {
public E source();
public E sink();
}
You would then have
interface LRU implements Node<LRU, Line> { ... }
interface Line implements Edge<LRU, Line> { ... }
(or classes instead).
For this particular problem. I've decided to use a LinkedListMultimap from Guava.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With