Java: treat String as a command without using exec

Status
You're currently viewing only snotnose's posts. Click here to go back to viewing the entire thread.

snotnose

Ars Praefectus
3,459
Subscriptor
I wish I'd found Graphstream last week, it does everything I need from a display standpoint. For example:
Code:
public class DemoGraphstream {
    void main() {
        System.setProperty("org.graphstream.ui", "swing");
        Graph graph = new SingleGraph("Tutorial 1");
        graph.addNode("A");
        graph.addNode("B");
        graph.addNode("C");
        graph.addEdge("AB", "A", "B");
        graph.addEdge("BC", "B", "C");
        graph.addEdge("CA", "C", "A");
        graph.display();
}
I have a parser that returns a List<String> of addNode and addEdge lines. Which is way cool, I can now skip the copy-paste I was doing. Except, now that I have the string "graph.addNode("A");", what do I do with it?

It occurs to me my parser can just return the list of nodes and edges, instead of strings. Which I will do tomorrow.

But now I wanna know, in Java (or Kotlin), how do I treat a string like a line of code?
 

snotnose

Ars Praefectus
3,459
Subscriptor
The answers above cover it. I just find it amusing you're trying to do something very similar to what I'm currently working on, but I'm in C++. My graph inputs are circuit netlists. I ended up writing my own simple graph implementation because the one in boost was just incomprehensible.
I strongly recommend Graphstream.

Jgrapht - looks good but after a week I still couldn't figure out how to display my graph correctly. It's like getting an Ikea dresser except it has no instructions and you've never seen a dresser before so you don't know what it should look like.
gelphi - almost worked but it's a separate program
Graphstream - Works like a champ, but looks to be abandoned. No updates in 5 years and a lot of dead links at the website. Nowhere near as hard to figure out from the source as Jgrapht.

Turns out graph manipulation is easy, displaying that graph not so much.

I'm using Kotlin, not C++, YMMV.
 
Last edited:
Status
You're currently viewing only snotnose's posts. Click here to go back to viewing the entire thread.