mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
Merge branch 'v6-dev' of gitee.com:dromara/hutool into v6-dev
This commit is contained in:
commit
bd50e7f474
@ -12,10 +12,10 @@
|
||||
|
||||
package org.dromara.hutool.core.stream;
|
||||
|
||||
import org.dromara.hutool.core.array.ArrayUtil;
|
||||
import org.dromara.hutool.core.lang.Opt;
|
||||
import org.dromara.hutool.core.lang.mutable.MutableInt;
|
||||
import org.dromara.hutool.core.lang.mutable.MutableObj;
|
||||
import org.dromara.hutool.core.array.ArrayUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
@ -214,7 +214,7 @@ public interface TerminableWrappedStream<T, S extends TerminableWrappedStream<T,
|
||||
*/
|
||||
default <U> Map<Integer, U> toIdxMap(final Function<? super T, ? extends U> valueMapper) {
|
||||
final MutableInt index = new MutableInt(NOT_FOUND_ELEMENT_INDEX);
|
||||
return EasyStream.of(toList()).toMap(e -> index.incrementAndGet(), valueMapper, (l, r) -> r);
|
||||
return EasyStream.of(sequential().toList()).toMap(e -> index.incrementAndGet(), valueMapper, (l, r) -> r);
|
||||
}
|
||||
|
||||
// region ============ to zip ============
|
||||
@ -269,16 +269,12 @@ public interface TerminableWrappedStream<T, S extends TerminableWrappedStream<T,
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
default int findFirstIdx(final Predicate<? super T> predicate) {
|
||||
Objects.requireNonNull(predicate);
|
||||
if (isParallel()) {
|
||||
return NOT_FOUND_ELEMENT_INDEX;
|
||||
} else {
|
||||
final MutableInt index = new MutableInt(NOT_FOUND_ELEMENT_INDEX);
|
||||
unwrap().filter(e -> {
|
||||
index.increment();
|
||||
return predicate.test(e);
|
||||
}).findFirst();// 此处只做计数,不需要值
|
||||
return index.get();
|
||||
}
|
||||
final MutableInt index = new MutableInt(NOT_FOUND_ELEMENT_INDEX);
|
||||
unwrap().filter(e -> {
|
||||
index.increment();
|
||||
return predicate.test(e);
|
||||
}).findFirst();// 此处只做计数,不需要值
|
||||
return index.get();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -317,17 +313,13 @@ public interface TerminableWrappedStream<T, S extends TerminableWrappedStream<T,
|
||||
*/
|
||||
default int findLastIdx(final Predicate<? super T> predicate) {
|
||||
Objects.requireNonNull(predicate);
|
||||
if (isParallel()) {
|
||||
return NOT_FOUND_ELEMENT_INDEX;
|
||||
} else {
|
||||
final MutableInt idxRef = new MutableInt(NOT_FOUND_ELEMENT_INDEX);
|
||||
forEachIdx((e, i) -> {
|
||||
if (predicate.test(e)) {
|
||||
idxRef.set(i);
|
||||
}
|
||||
});
|
||||
return idxRef.get();
|
||||
}
|
||||
final MutableInt idxRef = new MutableInt(NOT_FOUND_ELEMENT_INDEX);
|
||||
forEachIdx((e, i) -> {
|
||||
if (predicate.test(e)) {
|
||||
idxRef.set(i);
|
||||
}
|
||||
});
|
||||
return idxRef.get();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -505,13 +497,8 @@ public interface TerminableWrappedStream<T, S extends TerminableWrappedStream<T,
|
||||
*/
|
||||
default void forEachIdx(final BiConsumer<? super T, Integer> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if (isParallel()) {
|
||||
EasyStream.of(toIdxMap().entrySet()).parallel(isParallel())
|
||||
.forEach(e -> action.accept(e.getValue(), e.getKey()));
|
||||
} else {
|
||||
final MutableInt index = new MutableInt(NOT_FOUND_ELEMENT_INDEX);
|
||||
unwrap().forEach(e -> action.accept(e, index.incrementAndGet()));
|
||||
}
|
||||
final MutableInt index = new MutableInt(NOT_FOUND_ELEMENT_INDEX);
|
||||
unwrap().forEach(e -> action.accept(e, index.incrementAndGet()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -522,14 +509,8 @@ public interface TerminableWrappedStream<T, S extends TerminableWrappedStream<T,
|
||||
*/
|
||||
default void forEachOrderedIdx(final BiConsumer<? super T, Integer> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if (isParallel()) {
|
||||
EasyStream.of(toIdxMap().entrySet())
|
||||
.parallel(isParallel())
|
||||
.forEachOrdered(e -> action.accept(e.getValue(), e.getKey()));
|
||||
} else {
|
||||
final MutableInt index = new MutableInt(NOT_FOUND_ELEMENT_INDEX);
|
||||
unwrap().forEachOrdered(e -> action.accept(e, index.incrementAndGet()));
|
||||
}
|
||||
final MutableInt index = new MutableInt(NOT_FOUND_ELEMENT_INDEX);
|
||||
unwrap().forEachOrdered(e -> action.accept(e, index.incrementAndGet()));
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
package org.dromara.hutool.core.stream;
|
||||
|
||||
import org.dromara.hutool.core.array.ArrayUtil;
|
||||
import org.dromara.hutool.core.collection.ListUtil;
|
||||
import org.dromara.hutool.core.collection.iter.IterUtil;
|
||||
import org.dromara.hutool.core.lang.Console;
|
||||
@ -19,7 +20,6 @@ import org.dromara.hutool.core.lang.mutable.MutableInt;
|
||||
import org.dromara.hutool.core.lang.mutable.MutableObj;
|
||||
import org.dromara.hutool.core.map.MapUtil;
|
||||
import org.dromara.hutool.core.map.SafeConcurrentHashMap;
|
||||
import org.dromara.hutool.core.array.ArrayUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@ -279,16 +279,8 @@ public interface TransformableWrappedStream<T, S extends TransformableWrappedStr
|
||||
*/
|
||||
default S peekIdx(final BiConsumer<? super T, Integer> action) {
|
||||
Objects.requireNonNull(action);
|
||||
if (isParallel()) {
|
||||
final Map<Integer, T> idxMap = easyStream().toIdxMap();
|
||||
return wrap(EasyStream.of(idxMap.entrySet())
|
||||
.parallel(isParallel())
|
||||
.peek(e -> action.accept(e.getValue(), e.getKey()))
|
||||
.map(Map.Entry::getValue));
|
||||
} else {
|
||||
final AtomicInteger index = new AtomicInteger(NOT_FOUND_ELEMENT_INDEX);
|
||||
return peek(e -> action.accept(e, index.incrementAndGet()));
|
||||
}
|
||||
final AtomicInteger index = new AtomicInteger(NOT_FOUND_ELEMENT_INDEX);
|
||||
return peek(e -> action.accept(e, index.incrementAndGet()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -383,16 +375,8 @@ public interface TransformableWrappedStream<T, S extends TransformableWrappedStr
|
||||
*/
|
||||
default S filterIdx(final BiPredicate<? super T, Integer> predicate) {
|
||||
Objects.requireNonNull(predicate);
|
||||
if (isParallel()) {
|
||||
final Map<Integer, T> idxMap = easyStream().toIdxMap();
|
||||
return wrap(EasyStream.of(idxMap.entrySet())
|
||||
.parallel(isParallel())
|
||||
.filter(e -> predicate.test(e.getValue(), e.getKey()))
|
||||
.map(Map.Entry::getValue));
|
||||
} else {
|
||||
final MutableInt index = new MutableInt(NOT_FOUND_ELEMENT_INDEX);
|
||||
return filter(e -> predicate.test(e, index.incrementAndGet()));
|
||||
}
|
||||
final MutableInt index = new MutableInt(NOT_FOUND_ELEMENT_INDEX);
|
||||
return filter(e -> predicate.test(e, index.incrementAndGet()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -440,15 +424,8 @@ public interface TransformableWrappedStream<T, S extends TransformableWrappedStr
|
||||
*/
|
||||
default <R> EasyStream<R> flatMapIdx(final BiFunction<? super T, Integer, ? extends Stream<? extends R>> mapper) {
|
||||
Objects.requireNonNull(mapper);
|
||||
if (isParallel()) {
|
||||
final Map<Integer, T> idxMap = easyStream().toIdxMap();
|
||||
return EasyStream.of(idxMap.entrySet())
|
||||
.parallel(isParallel())
|
||||
.flatMap(e -> mapper.apply(e.getValue(), e.getKey()));
|
||||
} else {
|
||||
final MutableInt index = new MutableInt(NOT_FOUND_ELEMENT_INDEX);
|
||||
return flatMap(e -> mapper.apply(e, index.incrementAndGet()));
|
||||
}
|
||||
final MutableInt index = new MutableInt(NOT_FOUND_ELEMENT_INDEX);
|
||||
return flatMap(e -> mapper.apply(e, index.incrementAndGet()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -553,15 +530,8 @@ public interface TransformableWrappedStream<T, S extends TransformableWrappedStr
|
||||
*/
|
||||
default <R> EasyStream<R> mapIdx(final BiFunction<? super T, Integer, ? extends R> mapper) {
|
||||
Objects.requireNonNull(mapper);
|
||||
if (isParallel()) {
|
||||
final Map<Integer, T> idxMap = easyStream().toIdxMap();
|
||||
return EasyStream.of(idxMap.entrySet())
|
||||
.parallel(isParallel())
|
||||
.map(e -> mapper.apply(e.getValue(), e.getKey()));
|
||||
} else {
|
||||
final MutableInt index = new MutableInt(NOT_FOUND_ELEMENT_INDEX);
|
||||
return map(e -> mapper.apply(e, index.incrementAndGet()));
|
||||
}
|
||||
final MutableInt index = new MutableInt(NOT_FOUND_ELEMENT_INDEX);
|
||||
return map(e -> mapper.apply(e, index.incrementAndGet()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,7 +12,6 @@ import org.junit.jupiter.api.Test;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@ -145,9 +144,6 @@ public class EasyStreamTest {
|
||||
final List<String> list = Arrays.asList("dromara", "hutool", "sweet");
|
||||
final List<String> mapIndex = EasyStream.of(list).mapIdx((e, i) -> i + 1 + "." + e).toList();
|
||||
Assertions.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), mapIndex);
|
||||
// 并行流时正常
|
||||
Assertions.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"),
|
||||
EasyStream.of("dromara", "hutool", "sweet").parallel().mapIdx((e, i) -> i + 1 + "." + e).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -199,10 +195,6 @@ public class EasyStreamTest {
|
||||
final EasyStream.Builder<String> builder = EasyStream.builder();
|
||||
EasyStream.of(list).forEachIdx((e, i) -> builder.accept(i + 1 + "." + e));
|
||||
Assertions.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), builder.build().toList());
|
||||
// 并行流时正常
|
||||
final AtomicInteger total = new AtomicInteger(0);
|
||||
EasyStream.of("dromara", "hutool", "sweet").parallel().forEachIdx((e, i) -> total.addAndGet(i));
|
||||
Assertions.assertEquals(3, total.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -223,10 +215,6 @@ public class EasyStreamTest {
|
||||
final List<String> list = Arrays.asList("dromara", "hutool", "sweet");
|
||||
final List<String> mapIndex = EasyStream.of(list).flatMapIdx((e, i) -> EasyStream.of(i + 1 + "." + e)).toList();
|
||||
Assertions.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"), mapIndex);
|
||||
// 并行流时正常
|
||||
Assertions.assertEquals(Arrays.asList("1.dromara", "2.hutool", "3.sweet"),
|
||||
EasyStream.of("dromara", "hutool", "sweet").parallel()
|
||||
.flatMapIdx((e, i) -> EasyStream.of(i + 1 + "." + e)).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -280,9 +268,6 @@ public class EasyStreamTest {
|
||||
final List<String> list = Arrays.asList("dromara", "hutool", "sweet");
|
||||
final List<String> filterIndex = EasyStream.of(list).filterIdx((e, i) -> i < 2).toList();
|
||||
Assertions.assertEquals(Arrays.asList("dromara", "hutool"), filterIndex);
|
||||
// 并行流时正常
|
||||
Assertions.assertEquals(Arrays.asList("dromara", "hutool"),
|
||||
EasyStream.of("dromara", "hutool", "sweet").parallel().filterIdx((e, i) -> i < 2).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -350,7 +335,6 @@ public class EasyStreamTest {
|
||||
public void testFindFirstIdx() {
|
||||
final List<Integer> list = Arrays.asList(null, 2, 3);
|
||||
Assertions.assertEquals(1, EasyStream.of(list).findFirstIdx(Objects::nonNull));
|
||||
Assertions.assertEquals(-1, (Object) EasyStream.of(list).parallel().findFirstIdx(Objects::nonNull));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -370,7 +354,6 @@ public class EasyStreamTest {
|
||||
public void testFindLastIdx() {
|
||||
final List<Integer> list = Arrays.asList(1, null, 3);
|
||||
Assertions.assertEquals(2, (Object) EasyStream.of(list).findLastIdx(Objects::nonNull));
|
||||
Assertions.assertEquals(-1, (Object) EasyStream.of(list).parallel().findLastIdx(Objects::nonNull));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -15,14 +15,12 @@ package org.dromara.hutool.crypto.asymmetric;
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.crypto.asymmetric.paillier.PaillierCrypto;
|
||||
import org.dromara.hutool.crypto.asymmetric.paillier.PaillierKeyPairGenerator;
|
||||
import org.dromara.hutool.crypto.asymmetric.paillier.PaillierProvider;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.security.KeyPair;
|
||||
import java.security.KeyPairGenerator;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.Security;
|
||||
|
||||
public class PaillierTest {
|
||||
@Test
|
||||
@ -35,7 +33,6 @@ public class PaillierTest {
|
||||
|
||||
@Test
|
||||
void keyPairGeneratorByJceTest() throws NoSuchAlgorithmException {
|
||||
Security.addProvider(new PaillierProvider());
|
||||
final KeyPairGenerator generator = KeyPairGenerator.getInstance("Paillier");
|
||||
final KeyPair keyPair = generator.generateKeyPair();
|
||||
Assertions.assertNotNull(keyPair.getPrivate());
|
||||
|
@ -12,8 +12,9 @@
|
||||
|
||||
package org.dromara.hutool.json;
|
||||
|
||||
import org.dromara.hutool.core.io.file.FileUtil;
|
||||
import org.dromara.hutool.core.convert.Convert;
|
||||
import org.dromara.hutool.core.io.IORuntimeException;
|
||||
import org.dromara.hutool.core.io.file.FileUtil;
|
||||
import org.dromara.hutool.core.lang.Assert;
|
||||
import org.dromara.hutool.core.reflect.TypeReference;
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
@ -27,7 +28,10 @@ import org.dromara.hutool.json.writer.JSONValueWriter;
|
||||
import org.dromara.hutool.json.writer.JSONWriter;
|
||||
import org.dromara.hutool.json.xml.JSONXMLUtil;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
@ -388,7 +392,8 @@ public class JSONUtil {
|
||||
return ((JSON) json).toBean(type);
|
||||
}
|
||||
|
||||
throw new JSONException("Unsupported json string to bean : {}", json);
|
||||
//issue#I7CW27,其他类型使用默认转换
|
||||
return Convert.convert(type, json);
|
||||
}
|
||||
// -------------------------------------------------------------------- toBean end
|
||||
|
||||
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2023 looly(loolly@aliyun.com)
|
||||
* Hutool is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
package org.dromara.hutool.json;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class IssueI7CW27Test {
|
||||
|
||||
@Test
|
||||
void longToBeanTest() {
|
||||
final String number = "123123123";
|
||||
final Long bean = JSONUtil.toBean(number, Long.class);
|
||||
|
||||
Assertions.assertEquals(123123123L, bean);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user