mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
|
||||
package cn.hutool.core.map;
|
||||
|
||||
import cn.hutool.core.array.ArrayUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.collection.iter.ArrayIter;
|
||||
@@ -19,23 +20,11 @@ import cn.hutool.core.collection.iter.IterUtil;
|
||||
import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.reflect.ConstructorUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.array.ArrayUtil;
|
||||
import cn.hutool.core.util.JdkUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
@@ -1282,6 +1271,7 @@ public class MapUtil extends MapGetUtil {
|
||||
* 方法来自Dubbo,解决使用ConcurrentHashMap.computeIfAbsent导致的死循环问题。(issues#2349)<br>
|
||||
* A temporary workaround for Java 8 specific performance issue JDK-8161372 .<br>
|
||||
* This class should be removed once we drop Java 8 support.
|
||||
* 参考:https://github.com/apache/dubbo/blob/3.2/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ConcurrentHashMapUtils.java
|
||||
*
|
||||
* @param <K> 键类型
|
||||
* @param <V> 值类型
|
||||
@@ -1292,11 +1282,15 @@ public class MapUtil extends MapGetUtil {
|
||||
* @see <a href="https://bugs.openjdk.java.net/browse/JDK-8161372">https://bugs.openjdk.java.net/browse/JDK-8161372</a>
|
||||
*/
|
||||
public static <K, V> V computeIfAbsent(final Map<K, V> map, final K key, final Function<? super K, ? extends V> mappingFunction) {
|
||||
if (JdkUtil.IS_JDK8) {
|
||||
V value = map.get(key);
|
||||
if (null == value) {
|
||||
map.putIfAbsent(key, mappingFunction.apply(key));
|
||||
value = map.get(key);
|
||||
//map.putIfAbsent(key, mappingFunction.apply(key));
|
||||
value = map.computeIfAbsent(key, mappingFunction);
|
||||
}
|
||||
return value;
|
||||
} else {
|
||||
return map.computeIfAbsent(key, mappingFunction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -57,18 +57,19 @@ public class JdkUtil {
|
||||
* @return JVM名称
|
||||
*/
|
||||
private static String _getJvmName() {
|
||||
return System.getProperty("java.vm.name");
|
||||
return SystemUtil.getQuietly("java.vm.name");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据{@code java.specification.version}属性值,获取版本号
|
||||
* 根据{@code java.specification.version}属性值,获取版本号<br>
|
||||
* 默认8
|
||||
*
|
||||
* @return 版本号
|
||||
*/
|
||||
private static int _getJvmVersion() {
|
||||
int jvmVersion = -1;
|
||||
int jvmVersion = 8;
|
||||
|
||||
String javaSpecVer = System.getProperty("java.specification.version");
|
||||
String javaSpecVer = SystemUtil.getQuietly("java.specification.version");
|
||||
if (StrUtil.isNotBlank(javaSpecVer)) {
|
||||
if (javaSpecVer.startsWith("1.")) {
|
||||
javaSpecVer = javaSpecVer.substring(2);
|
||||
|
@@ -30,7 +30,9 @@ import java.util.Properties;
|
||||
*/
|
||||
public class SystemUtil {
|
||||
|
||||
/** Hutool自定义系统属性:是否解析日期字符串采用严格模式 */
|
||||
/**
|
||||
* Hutool自定义系统属性:是否解析日期字符串采用严格模式
|
||||
*/
|
||||
public static String HUTOOL_DATE_LENIENT = "hutool.date.lenient";
|
||||
|
||||
/**
|
||||
@@ -43,7 +45,31 @@ public class SystemUtil {
|
||||
* @see System#getenv(String)
|
||||
*/
|
||||
public static String get(final String name, final String defaultValue) {
|
||||
return ObjUtil.defaultIfNull(get(name, false), defaultValue);
|
||||
return ObjUtil.defaultIfNull(get(name), defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得System属性
|
||||
*
|
||||
* @param key 键
|
||||
* @return 属性值
|
||||
* @see System#getProperty(String)
|
||||
* @see System#getenv(String)
|
||||
*/
|
||||
public static String get(final String key) {
|
||||
return get(key, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得System属性,忽略无权限问题
|
||||
*
|
||||
* @param key 键
|
||||
* @return 属性值
|
||||
* @see System#getProperty(String)
|
||||
* @see System#getenv(String)
|
||||
*/
|
||||
public static String getQuietly(final String key) {
|
||||
return get(key, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,18 +106,6 @@ public class SystemUtil {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得System属性
|
||||
*
|
||||
* @param key 键
|
||||
* @return 属性值
|
||||
* @see System#getProperty(String)
|
||||
* @see System#getenv(String)
|
||||
*/
|
||||
public static String get(final String key) {
|
||||
return get(key, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得boolean类型值
|
||||
*
|
||||
|
Reference in New Issue
Block a user