You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aggregation-platform/src/com/platform/glusterfs/GetTreeData.java

66 lines
1.6 KiB

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<String, String> files = showData.showFolderData(name);
if(files==null || files.size()==0){
return fileOrFolder;
}
fileOrFolder.isFolder = files.size();
fileOrFolder.children = new ArrayList<FileOrFolder>();
for (Map.Entry<String, String> 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<FileOrFolder> 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;
}
}