| | |
| | | * @param <R> parentId的类型 |
| | | * @return List<T> |
| | | */ |
| | | public static <T, R> List<T> toTreeData(List<T> data, R parentId, |
| | | public static <T, R> List<T> toTreeData(List<T> data, |
| | | R parentId, |
| | | Function<? super T, ? extends R> parentIdMapper, |
| | | Function<? super T, ? extends R> idMapper, |
| | | BiConsumer<T, List<T>> consumer) { |
| | |
| | | if (parentId.equals(dParentId)) { |
| | | R dId = idMapper.apply(d); |
| | | List<T> children = toTreeData(data, dId, parentIdMapper, idMapper, consumer); |
| | | consumer.accept(d, children); |
| | | if(children.size() > 0) { |
| | | consumer.accept(d, children); |
| | | } |
| | | result.add(d); |
| | | } |
| | | } |