Revert "HashMap应指定初始长度"

This reverts commit 4f04bd121a4f769f28728ccbc4d41e0c742a82cc.
This commit is contained in:
achao 2021-11-10 20:29:41 +08:00
parent 4f04bd121a
commit 1e7af4d7fc
2 changed files with 9 additions and 9 deletions

View File

@ -179,7 +179,7 @@ public class CollStreamUtil {
Set<K> key = new HashSet<>(); Set<K> key = new HashSet<>();
key.addAll(map1.keySet()); key.addAll(map1.keySet());
key.addAll(map2.keySet()); key.addAll(map2.keySet());
Map<K, V> map = MapUtil.newHashMap(key.size()); Map<K, V> map = new HashMap<>();
for (K t : key) { for (K t : key) {
X x = map1.get(t); X x = map1.get(t);
Y y = map2.get(t); Y y = map2.get(t);

View File

@ -7,12 +7,12 @@ import cn.hutool.core.math.Calculator;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.security.SecureRandom;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.text.ParseException; import java.text.ParseException;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Random;
import java.util.Set; import java.util.Set;
/** /**
@ -1362,8 +1362,8 @@ public class NumberUtil {
throw new UtilException("Size is larger than range between begin and end!"); throw new UtilException("Size is larger than range between begin and end!");
} }
SecureRandom ran = new SecureRandom(); Random ran = new Random();
Set<Integer> set = new HashSet<>(Math.max((int) (size / .75f) + 1, 16)); Set<Integer> set = new HashSet<>();
while (set.size() < size) { while (set.size() < size) {
set.add(begin + ran.nextInt(end - begin)); set.add(begin + ran.nextInt(end - begin));
} }
@ -2159,14 +2159,14 @@ public class NumberUtil {
* @since 4.0.9 * @since 4.0.9
*/ */
public static BigDecimal toBigDecimal(String numberStr) { public static BigDecimal toBigDecimal(String numberStr) {
if (StrUtil.isBlank(numberStr)) { if(StrUtil.isBlank(numberStr)){
return BigDecimal.ZERO; return BigDecimal.ZERO;
} }
try { try {
// 支持类似于 1,234.55 格式的数字 // 支持类似于 1,234.55 格式的数字
final Number number = parseNumber(numberStr); final Number number = parseNumber(numberStr);
if (number instanceof BigDecimal) { if(number instanceof BigDecimal){
return (BigDecimal) number; return (BigDecimal) number;
} else { } else {
return new BigDecimal(number.toString()); return new BigDecimal(number.toString());
@ -2512,7 +2512,7 @@ public class NumberUtil {
public static Number parseNumber(String numberStr) throws NumberFormatException { public static Number parseNumber(String numberStr) throws NumberFormatException {
try { try {
final NumberFormat format = NumberFormat.getInstance(); final NumberFormat format = NumberFormat.getInstance();
if (format instanceof DecimalFormat) { if(format instanceof DecimalFormat){
// issue#1818@Github // issue#1818@Github
// 当字符串数字超出double的长度时会导致截断此处使用BigDecimal接收 // 当字符串数字超出double的长度时会导致截断此处使用BigDecimal接收
((DecimalFormat) format).setParseBigDecimal(true); ((DecimalFormat) format).setParseBigDecimal(true);
@ -2699,9 +2699,9 @@ public class NumberUtil {
* @since 5.7.8 * @since 5.7.8
*/ */
public static double toDouble(Number value) { public static double toDouble(Number value) {
if (value instanceof Float) { if(value instanceof Float){
return Double.parseDouble(value.toString()); return Double.parseDouble(value.toString());
} else { }else{
return value.doubleValue(); return value.doubleValue();
} }
} }