temp = new HashMap<>();
for (T value : values) {
- builder.put(value.getId(), value);
+ temp.put(value.getId(), value);
}
- return new ValueSet<>(builder.build());
+ return new ValueSet<>(Collections.unmodifiableMap(temp));
}
public T get(int id) {
diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/MoreArrays.java b/src/main/java/xyz/zhouxy/plusone/commons/util/MoreArrays.java
deleted file mode 100644
index 284244e..0000000
--- a/src/main/java/xyz/zhouxy/plusone/commons/util/MoreArrays.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright 2022-2023 the original author or authors.
- *
- * Licensed 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
- *
- * https://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 xyz.zhouxy.plusone.commons.util;
-
-import javax.annotation.Nullable;
-
-/**
- * MoreArrays
- *
- *
- * 数组工具类
- *
- * @author ZhouXY
- * @since 0.1.0
- */
-public class MoreArrays {
-
- @SafeVarargs
- public static T[] newArray(final T... values) {
- return values;
- }
-
- public static short[] newArray(final short... values) {
- return values;
- }
-
- public static int[] newArray(final int... values) {
- return values;
- }
-
- public static long[] newArray(final long... values) {
- return values;
- }
-
- public static byte[] newArray(final byte... values) {
- return values;
- }
-
- public static boolean[] newArray(final boolean... values) {
- return values;
- }
-
- public static char[] newArray(final char... values) {
- return values;
- }
-
- public static double[] newArray(final double... values) {
- return values;
- }
-
- public static float[] newArray(final float... values) {
- return values;
- }
-
- public static boolean isEmpty(@Nullable int[] arr) {
- return arr == null || arr.length == 0;
- }
-
- public static boolean isNotEmpty(@Nullable int[] arr) {
- return arr != null && arr.length > 0;
- }
-
- public static boolean isEmpty(@Nullable long[] arr) {
- return arr == null || arr.length == 0;
- }
-
- public static boolean isNotEmpty(@Nullable long[] arr) {
- return arr != null && arr.length > 0;
- }
-
- public static boolean isEmpty(@Nullable double[] arr) {
- return arr == null || arr.length == 0;
- }
-
- public static boolean isNotEmpty(@Nullable double[] arr) {
- return arr != null && arr.length > 0;
- }
-
- public static boolean isEmpty(@Nullable T[] arr) {
- return arr == null || arr.length == 0;
- }
-
- public static boolean isNotEmpty(@Nullable T[] arr) {
- return arr != null && arr.length > 0;
- }
-
- private MoreArrays() {
- throw new IllegalStateException("Utility class");
- }
-}
diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/MoreStrings.java b/src/main/java/xyz/zhouxy/plusone/commons/util/MoreStrings.java
deleted file mode 100644
index a1bd9e7..0000000
--- a/src/main/java/xyz/zhouxy/plusone/commons/util/MoreStrings.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package xyz.zhouxy.plusone.commons.util;
-
-import javax.annotation.Nullable;
-
-public class MoreStrings {
- public static boolean hasText(@Nullable String str) {
- return (str != null && !str.isEmpty() && containsText(str));
- }
-
- private static boolean containsText(CharSequence str) {
- int strLen = str.length();
- for (int i = 0; i < strLen; i++) {
- if (!Character.isWhitespace(str.charAt(i))) {
- return true;
- }
- }
- return false;
- }
-
- private MoreStrings() {
- throw new IllegalStateException("Utility class");
- }
-}
diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/PagingAndSortingQueryParams.java b/src/main/java/xyz/zhouxy/plusone/commons/util/PagingAndSortingQueryParams.java
index 1c412c6..b34bea2 100644
--- a/src/main/java/xyz/zhouxy/plusone/commons/util/PagingAndSortingQueryParams.java
+++ b/src/main/java/xyz/zhouxy/plusone/commons/util/PagingAndSortingQueryParams.java
@@ -16,15 +16,14 @@
package xyz.zhouxy.plusone.commons.util;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-
import xyz.zhouxy.plusone.commons.annotation.Overridable;
/**
@@ -41,27 +40,28 @@ import xyz.zhouxy.plusone.commons.annotation.Overridable;
public class PagingAndSortingQueryParams {
private static final int DEFAULT_PAGE_SIZE = 15;
- protected final List orderBy = Lists.newLinkedList();
+ protected final List orderBy = new LinkedList<>();
protected int size;
protected long pageNum;
private final Set sortableColNames;
public PagingAndSortingQueryParams() {
- this.sortableColNames = ImmutableSet.of();
+ this.sortableColNames = Collections.emptySet();
}
public PagingAndSortingQueryParams(String... sortableColNames) {
for (String colName : sortableColNames) {
- Assert.hasText(colName, "Column name must has text.");
+ Assert.isNotBlank(colName, "Column name must has text.");
}
- this.sortableColNames = ImmutableSet.copyOf(sortableColNames);
+ Set sortableColNameSet = new HashSet<>(sortableColNames.length);
+ this.sortableColNames = Collections.unmodifiableSet(sortableColNameSet);
}
// Getters
public final List getOrderBy() {
- return ImmutableList.copyOf(this.orderBy);
+ return Collections.unmodifiableList(this.orderBy);
}
public final int getSize() {
diff --git a/src/test/java/xyz/zhouxy/plusone/commons/EnumerationTests.java b/src/test/java/xyz/zhouxy/plusone/commons/EnumerationTests.java
index b1d5154..dd04458 100644
--- a/src/test/java/xyz/zhouxy/plusone/commons/EnumerationTests.java
+++ b/src/test/java/xyz/zhouxy/plusone/commons/EnumerationTests.java
@@ -2,13 +2,13 @@ package xyz.zhouxy.plusone.commons;
import static org.junit.jupiter.api.Assertions.assertSame;
-import com.google.common.collect.Lists;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xyz.zhouxy.plusone.commons.util.Enumeration;
+import java.util.ArrayList;
import java.util.Collection;
class EnumerationTests {
@@ -19,7 +19,7 @@ class EnumerationTests {
void testEnumeration() {
assertSame(EntityStatus.AVAILABLE, EntityStatus.of(0));
assertSame(Result.SUCCESSFUL, Result.of(1));
- Collection>> enums = Lists.newArrayList();
+ Collection>> enums = new ArrayList<>();
enums.addAll(EntityStatus.constants());
enums.addAll(Result.constants());
for (Comparable extends Enumeration>> anEnum : enums) {
diff --git a/src/test/java/xyz/zhouxy/plusone/commons/function/FunctionTests.java b/src/test/java/xyz/zhouxy/plusone/commons/function/FunctionTests.java
index 1ec1353..00e5825 100644
--- a/src/test/java/xyz/zhouxy/plusone/commons/function/FunctionTests.java
+++ b/src/test/java/xyz/zhouxy/plusone/commons/function/FunctionTests.java
@@ -13,7 +13,7 @@ class FunctionTests {
void test() {
String str = "";
Predicate predicate = Predicates.of(Objects::nonNull)
- .and(StringUtils::isNotEmpty);
+ .and(StringUtils::isNotBlank);
Assert.isFalse(predicate.test(str), "校验应是不通过");
}
}