All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.noear.grit.client.utils.SujectTreeUtils Maven / Gradle / Ivy

There is a newer version: 1.9.2
Show newest version
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);
                });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy