Mail Impressum Werner Diwischek
j-tree logo j-tree typo

J-Tree

JTreeMap is a java class storing objects in a directory structure. This means that one can list the keys and content of each "directory". The API methods have basically the same names as their unix counterparts.

In Perl there is a language part called Hashes of Hashes to build tree like structures referenced by name.

  • Perl map->{'rootDirectory'}->{'subDirectory'}->{'key'}

This basically creates a directory type structure we all know from the file system, not for files but for scalar values. In OSes we use a "/" or a "\" as delimiter for file systems.

  • Unix: /rootDirectory/subDirectory/fileName
  • Windows: \rootDirectory\subDirectory\fileName

Since the file system is something everybody knows I use this analogy for JTreeMap with the method names common in unix. As a directory separator the default value is a colon ":" But It can be set with the Constructor.

  • new JTreeMap("delimiter");

To store a value one use the insert method.

  • JTreeMapString map.insert(directory,key,value)

To get the value again, one use the read method:

  • value = map.read(directory,key)

To get a list of the "directory" content one just use

  • List <String> mapKeys =map.ls(directory)

Why to use it

In project one find a lot of container classes with no logic beside getters and setters. All these different container classes could be replaced with one map to avoid "OverClassification". This mostly lead to a situation, where one "can't see the wood for the trees".

Since one class can replace a lot of classes, this save a lot of coding and could be especially useful in prototyping.

Download

J-Tree consists in the core of one generic JTreeMap class. There is a small String implementation I use. Furthermore there are some Exceptions thrown. This version just need the apache logging for output.

  • Sources: j-tree-0.2-SNAPSHOT.zip
  • Compiled: j-tree-0.2-SNAPSHOT.jar
  • You can clone it from the git master with git clone https://W.Diwischek@code.google.com/p/j-tree/ .

    Versions

    I don't defined a separate versioning for JTreeMap since I heavily use it in the templating framework action4JAVA I named J-Tree before January 2013.

    Beside the template framework I think these two small classes can be useful just by itself in a java project.

    action4Java

    JTree is the base for the template solution http://www.action4java.org/.

    java duke with deers
    created by action4JAVA and J-Tree (30.3.2013 11:10)
    complexity is easy, simplicity is hard work.