code: public static <T, K> ArrayList<T> buildTree(Collection<T> list,
  			Function<T, K> keyMapper, Function<T, K> parentKeyMapper,
  			Function<T, Collection<T>> childMapper) {
  		HashMap<K, T> map = toHashMap(list, keyMapper);
  
  		ArrayList<T> root = new ArrayList<T>();
  		for (T t : list) {
  			K key = keyMapper.apply(t);
  			K parentKey = parentKeyMapper.apply(t);
  			if (parentKey == null || key.equals(parentKey))
  				root.add(t);
  			else
  				childMapper.apply(map.get(parentKey)).add(t);
  		}
  
  		return root;
  	}
docs: 建立树形结构
  
  @param list
  @param keyMapper
  @param parentKeyMapper
  @param childMapper
  @return