org.noear.grit.client.utils.SujectTreeUtils Maven / Gradle / Ivy
package org.noear.grit.client.utils;
import org.noear.grit.client.comparator.SubjectComparator;
import org.noear.grit.model.domain.Subject;
import java.util.ArrayList;
import java.util.List;
/**
* @author noear
* @since 1.0
*/
public class SujectTreeUtils {
/**
* 开始构建
*/
public static List build(List list, long rootId) {
List list2 = new ArrayList<>(list.size());
transDo(list, list2, rootId, 0);
return list2;
}
private static void transDo(List list, List list2, long pId, int level) {
list.stream().filter(m -> m.subject_pid == pId)
.sorted(SubjectComparator.instance)
.forEachOrdered(r -> {
r.level = level;
list2.add(r);
transDo(list, list2, r.subject_id, level + 1);
});
}
}