Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: searching a tree of objects Date: Tue, 8 Dec 2015 19:22:18 -0000 (UTC) Organization: A noiseless patient Spider Lines: 45 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Tue, 8 Dec 2015 19:22:18 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="e5160e2be48f1ea550cf61512446f525"; logging-data="11161"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19+x48Wf6/I5cEE3o0V8Qrc8ALmfmayKRU=" User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Cancel-Lock: sha1:BRZQATVe6ovpk+yJZuP9e9TFZcY= Xref: csiph.com comp.lang.java.programmer:33317 On Tue, 08 Dec 2015 10:29:24 -0800, mike wrote: > Hi, > > We have a tree of objects with root at the top. > Now I want to search the tree for a specific node (object) > search string will look like: > > name=,name2=,name3= > > example could be: > > RootType=1,Device=1,DdcDevice=1 > > Rootype=1 > | > ----------- | | > Device=1 Equipment=1 > | > --------------------------------------- > | | | | > DbcDevice=1 DbcDevice=2 DrpDevice=2 VrpDevice=1 > > In each object I have the information name= in an attribute > called identifier. > > How can I use the search string and find the correct node that is > DbcDevice=1 and return another attribute for this object. > What is the purpose of your tree and what do you expect to return from searching it? If you expect to return a path to the target node, e.g "RootType,Device.RrpDevice" as well as and attribute of the target node content, then simply recursively walking the tree is your best bet. OTOH, If all you want to do is directly access a node or the subtree beneath it, use a HashMap as a fast node index. Use a TreeMap if you need an ordered index of node names. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |