As part of my homework, I've been asked to create a JTree Model with a fixed set of constants (Authors and Books) Presented below is only a small subset of constants to include. Is there a more elegant and maintainable solution to build the tree? I would have preferred to create a database but we have been advised that this is too complex at the moment. Any design advise or patterns would be much appreciated.
As a side note I couldn't find a homework tag.
public class TreeBuilder {
public static ItemNode build(){
ItemNode rootNode = new ItemNode("Library", ItemNode.NODE_ROOT);
ItemNode authorOne = new ItemNode("Author One", ItemNode.NODE_AUTHOR);
ItemNode bookOne = new ItemNode("Book One", "isbn12345", ItemNode.NODE_BOOK);
ItemNode bookTwo = new ItemNode("Book Two", "isbn54321", ItemNode.NODE_BOOK);
authorOne.addChild(bookOne);
authorOne.addChild(bookTwo);
ItemNode authorTwo = new ItemNode("Author Two", ItemNode.NODE_AUTHOR);
ItemNode bookThree = new ItemNode("Book Three", "isbn98765", ItemNode.NODE_BOOK);
authorTwo.addChild(bookThree);
rootNode.addChild(authorOne);
rootNode.addChild(authorTwo);
return rootNode;
}
}