@Test public void parseLines() throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { MkStdDirExec intance = injector.getInstance(MkStdDirExec.class); String filePath = this.getClass().getResource("/dirinfo/").getPath() + "dirinfo.txt"; intance.readDirInfo(filePath); intance.parseLines(0, "#", 1, null); MenuInfo menuInfo = new MenuInfo(); MenuInfo aa = new MenuInfo(); aa.setLevel(1); aa.setName("aa"); aa.setParent(menuInfo); menuInfo.getNexts().add(aa); MenuInfo bbb = new MenuInfo(); bbb.setLevel(2); bbb.setName("bbb"); bbb.setParent(aa); MenuInfo ccc = new MenuInfo(); ccc.setLevel(2); ccc.setName("ccc"); ccc.setParent(aa); MenuInfo eee = new MenuInfo(); eee.setLevel(3); eee.setName("eee"); eee.setParent(ccc); MenuInfo ddd = new MenuInfo(); ddd.setLevel(1); ddd.setName("ddd"); ddd.setParent(menuInfo); menuInfo.getNexts().add(ddd); MenuInfo ee = new MenuInfo(); ee.setLevel(2); ee.setName("ee"); ee.setParent(aa); Field field = intance.getClass().getDeclaredField("menuInfo"); MenuInfo menuInfo1 = (MenuInfo) field.get(intance); }
public void parseLines(Integer fistIndex,String dot,int level,MenuInfo parentMenu) { String line = lineNoAndLine.get(fistIndex++); if(null == line) { return; } if(null!=line&& line.contains(dot+"#")) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(level+1); nextMenu.setName(parseLineContent(dot+"#",line)); nextMenu.setParent(parentMenu); parentMenu.addNext(nextMenu); dot = dot +"#"; level = level + 1; parseLines(fistIndex,dot,level,nextMenu); } else if(null!=line &&line.contains(dot) && parentMenu != null) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(level); nextMenu.setName(parseLineContent(dot,line)); nextMenu.setParent(parentMenu.getParent()); parentMenu.getParent().addNext(nextMenu); parseLines(fistIndex,dot,level,nextMenu); } else { int size = (line.length() - line.replaceAll("#", "").length())/2; boolean notfindParent = true; while(parentMenu!= null && null != parentMenu.getParent()) { if(size-1 ==parentMenu.getParent().getLevel()) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(size); nextMenu.setName(parseLineContent(pow("#",size),line)); nextMenu.setParent(parentMenu.getParent()); parentMenu.getParent().addNext(nextMenu); dot = pow("#",size); level = size; parseLines(fistIndex,dot,level,nextMenu); notfindParent = false; break; } parentMenu = parentMenu.getParent(); } if(notfindParent) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(size); nextMenu.setName(parseLineContent(pow("#",size),line)); nextMenu.setParent(menuInfo); menuInfo.addNext(nextMenu); dot = pow("#",size); level = size ; parseLines(fistIndex,dot,level,nextMenu); } } }
MkStdDirExec { public void parseLines(Integer fistIndex,String dot,int level,MenuInfo parentMenu) { String line = lineNoAndLine.get(fistIndex++); if(null == line) { return; } if(null!=line&& line.contains(dot+"#")) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(level+1); nextMenu.setName(parseLineContent(dot+"#",line)); nextMenu.setParent(parentMenu); parentMenu.addNext(nextMenu); dot = dot +"#"; level = level + 1; parseLines(fistIndex,dot,level,nextMenu); } else if(null!=line &&line.contains(dot) && parentMenu != null) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(level); nextMenu.setName(parseLineContent(dot,line)); nextMenu.setParent(parentMenu.getParent()); parentMenu.getParent().addNext(nextMenu); parseLines(fistIndex,dot,level,nextMenu); } else { int size = (line.length() - line.replaceAll("#", "").length())/2; boolean notfindParent = true; while(parentMenu!= null && null != parentMenu.getParent()) { if(size-1 ==parentMenu.getParent().getLevel()) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(size); nextMenu.setName(parseLineContent(pow("#",size),line)); nextMenu.setParent(parentMenu.getParent()); parentMenu.getParent().addNext(nextMenu); dot = pow("#",size); level = size; parseLines(fistIndex,dot,level,nextMenu); notfindParent = false; break; } parentMenu = parentMenu.getParent(); } if(notfindParent) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(size); nextMenu.setName(parseLineContent(pow("#",size),line)); nextMenu.setParent(menuInfo); menuInfo.addNext(nextMenu); dot = pow("#",size); level = size ; parseLines(fistIndex,dot,level,nextMenu); } } } }
MkStdDirExec { public void parseLines(Integer fistIndex,String dot,int level,MenuInfo parentMenu) { String line = lineNoAndLine.get(fistIndex++); if(null == line) { return; } if(null!=line&& line.contains(dot+"#")) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(level+1); nextMenu.setName(parseLineContent(dot+"#",line)); nextMenu.setParent(parentMenu); parentMenu.addNext(nextMenu); dot = dot +"#"; level = level + 1; parseLines(fistIndex,dot,level,nextMenu); } else if(null!=line &&line.contains(dot) && parentMenu != null) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(level); nextMenu.setName(parseLineContent(dot,line)); nextMenu.setParent(parentMenu.getParent()); parentMenu.getParent().addNext(nextMenu); parseLines(fistIndex,dot,level,nextMenu); } else { int size = (line.length() - line.replaceAll("#", "").length())/2; boolean notfindParent = true; while(parentMenu!= null && null != parentMenu.getParent()) { if(size-1 ==parentMenu.getParent().getLevel()) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(size); nextMenu.setName(parseLineContent(pow("#",size),line)); nextMenu.setParent(parentMenu.getParent()); parentMenu.getParent().addNext(nextMenu); dot = pow("#",size); level = size; parseLines(fistIndex,dot,level,nextMenu); notfindParent = false; break; } parentMenu = parentMenu.getParent(); } if(notfindParent) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(size); nextMenu.setName(parseLineContent(pow("#",size),line)); nextMenu.setParent(menuInfo); menuInfo.addNext(nextMenu); dot = pow("#",size); level = size ; parseLines(fistIndex,dot,level,nextMenu); } } }  }
MkStdDirExec { public void parseLines(Integer fistIndex,String dot,int level,MenuInfo parentMenu) { String line = lineNoAndLine.get(fistIndex++); if(null == line) { return; } if(null!=line&& line.contains(dot+"#")) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(level+1); nextMenu.setName(parseLineContent(dot+"#",line)); nextMenu.setParent(parentMenu); parentMenu.addNext(nextMenu); dot = dot +"#"; level = level + 1; parseLines(fistIndex,dot,level,nextMenu); } else if(null!=line &&line.contains(dot) && parentMenu != null) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(level); nextMenu.setName(parseLineContent(dot,line)); nextMenu.setParent(parentMenu.getParent()); parentMenu.getParent().addNext(nextMenu); parseLines(fistIndex,dot,level,nextMenu); } else { int size = (line.length() - line.replaceAll("#", "").length())/2; boolean notfindParent = true; while(parentMenu!= null && null != parentMenu.getParent()) { if(size-1 ==parentMenu.getParent().getLevel()) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(size); nextMenu.setName(parseLineContent(pow("#",size),line)); nextMenu.setParent(parentMenu.getParent()); parentMenu.getParent().addNext(nextMenu); dot = pow("#",size); level = size; parseLines(fistIndex,dot,level,nextMenu); notfindParent = false; break; } parentMenu = parentMenu.getParent(); } if(notfindParent) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(size); nextMenu.setName(parseLineContent(pow("#",size),line)); nextMenu.setParent(menuInfo); menuInfo.addNext(nextMenu); dot = pow("#",size); level = size ; parseLines(fistIndex,dot,level,nextMenu); } } }  void readDirInfo(String filePath); void parseLines(Integer fistIndex,String dot,int level,MenuInfo parentMenu); String pow(String doc,int size); String parseLineContent(String dot,String line); void mkdir(String rootPath,MenuInfo menuInfo); static void main(String[] args); }
MkStdDirExec { public void parseLines(Integer fistIndex,String dot,int level,MenuInfo parentMenu) { String line = lineNoAndLine.get(fistIndex++); if(null == line) { return; } if(null!=line&& line.contains(dot+"#")) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(level+1); nextMenu.setName(parseLineContent(dot+"#",line)); nextMenu.setParent(parentMenu); parentMenu.addNext(nextMenu); dot = dot +"#"; level = level + 1; parseLines(fistIndex,dot,level,nextMenu); } else if(null!=line &&line.contains(dot) && parentMenu != null) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(level); nextMenu.setName(parseLineContent(dot,line)); nextMenu.setParent(parentMenu.getParent()); parentMenu.getParent().addNext(nextMenu); parseLines(fistIndex,dot,level,nextMenu); } else { int size = (line.length() - line.replaceAll("#", "").length())/2; boolean notfindParent = true; while(parentMenu!= null && null != parentMenu.getParent()) { if(size-1 ==parentMenu.getParent().getLevel()) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(size); nextMenu.setName(parseLineContent(pow("#",size),line)); nextMenu.setParent(parentMenu.getParent()); parentMenu.getParent().addNext(nextMenu); dot = pow("#",size); level = size; parseLines(fistIndex,dot,level,nextMenu); notfindParent = false; break; } parentMenu = parentMenu.getParent(); } if(notfindParent) { MenuInfo nextMenu = new MenuInfo(); nextMenu.setLevel(size); nextMenu.setName(parseLineContent(pow("#",size),line)); nextMenu.setParent(menuInfo); menuInfo.addNext(nextMenu); dot = pow("#",size); level = size ; parseLines(fistIndex,dot,level,nextMenu); } } }  void readDirInfo(String filePath); void parseLines(Integer fistIndex,String dot,int level,MenuInfo parentMenu); String pow(String doc,int size); String parseLineContent(String dot,String line); void mkdir(String rootPath,MenuInfo menuInfo); static void main(String[] args);  }