+ *
+ * @return A string representation of this {@code UUID}
*/
public static String toString(UUID uuid, boolean isSimple) {
long mostSigBits = uuid.getMostSignificantBits();
diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/Joiner.java b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/Joiner.java
index 05eefe1f..de798647 100644
--- a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/Joiner.java
+++ b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/Joiner.java
@@ -23,7 +23,8 @@ import java.util.Iterator;
import java.util.Objects;
/**
- * reference google guava
+ * reference google guava
+ * com.google.common.base.Joiner
*/
public class Joiner {
diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/MapUtil.java b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/MapUtil.java
index 7436cfda..f23b0a04 100644
--- a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/MapUtil.java
+++ b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/MapUtil.java
@@ -17,10 +17,7 @@
package cn.hippo4j.common.toolkit;
-import java.util.Collection;
-import java.util.Dictionary;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Predicate;
@@ -151,6 +148,41 @@ public class MapUtil {
return val;
}
+ /**
+ * Fuzzy matching based on Key.
+ *
+ * @param sourceMap
+ * @param filters
+ * @return
+ */
+ public static List parseMapForFilter(Map sourceMap, String filters) {
+ List resultList = new ArrayList<>();
+ if (CollectionUtil.isEmpty(sourceMap)) {
+ return resultList;
+ }
+ sourceMap.forEach((key, val) -> {
+ if (checkKey(key, filters)) {
+ resultList.add(key);
+ }
+ });
+ return resultList;
+ }
+
+ /**
+ * Match the characters you want to query.
+ *
+ * @param key
+ * @param filters
+ * @return
+ */
+ private static boolean checkKey(String key, String filters) {
+ if (key.indexOf(filters) > -1) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
/**
* remove value, Thread safety depends on whether the Map is a thread-safe Map.
*
diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/Md5Util.java b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/Md5Util.java
index 931f683d..1e410b02 100644
--- a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/Md5Util.java
+++ b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/Md5Util.java
@@ -28,6 +28,7 @@ import java.util.List;
/**
* MD5 util.
+ * Refer to com.alibaba.nacos.common.util.Md5Utils:
*/
public class Md5Util {
@@ -96,16 +97,12 @@ public class Md5Util {
sb.append(Constants.WORD_SEPARATOR);
sb.append(dataIdGroupId[1]);
// if have tenant, then set it
- if (dataIdGroupId.length == DATA_ID_GROUP_ID_THREE_LEN) {
- if (StringUtil.isNotBlank(dataIdGroupId[2])) {
- sb.append(Constants.WORD_SEPARATOR);
- sb.append(dataIdGroupId[2]);
- }
- } else if (dataIdGroupId.length == DATA_ID_GROUP_ID_FOUR_LEN) {
- if (StringUtil.isNotBlank(dataIdGroupId[2])) {
- sb.append(Constants.WORD_SEPARATOR);
- sb.append(dataIdGroupId[2]);
- }
+ boolean b = (dataIdGroupId.length == DATA_ID_GROUP_ID_THREE_LEN
+ || dataIdGroupId.length == DATA_ID_GROUP_ID_FOUR_LEN)
+ && StringUtil.isNotBlank(dataIdGroupId[2]);
+ if (b) {
+ sb.append(Constants.WORD_SEPARATOR);
+ sb.append(dataIdGroupId[2]);
}
sb.append(Constants.LINE_SEPARATOR);
}
diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/MemoryUtil.java b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/MemoryUtil.java
new file mode 100644
index 00000000..3b62bab9
--- /dev/null
+++ b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/MemoryUtil.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package cn.hippo4j.common.toolkit;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.MemoryUsage;
+
+/**
+ * memory util
+ * the obtained information is not invalid, after a long wait, obtain it again
+ *
+ * @author liuwenhao
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class MemoryUtil {
+
+ static MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
+ static MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage();
+ static MemoryUsage noHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage();
+
+ /**
+ * get used memory in heap
+ *
+ * @return long bytes
+ */
+ public static long heapMemoryUsed() {
+ return heapMemoryUsage.getUsed();
+ }
+
+ /**
+ * get max memory in heap
+ *
+ * @return long bytes
+ */
+ public static long heapMemoryMax() {
+ return heapMemoryUsage.getMax();
+ }
+
+ /**
+ * get free memory in heap
+ *
+ * @return long bytes
+ */
+ public static long heapMemoryFree() {
+ return Math.subtractExact(heapMemoryMax(), heapMemoryUsed());
+ }
+
+ /**
+ * get used memory in no-heap
+ *
+ * @return long bytes
+ */
+ public static long noHeapMemoryUsed() {
+ return noHeapMemoryUsage.getUsed();
+ }
+
+ /**
+ * get max memory in no-heap
+ *
+ * @return long bytes
+ */
+ public static long noHeapMemoryMax() {
+ return noHeapMemoryUsage.getMax();
+ }
+
+ /**
+ * get free memory in no-heap
+ *
+ * @return long bytes
+ */
+ public static long noHeapMemoryFree() {
+ return Math.subtractExact(noHeapMemoryMax(), noHeapMemoryUsed());
+ }
+
+}
diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/ReflectUtil.java b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/ReflectUtil.java
index 35ae9095..9a4bfa86 100644
--- a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/ReflectUtil.java
+++ b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/ReflectUtil.java
@@ -29,10 +29,13 @@ import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ThreadPoolExecutor;
/**
- * Reflect util.
+ * Reflect util.
+ * Refer to cn.hutool.core.util.ReflectUtil:
+ * {@link this#getFieldsDirectly(Class, boolean)}
+ * {@link this#setFieldValue(Object, Field, Object)}
+ * {@link this#getDefaultValue(Class)}
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ReflectUtil {
diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/StringUtil.java b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/StringUtil.java
index c9fcde40..1134b34b 100644
--- a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/StringUtil.java
+++ b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/StringUtil.java
@@ -21,7 +21,11 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
- * String util.
+ * String util.
+ * Refer to cn.hutool.core.util.StrUtil:
+ * {@link this#toSymbolCase(CharSequence, char)}
+ * {@link this#toCamelCase(CharSequence, char)}
+ * {@link this#subBefore(String, String)}
*/
public class StringUtil {
@@ -53,8 +57,9 @@ public class StringUtil {
/**
* Returns {@code true} if the given string is null or is the empty string.
- *
+ *
* this method has been deprecated, use isEmpty() instead.
+ *
* @param str
* @return
*/
@@ -302,7 +307,8 @@ public class StringUtil {
* StringUtils.split("abc def", " ") = ["abc", "def"]
* StringUtils.split("ab:cd:ef", ":") = ["ab", "cd", "ef"]
*
- * @param str the String to parse, may be null
+ *
+ * @param str the String to parse, may be null
* @param separatorChars the characters used as the delimiters,
* @return an array of parsed Strings
*/
diff --git a/hippo4j-server/hippo4j-config/src/test/java/cn/hippo4j/config/toolkit/MapUtilTest.java b/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/MapUtilTest.java
similarity index 85%
rename from hippo4j-server/hippo4j-config/src/test/java/cn/hippo4j/config/toolkit/MapUtilTest.java
rename to hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/MapUtilTest.java
index 440b84dd..b0c00d04 100644
--- a/hippo4j-server/hippo4j-config/src/test/java/cn/hippo4j/config/toolkit/MapUtilTest.java
+++ b/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/MapUtilTest.java
@@ -15,10 +15,8 @@
* limitations under the License.
*/
-package cn.hippo4j.config.toolkit;
+package cn.hippo4j.common.toolkit;
-import cn.hippo4j.common.toolkit.Assert;
-import cn.hippo4j.common.toolkit.CollectionUtil;
import org.junit.Test;
import java.util.HashMap;
@@ -66,9 +64,9 @@ public class MapUtilTest {
@Test
public void computeIfAbsentNotExistKeyTest() {
- Map