| | |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.concurrent.ThreadLocalRandom; |
| | | import java.util.function.BiConsumer; |
| | | import java.util.function.Function; |
| | | import java.util.Map; |
| | |
| | | } |
| | | 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(); |
| | |
| | | return processed; |
| | | } |
| | | |
| | | public static String randomNumbers(int length) { |
| | | String baseString = "0123456789"; |
| | | |
| | | if (length < 1) { |
| | | length = 1; |
| | | } |
| | | |
| | | StringBuilder sb = new StringBuilder(length); |
| | | int baseLength = baseString.length(); |
| | | |
| | | for(int i = 0; i < length; ++i) { |
| | | int number = ThreadLocalRandom.current().nextInt(baseLength); |
| | | sb.append(baseString.charAt(number)); |
| | | } |
| | | |
| | | return sb.toString(); |
| | | } |
| | | |
| | | } |