我有一个类名列表如下:
String s1 = "com.mycompany.project.dao.hibernate.BaseDAOHibernate";
String s2 = "com.mycompany.project.domain.Product";
String s3 = "com.mycompany.project.domain.ProductCategory";
String s4 = "com.mycompany.project.service.impl.ProductServiceImpl";
String s5 = "com.mycompany.project.domain.User";
String s6 = "com.mycompany.project.service.impl.ProductCategoryServiceImpl";
String s7 = "com.mycompany.project.dao.hibernate.ProductCategoryDAOHibernate";
String s8 = "com.mycompany.project.dao.hibernate.ProductDAOHibernate";
String[] strings = { s1, s2, s3, s4, s5, s6, s7, s8};
我想使用以下类定义将此数组转换为树结构:
public class Item {
private String itemName;
private List<Item> subItems;
}
该方法将采用上面的数组并生成以下对象。
item.ItemName = "com";
item.suItems = {"mycompany"};
item2.itemName = "mycompany";
item2.subItems = {"project");
item3.itemName = {"project"};
item3.subItems = {"dao", "domain", "service"}
... 等等。
请告知如何执行此操作,知道我可能有数百个类的列表作为输入。
谢谢