#
luxiaotao1123
2024-02-22 ad847473401730c14a5d667bd06afcb7d4575eb6
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/utils/Utils.java
@@ -10,6 +10,7 @@
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Predicate;
/**
 * Created by vincent on 2023/3/14
@@ -48,6 +49,45 @@
        return result;
    }
//    public static <T> List<T> treeRemove(List<T> data, String condition,
//                                         Function<? super T, ? extends String> fetcher,
//                                         Function<T, List<T>> childrenGetter,
//                                         BiConsumer<T, List<T>> childrenSetter) {
//        List<T> result = new ArrayList<>();
//        for (T node : data) {
//            List<T> children = childrenGetter.apply(node);
//
//            if (children != null && !children.isEmpty()) {
//                List<T> newChildren = treeRemove(children, condition, fetcher, childrenGetter, childrenSetter);
//                childrenSetter.accept(node, newChildren);
//            }
//
//            if (fetcher.apply(node).contains(condition)) {
//                result.add(node);
//            }
//        }
//        return result;
//    }
    public static <T> List<T> treeRemove(List<T> data, String condition,
                                         Function<? super T, ? extends String> fetcher,
                                         Function<T, List<T>> childrenGetter,
                                         BiConsumer<T, List<T>> childrenSetter) {
        List<T> result = new ArrayList<>();
        Predicate<T> predicate = node -> fetcher.apply(node).contains(condition);
        for (T node : data) {
            List<T> children = childrenGetter.apply(node);
            if (children != null && !children.isEmpty()) {
                List<T> newChildren = treeRemove(children, condition, fetcher, childrenGetter, childrenSetter);
                childrenSetter.accept(node, newChildren);
            }
            if (predicate.test(node)) {
                result.add(node);
            }
        }
        return result;
    }
    /**
     * 数组倒序
     * @param bytes