Mercurial > hg > Members > shoshi > TreeCMSv2
view src/treecms/tree/util/NodeFinder.java @ 17:168deb591f21
commit
author | shoshi |
---|---|
date | Tue, 24 May 2011 00:33:12 +0900 |
parents | |
children | 084de6909451 |
line wrap: on
line source
package treecms.tree.util; import treecms.api.Node; import treecms.api.NodeID; public class NodeFinder<T extends Node<T>> { private T m_root; public NodeFinder(T _root) { m_root = _root; } public T findByUUID(final String _uuid) { Evaluator<T,T> ev = new Evaluator<T,T>(){ private T m_res = null; @Override public boolean evaluate(T _target) { if(_target.getID().getUUID().equals(_uuid)){ m_res = _target; return true; } return false; } @Override public T getResult() { return m_res; } }; _recursiveFinder(m_root,ev); return ev.getResult(); } public T findByNodeID(final NodeID _id) { Evaluator<T,T> ev = new Evaluator<T,T>(){ private T m_res = null; @Override public boolean evaluate(T _target) { if(_target.getID().equals(_id)){ m_res = _target; return true; } return false; } @Override public T getResult() { return m_res; } }; _recursiveFinder(m_root,ev); return ev.getResult(); } private boolean _recursiveFinder(T _cur,Evaluator<T,?> _e) { if(_e.evaluate(_cur)){ return true; } for(T child : _cur.getList()){ if(_recursiveFinder(child,_e)){ return true; } } return false; } private static interface Evaluator<T,R> { public boolean evaluate(T _target); public R getResult(); } }