Skip to content

Instantly share code, notes, and snippets.

@benbai123
Last active August 29, 2015 14:04
Show Gist options
  • Save benbai123/9b8d704506e4a99084eb to your computer and use it in GitHub Desktop.
Save benbai123/9b8d704506e4a99084eb to your computer and use it in GitHub Desktop.
package test.tree.rod;
import java.util.List;
/**
* tested with ZK 6.0.2
*
* The interface for data bean that used in RODTreeModel and RODTreeNode
*
* @author benbai123
*
*/
public class RODTreeNodeData {
private Object _obj;
// constructor
public RODTreeNodeData (Object obj) {
_obj = obj;
}
/**
* get children of this data
* @return
*/
public List<? extends RODTreeNodeData> getChildren() {
RODTreeNodeDataHelper.getChildrenOf(obj);
}
/**
* get child count of this data, do not need to really get children
* @return
*/
public int getChildCount () {
RODTreeNodeDataHelper.getChildCountOf(obj);
}
}
package test.tree.rod;
import java.util.List;
public class RODTreeNodeDataHelper {
// probably can cache children for reuse (Multiton Pattern)
// remember to override hashCode and equals methods
private Map<Object, List> _childrenCache = new HashMap<Object, List>();
public static getChildCountOf (Object data) {
// detect instance of data
// access files or db to get child count of data
// e.g.
if (data instanceof File) {
// operations for File class
// probably can apply some other design patterns here
// e.g. Chain of Responsibility or Strategy
} else if (data instanceof Employee) {
// operations for Employee class
}
}
public static getChildrenOf (Object obj) {
List children = new ArrayList();
// some operations...
// similar to getChildCountOf method
// some operations...
_childrenCache.put(obj, children)
return children;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment