Search tree implementation (reverse traversal)

List <the Map <String, Object List >> new new = the ArrayList <> (); 
// raw data tree
// define the secondary list
List <the Map <String, Object >> = new new tempList the ArrayList <> ();
List <the Map < String, Object >> parentList = new new ArrayList <> ();
List <TreeVO> = resultList new new ArrayList <> ();
// converted to speed up the search map
map <Object, map <String, Object >> orgMap = list. parallelStream ()
.collect (Collectors.toMap (V -> v.get (ID), V -> {
// initialization query result
String O = (String) v.getOrDefault (name, "");
IF (((String ) O) .Contains (searchStr)) {
tempList.add (V);
}
return V;
}));
// Traverse get higher
while (! TempList.isEmpty ()) {
tempList.forEach(v->{
if(v != null){
Object o = v.get(pid);
if(o == null){
o = "";
}
String vPid = (String)o;
if(!vPid.isEmpty()){
Map<String, Object> parent = orgMap.get(vPid);
if(parent != null){
parentList.add(parent);
}
}
       //定义的树结构
TreeVO vo = new TreeVO();
vo.setId((String) v.get(id));
vo.setName((String) v.get(name));
vo.setType((String) v.get(type));
vo.setCode((String) v.get(code));
vo.setParentId((String) v.get(pid));
if(!resultList.contains(vo)){
resultList.add(vo);
}
}
});
tempList.clear();
tempList.addAll(parentList);
parentList.clear();
}

Guess you like

Origin www.cnblogs.com/hjm0928/p/11830613.html