diff --git a/pom.xml b/pom.xml
index 9370c02..bca7374 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
org.kangspace.devhelper
dev-helper
- 0.0.3-SNAPSHOT
+ 0.0.3
jar
dev-helper
@@ -75,7 +75,7 @@
2.13.3
1.7.30
2.9.0
- 2.12.5
+ 2.15.2
4.13.2
4.1.79.Final
diff --git a/src/main/java/org/kangspace/devhelper/CollectionUtil.java b/src/main/java/org/kangspace/devhelper/CollectionUtil.java
index 01ad677..62c7c8f 100644
--- a/src/main/java/org/kangspace/devhelper/CollectionUtil.java
+++ b/src/main/java/org/kangspace/devhelper/CollectionUtil.java
@@ -15,7 +15,7 @@ public static boolean isEmpty(Collection> collection) {
return collection == null || collection.isEmpty();
}
- public static boolean isEmpty(Map map) {
+ public static boolean isEmpty(Map,?> map) {
return map == null || map.isEmpty();
}
@@ -23,6 +23,10 @@ public static boolean isNotEmpty(Collection> collection) {
return !isEmpty(collection);
}
+ public static boolean isNotEmpty(Map,?> map) {
+ return !isEmpty(map);
+ }
+
public static T first(Collection collection) {
return isNotEmpty(collection) ? collection.stream().findFirst().orElse(null) : null;
}
diff --git a/src/main/java/org/kangspace/devhelper/http/UrlHelper.java b/src/main/java/org/kangspace/devhelper/http/UrlHelper.java
index 9b98e62..b4228d2 100644
--- a/src/main/java/org/kangspace/devhelper/http/UrlHelper.java
+++ b/src/main/java/org/kangspace/devhelper/http/UrlHelper.java
@@ -1,6 +1,7 @@
package org.kangspace.devhelper.http;
import org.kangspace.devhelper.str.StringHelper;
+import org.kangspace.devhelper.str.StringLiteral;
import javax.annotation.Nonnull;
import java.io.UnsupportedEncodingException;
@@ -73,4 +74,27 @@ public static String url(String urlPattern, String... params) {
}
return MessageFormat.format(urlPattern, vars);
}
+
+ /**
+ * url参数替换
+ * @param url url
+ * @param name 参数名
+ * @param value 参数值
+ */
+ public static String urlReplaceParam(String url, String name, String value) {
+ // 如何url中包含name参数,则删除并替换为新的value,如果不存在name,则添加该参数到url中
+ String regex = "([?&])" + name + "=.*?(&|$)";
+ url = url.replaceAll(regex, "$1" + name + "=" + value + "$2");
+ String prefix = name + StringLiteral.EQUALS;
+ if(!url.contains(prefix)){
+ url += (url.contains(StringLiteral.QUESTION_MARK) ? StringLiteral.AND : StringLiteral.QUESTION_MARK) + prefix + value;
+ }
+ return url;
+ }
+
+ public static void main(String[] args) {
+ System.out.println(urlReplaceParam("http://example.com/?a=1&b=2", "b", "3"));
+ System.out.println(urlReplaceParam("http://example.com/", "b", "3"));
+ System.out.println(urlReplaceParam("http://example.com/?b=2", "b", "3"));
+ }
}
diff --git a/src/main/java/org/kangspace/devhelper/thread/ThreadUtil.java b/src/main/java/org/kangspace/devhelper/thread/ThreadUtil.java
index 73f4658..c2bb4ff 100644
--- a/src/main/java/org/kangspace/devhelper/thread/ThreadUtil.java
+++ b/src/main/java/org/kangspace/devhelper/thread/ThreadUtil.java
@@ -10,11 +10,25 @@
*/
public class ThreadUtil {
+ /**
+ * 线程Sleep
+ *
+ * @param baseMillis 基于
+ */
+ @SuppressWarnings("all")
+ public static void sleep(int baseMillis) {
+ try {
+ Thread.sleep(baseMillis);
+ } catch (InterruptedException e) {
+ }
+ }
+
/**
* 线程随机Sleep
*
* @param baseMillis 基于
*/
+ @SuppressWarnings("all")
public static void randomSleep(int baseMillis) {
long sleepMillis = new Random().nextInt(baseMillis);
try {