package com.platform.glusterfs; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.log4j.PropertyConfigurator; import org.junit.Test; public class GetTreeData { ShowData showData = new ShowData(); public GetTreeData() { // TODO Auto-generated constructor stub } public FileOrFolder getDatas(String name) { FileOrFolder fileOrFolder = new FileOrFolder(name); Map files = showData.showFolderData(name); if(files==null || files.size()==0){ return fileOrFolder; } fileOrFolder.isFolder = files.size(); fileOrFolder.children = new ArrayList(); for (Map.Entry entry : files.entrySet()) { int number = Integer.parseInt(entry.getValue()); if(entry.getKey().equals("app")){ continue; } if (number == 1) { fileOrFolder.children.add(new FileOrFolder(entry.getKey(), number)); } if (number > 1) { FileOrFolder temp=getDatas(name+"/"+entry.getKey()); fileOrFolder.children.add(temp); } } return fileOrFolder; } public static void main(String[] args) { GetTreeData getTreeData=new GetTreeData(); FileOrFolder fileOrFolder=getTreeData.getDatas("/home"); System.out.println(fileOrFolder); } } class FileOrFolder { String name; int isFolder; // 1 is file and other integer is folder show children number List children; public FileOrFolder(String name) { // TODO Auto-generated constructor stub this.name = name; } public FileOrFolder(String name, int isFolder) { // TODO Auto-generated constructor stub this.name = name; this.isFolder = isFolder; } }