| | |
| | | return result; |
| | | } |
| | | |
| | | public static <T, R> List<T> getAllTree(List<T> data, R parentId, Function<? super T, ? extends R> parentIdMapper, Function<? super T, ? extends R> idMapper, BiConsumer<T, List<T>> consumer) { |
| | | List<T> result = new ArrayList<>(); |
| | | for (T datum : data) { |
| | | R dParentId = parentIdMapper.apply(datum); |
| | | R dId = idMapper.apply(datum); |
| | | if (dParentId.equals(dId)) { |
| | | List<T> children = toTreeData(data, dId, parentIdMapper, idMapper, consumer); |
| | | if (!children.isEmpty()) { |
| | | consumer.accept(datum, children); |
| | | } |
| | | result.add(datum); |
| | | } |
| | | if (dParentId.equals(dId)) { |
| | | continue; |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | |
| | | public static <T> void treeRemove(List<T> list, String condition, Function<? super T, ? extends String> fetcher, Function<T, List<T>> childrenGetter) { |
| | | Iterator<T> iterator = list.iterator(); |
| | | while (iterator.hasNext()) { |