这个方法存在严重问题
public static <T> List<Node> convertDatas2Nodes(List<T> datas)
throws IllegalArgumentException, IllegalAccessException
{
List<Node> nodes = new ArrayList<Node>();
Node node = null;
for (T t : datas)
{
int id = -1;
int pid = -1;
String label = null;
node = new Node();
Class clazz = t.getClass();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields)
{
if (field.getAnnotation(TreeNodeId.class) != null)
{
field.setAccessible(true);
id = field.getInt(t);
}
if (field.getAnnotation(TreeNodePid.class) != null)
{
field.setAccessible(true);
pid = field.getInt(t);
}
if (field.getAnnotation(TreeNodeLabel.class) != null)
{
field.setAccessible(true);
label = (String) field.get(t);
}
}
node = new Node(id, pid, label);
nodes.add(node);
}// for end
Log.e("TAG", nodes+"");
/**
* 设置Node间的节点关系
*/
for (int i = 0; i < nodes.size(); i++)
{
Node n = nodes.get(i);
for (int j = i + 1; j < nodes.size(); j++)
{
Node m = nodes.get(j);
if (m.getpId() == n.getId())
{
n.getChildren().add(m);
m.setParent(n);
} else if (m.getId() == n.getpId())
{
m.getChildren().add(n);
n.setParent(m);
}
}
}
for (Node n : nodes)
{
setNodeIcon(n);
}
return nodes;
}