diff --git a/README.md b/README.md index b975eba74..c58f33376 100644 --- a/README.md +++ b/README.md @@ -161,8 +161,8 @@ Hutool欢迎任何人为Hutool添砖加瓦,贡献代码,不过作者是一 1. 在Gitee或者Github上fork项目到自己的repo 2. 把fork过去的项目也就是你的项目clone到你的本地 -3. 修改代码(记得一定要修改v4-dev分支) -4. commit后push到自己的库(v4-dev分支) +3. 修改代码(记得一定要修改v5-dev分支) +4. commit后push到自己的库(v5-dev分支) 5. 登录Gitee或Github在你首页可以看到一个 pull request 按钮,点击它,填写一些说明信息,然后提交即可。 6. 等待作者合并 diff --git a/hutool-setting/src/main/java/cn/hutool/setting/AbsSetting.java b/hutool-setting/src/main/java/cn/hutool/setting/AbsSetting.java index 9b12531c0..9466eceb9 100644 --- a/hutool-setting/src/main/java/cn/hutool/setting/AbsSetting.java +++ b/hutool-setting/src/main/java/cn/hutool/setting/AbsSetting.java @@ -266,11 +266,7 @@ public abstract class AbsSetting extends OptNullBasicTypeFromStringGetter valueMap = this.get(group); - if (null == valueMap) { - valueMap = new LinkedHashMap<>(); - this.put(group, valueMap); - } + final LinkedHashMap valueMap = this.computeIfAbsent(group, k -> new LinkedHashMap<>()); this.size = -1; return valueMap.put(key, value); } finally { diff --git a/hutool-setting/src/main/java/cn/hutool/setting/GroupedSet.java b/hutool-setting/src/main/java/cn/hutool/setting/GroupedSet.java index 6703e8830..13adfaf2e 100644 --- a/hutool-setting/src/main/java/cn/hutool/setting/GroupedSet.java +++ b/hutool-setting/src/main/java/cn/hutool/setting/GroupedSet.java @@ -199,7 +199,7 @@ public class GroupedSet extends HashMap> { try { reader = IoUtil.getReader(settingStream, charset); // 分组 - String group = null; + String group; LinkedHashSet valueSet = null; while (true) { @@ -223,7 +223,7 @@ public class GroupedSet extends HashMap> { group = line.substring(1, line.length() - 1).trim(); valueSet = super.get(group); if (null == valueSet) { - valueSet = new LinkedHashSet(); + valueSet = new LinkedHashSet<>(); } super.put(group, valueSet); continue; @@ -232,7 +232,7 @@ public class GroupedSet extends HashMap> { // 添加值 if (null == valueSet) { // 当出现无分组值的时候,会导致valueSet为空,此时group为"" - valueSet = new LinkedHashSet(); + valueSet = new LinkedHashSet<>(); super.put(StrUtil.EMPTY, valueSet); } valueSet.add(line); diff --git a/hutool-setting/src/main/java/cn/hutool/setting/Setting.java b/hutool-setting/src/main/java/cn/hutool/setting/Setting.java index 310f41555..69941d927 100644 --- a/hutool-setting/src/main/java/cn/hutool/setting/Setting.java +++ b/hutool-setting/src/main/java/cn/hutool/setting/Setting.java @@ -258,14 +258,14 @@ public class Setting extends AbsSetting implements Map { * @since 3.1.2 */ public String getAndRemoveStr(String... keys) { - Object value = null; + String value = null; for (String key : keys) { value = remove(key); if (null != value) { break; } } - return (String) value; + return value; } /** @@ -276,7 +276,7 @@ public class Setting extends AbsSetting implements Map { */ public Map getMap(String group) { final LinkedHashMap map = this.groupedMap.get(group); - return (null != map) ? map : new LinkedHashMap(0); + return (null != map) ? map : new LinkedHashMap<>(0); } /** @@ -692,13 +692,10 @@ public class Setting extends AbsSetting implements Map { return false; } if (settingUrl == null) { - if (other.settingUrl != null) { - return false; - } - } else if (!settingUrl.equals(other.settingUrl)) { - return false; + return other.settingUrl == null; + } else { + return settingUrl.equals(other.settingUrl); } - return true; } @Override diff --git a/hutool-setting/src/main/java/cn/hutool/setting/SettingLoader.java b/hutool-setting/src/main/java/cn/hutool/setting/SettingLoader.java index d2eef9471..c1021cd7a 100644 --- a/hutool-setting/src/main/java/cn/hutool/setting/SettingLoader.java +++ b/hutool-setting/src/main/java/cn/hutool/setting/SettingLoader.java @@ -202,7 +202,7 @@ public class SettingLoader { */ private String replaceVar(String group, String value) { // 找到所有变量标识 - final Set vars = ReUtil.findAll(varRegex, value, 0, new HashSet()); + final Set vars = ReUtil.findAll(varRegex, value, 0, new HashSet<>()); String key; for (String var : vars) { key = ReUtil.get(varRegex, var, 1); diff --git a/hutool-setting/src/main/java/cn/hutool/setting/SettingUtil.java b/hutool-setting/src/main/java/cn/hutool/setting/SettingUtil.java index 3a5ff1a94..2dfed771c 100644 --- a/hutool-setting/src/main/java/cn/hutool/setting/SettingUtil.java +++ b/hutool-setting/src/main/java/cn/hutool/setting/SettingUtil.java @@ -16,7 +16,7 @@ import cn.hutool.core.util.StrUtil; public class SettingUtil { /** 配置文件缓存 */ private static Map settingMap = new ConcurrentHashMap<>(); - private static Object lock = new Object(); + private static final Object lock = new Object(); /** * 获取当前环境下的配置文件
diff --git a/hutool-system/src/main/java/cn/hutool/system/oshi/OshiUtil.java b/hutool-system/src/main/java/cn/hutool/system/oshi/OshiUtil.java index 0a67ebd04..b44a11101 100644 --- a/hutool-system/src/main/java/cn/hutool/system/oshi/OshiUtil.java +++ b/hutool-system/src/main/java/cn/hutool/system/oshi/OshiUtil.java @@ -16,6 +16,8 @@ import oshi.software.os.OperatingSystem; * 1、系统信息 * 2、硬件信息 * + * + * 相关内容见:https://github.com/oshi/oshi * * @author Looly * @since 4.6.4