Annotation Type Tree
When this annotation is applied to a class, it informs the core API that
the objects of this class can be organized into a tree structure, provided
that they also have the @Id and @Parent annotations.
The HappyTree API is able to transform a data structure that represents,
logically, a tree, but is physically organized in a linear form. Each object
that has this annotation will represent a node in a tree. It happens when the
API client passes a collection of linear objects that have a hierarchical
relationship through the Id and Parent, to be organized into
an actual tree structure through the
TreeTransaction.initializeSession(String, java.util.Collection)
method.
For instance, if there is, for any reason, a need to transform a data structure like this:
into this:@Treepublic class Directory {@Idprivate long identifier;@Parentprivate long parentIdentifier; private String name; //(System32 for example) ... }
public class Element<Directory> {
private Collection<Element<Directory>> children;
private Directory wrappedNode; //The respective Directory
...
}
Then, the HappyTree API will process and transform it into an actual tree
structure. This process is known as the API Transformation Process.
Note that in this example, there is a slight change in how the objects are
related. In the first one, the parentIdentifier of an object
references the identifier of another object, which conceptually
represents the parent of the first one.
The second example shows that the relationship between the objects is slightly different, because, indeed, an object is literally inside of another one, and so on, representing an actual tree structure.
After the tree is built, it is possible to handle each element in a very
flexible way (cut, copy, remove, etc.) through the TreeManager
interface.
The getters and setters for the @Id and
@Parent annotated fields are mandatory.
- Author:
- Diego Madson de Andrade Nóbrega