Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for declarative creation of trees #15

Open
davidsusu opened this issue May 24, 2024 · 0 comments
Open

Add support for declarative creation of trees #15

davidsusu opened this issue May 24, 2024 · 0 comments

Comments

@davidsusu
Copy link
Owner

davidsusu commented May 24, 2024

We should provide better support for constructing trees. A nice feature would be if we could create trees in a declarative way.

Here is an example of the conception:

ImmutableTree
    .of(
        "root node",
            BEGIN, "child 1",
                "grandchild 1,1",
                "grandchild 1,2",
            END,
             BEGIN, "child 2",
                BEGIN, "grandchild 2,1",
                    "grand-grandchild 2,1,1"
                END,
              "grandchild 2,2",
          END,
      DONE
  ).decorate(
      PAD, 2,
      BORDER, 3, Color.RED,
      BACKGROUND, Color.BLUE,
      DONE
  )

Alternative to the tree part:

L, "root node",
    P, "child 1",
        P, "grandchild 1,1",
        P, "grandchild 1,2",
        P, "grandchild 1,3",
        P, "grandchild 1,4",
        L, "grandchild 1,5",
    L, "child 2",
        P, "grandchild 2,1",
            L, "grand-grandchild 2,1,1"
        L, "grandchild 2,2",
DONE

Or:

"root node",
__, "child 1",
__, __, "grandchild 1,1",
__, __, "grandchild 1,2",
__, __, "grandchild 1,3",
__, __, "grandchild 1,4",
__, __, "grandchild 1,5",
___, "child 2",
__, __, "grandchild 2,1",
__, __, __, "grand-grandchild 2,1,1"
__, __, "grandchild 2,2",
DONE

The optionally present constant DONE is here only because Java doesn't support trailing commas. In other JVM languages, there could be no necessity for using it.

We could also support stateful method chaining builders, while I don't favor this method e. g.:

.node("child1").begin()
    .node("grandchild1.1")
    .node("grandchild1.2").begin()
        .node("grandchild1.2.1")
    .end()
    .node("grandchild1.3")
.end()

Later we should find a way to fully separate content and presentation. Currently, the handling of the outfit is shared between the tree printer and the tree itself.

Please comment and/or react if you have an opinion. 👍 😠 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant