From d81e68995ae64f6783701ed3e252f1ce7591a66a Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Mon, 13 Mar 2023 14:25:28 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/xyz/zhouxy/plusone/commons/util/Arrays2.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/Arrays2.java b/src/main/java/xyz/zhouxy/plusone/commons/util/Arrays2.java index 829dbb2..1780055 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/Arrays2.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/Arrays2.java @@ -31,6 +31,14 @@ public abstract class Arrays2 { return values; } + public static double[] of(final double... values) { + return values; + } + + public static float[] of(final float... values) { + return values; + } + private Arrays2() { throw new IllegalStateException("Utility class"); } From 481253c65dcfff1533199e29eab41b26fa3556a1 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Mon, 13 Mar 2023 14:26:03 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20copyright=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plusone/commons/constant/PatternConsts.java | 16 ++++++++++++++++ .../plusone/commons/constant/RegexConsts.java | 16 ++++++++++++++++ .../plusone/commons/exception/BaseException.java | 16 ++++++++++++++++ .../plusone/commons/exception/IWithCode.java | 16 ++++++++++++++++ .../xyz/zhouxy/plusone/commons/util/Arrays2.java | 16 ++++++++++++++++ .../zhouxy/plusone/commons/util/EnumUtil.java | 16 ++++++++++++++++ .../zhouxy/plusone/commons/util/Enumeration.java | 16 ++++++++++++++++ .../zhouxy/plusone/commons/util/NumberUtil.java | 16 ++++++++++++++++ .../xyz/zhouxy/plusone/commons/util/PageDTO.java | 16 ++++++++++++++++ .../util/PagingAndSortingQueryParams.java | 16 ++++++++++++++++ .../zhouxy/plusone/commons/util/RegexUtil.java | 16 ++++++++++++++++ .../plusone/commons/util/RestfulResult.java | 16 ++++++++++++++++ 12 files changed, 192 insertions(+) diff --git a/src/main/java/xyz/zhouxy/plusone/commons/constant/PatternConsts.java b/src/main/java/xyz/zhouxy/plusone/commons/constant/PatternConsts.java index 9efcf24..9c09f6f 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/constant/PatternConsts.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/constant/PatternConsts.java @@ -1,3 +1,19 @@ +/* + * 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.constant; import java.util.regex.Pattern; diff --git a/src/main/java/xyz/zhouxy/plusone/commons/constant/RegexConsts.java b/src/main/java/xyz/zhouxy/plusone/commons/constant/RegexConsts.java index 2daf331..2601c2a 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/constant/RegexConsts.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/constant/RegexConsts.java @@ -1,3 +1,19 @@ +/* + * 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.constant; /** diff --git a/src/main/java/xyz/zhouxy/plusone/commons/exception/BaseException.java b/src/main/java/xyz/zhouxy/plusone/commons/exception/BaseException.java index 87cf1d7..1e4e930 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/exception/BaseException.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/exception/BaseException.java @@ -1,3 +1,19 @@ +/* + * 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.exception; /** diff --git a/src/main/java/xyz/zhouxy/plusone/commons/exception/IWithCode.java b/src/main/java/xyz/zhouxy/plusone/commons/exception/IWithCode.java index 8671f54..d061c36 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/exception/IWithCode.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/exception/IWithCode.java @@ -1,3 +1,19 @@ +/* + * 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.exception; /** diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/Arrays2.java b/src/main/java/xyz/zhouxy/plusone/commons/util/Arrays2.java index 1780055..95eb458 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/Arrays2.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/Arrays2.java @@ -1,3 +1,19 @@ +/* + * 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; public abstract class Arrays2 { diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/EnumUtil.java b/src/main/java/xyz/zhouxy/plusone/commons/util/EnumUtil.java index 832d270..7135319 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/EnumUtil.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/EnumUtil.java @@ -1,3 +1,19 @@ +/* + * 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 java.util.Objects; diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/Enumeration.java b/src/main/java/xyz/zhouxy/plusone/commons/util/Enumeration.java index f94a4a8..9b028af 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/Enumeration.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/Enumeration.java @@ -1,3 +1,19 @@ +/* + * 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 java.util.Map; diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/NumberUtil.java b/src/main/java/xyz/zhouxy/plusone/commons/util/NumberUtil.java index 7078ba3..eb32634 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/NumberUtil.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/NumberUtil.java @@ -1,3 +1,19 @@ +/* + * 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; /** diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/PageDTO.java b/src/main/java/xyz/zhouxy/plusone/commons/util/PageDTO.java index 9fa076a..fbd265a 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/PageDTO.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/PageDTO.java @@ -1,3 +1,19 @@ +/* + * 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 java.util.List; 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 9dadeca..fb15ca6 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/PagingAndSortingQueryParams.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/PagingAndSortingQueryParams.java @@ -1,3 +1,19 @@ +/* + * 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 java.util.Arrays; diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/RegexUtil.java b/src/main/java/xyz/zhouxy/plusone/commons/util/RegexUtil.java index 0b0df2d..e9d1689 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/RegexUtil.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/RegexUtil.java @@ -1,3 +1,19 @@ +/* + * 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 java.util.regex.Pattern; diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/RestfulResult.java b/src/main/java/xyz/zhouxy/plusone/commons/util/RestfulResult.java index 674d77f..4f09d6e 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/RestfulResult.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/RestfulResult.java @@ -1,3 +1,19 @@ +/* + * 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 com.fasterxml.jackson.annotation.JsonInclude; From 0b80cf34ba27de32b8e04fc90dd5812c030c7d67 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Mon, 13 Mar 2023 16:25:13 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BE=9D=E8=B5=96=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pom.xml b/pom.xml index 994ed99..b192fbf 100644 --- a/pom.xml +++ b/pom.xml @@ -28,5 +28,12 @@ jackson-annotations ${jackson.version} + + + org.junit.jupiter + junit-jupiter-api + 5.9.2 + test + \ No newline at end of file From 61bd352fd7202405ccb7b9474ff7216537be1ef4 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Mon, 13 Mar 2023 16:33:38 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20toString=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/xyz/zhouxy/plusone/commons/util/Enumeration.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/Enumeration.java b/src/main/java/xyz/zhouxy/plusone/commons/util/Enumeration.java index 9b028af..b1255d3 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/Enumeration.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/Enumeration.java @@ -59,9 +59,7 @@ public abstract class Enumeration> { @Override public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("[").append(value).append(": ").append(name).append("]"); - return builder.toString(); + return "[" + value + ": " + name + "]"; } protected static final class EnumerationValuesHolder> { From a9bc2bfdc27ec198b2e0060f5a3f54299e88d2a7 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Fri, 17 Mar 2023 18:19:26 +0800 Subject: [PATCH 5/6] =?UTF-8?q?jsr305=20=E5=92=8C=20guava=20=E4=BD=9C?= =?UTF-8?q?=E4=B8=BA=E9=BB=98=E8=AE=A4=E5=BC=95=E5=85=A5=E7=9A=84=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index b192fbf..9ebd1b5 100644 --- a/pom.xml +++ b/pom.xml @@ -14,20 +14,32 @@ 1.8 1.18.24 2.13.4 + 3.0.2 + 31.1-jre - org.projectlombok - lombok - ${lombok.version} - true + com.google.code.findbugs + jsr305 + ${google-jsr305.version} + + + com.google.guava + guava + ${guava.version} com.fasterxml.jackson.core jackson-annotations ${jackson.version} + + org.projectlombok + lombok + ${lombok.version} + true + org.junit.jupiter From e3af2bd4e7bc0df2892917975b6043f445b2a118 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Fri, 17 Mar 2023 18:20:19 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=87=8D=E8=BD=BD?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plusone/commons/util/NumberUtil.java | 26 ++++++++++++- .../plusone/commons/EnumerationTests.java | 39 +++++++++++++++++++ .../plusone/commons/util/NumberUtilTest.java | 35 +++++++++++++++++ 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/test/java/xyz/zhouxy/plusone/commons/EnumerationTests.java create mode 100644 src/test/java/xyz/zhouxy/plusone/commons/util/NumberUtilTest.java diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/NumberUtil.java b/src/main/java/xyz/zhouxy/plusone/commons/util/NumberUtil.java index eb32634..088e005 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/NumberUtil.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/NumberUtil.java @@ -27,7 +27,15 @@ public class NumberUtil { throw new IllegalStateException("Utility class"); } - public static int sum(int... numbers) { + public static int sum(short... numbers) { + int result = 0; + for (short number : numbers) { + result += number; + } + return result; + } + + public static long sum(int... numbers) { int result = 0; for (int number : numbers) { result += number; @@ -42,4 +50,20 @@ public class NumberUtil { } return result; } + + public static double sum(float... numbers) { + double result = 0; + for (double number : numbers) { + result += number; + } + return result; + } + + public static double sum(double... numbers) { + double result = 0; + for (double number : numbers) { + result += number; + } + return result; + } } diff --git a/src/test/java/xyz/zhouxy/plusone/commons/EnumerationTests.java b/src/test/java/xyz/zhouxy/plusone/commons/EnumerationTests.java new file mode 100644 index 0000000..6e950a7 --- /dev/null +++ b/src/test/java/xyz/zhouxy/plusone/commons/EnumerationTests.java @@ -0,0 +1,39 @@ +package xyz.zhouxy.plusone.commons; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +import xyz.zhouxy.plusone.commons.util.Enumeration; + +class EnumerationTests { + + @Test + void testEnumeration() { + assertEquals(EntityStatus.AVAILABLE, EntityStatus.of(0)); + } +} + +final class EntityStatus extends Enumeration { + + private EntityStatus(int value, String name) { + super(value, name); + } + + // 常量 + public static final EntityStatus AVAILABLE = new EntityStatus(0, "正常"); + public static final EntityStatus DISABLED = new EntityStatus(1, "禁用"); + + private static final EnumerationValuesHolder ENUMERATION_VALUES = new EnumerationValuesHolder<>( + AVAILABLE, + DISABLED); + + public static EntityStatus of(int value) { + return ENUMERATION_VALUES.get(value); + } + + @Override + public String toString() { + return "EntityStatus" + super.toString(); + } +} \ No newline at end of file diff --git a/src/test/java/xyz/zhouxy/plusone/commons/util/NumberUtilTest.java b/src/test/java/xyz/zhouxy/plusone/commons/util/NumberUtilTest.java new file mode 100644 index 0000000..f330013 --- /dev/null +++ b/src/test/java/xyz/zhouxy/plusone/commons/util/NumberUtilTest.java @@ -0,0 +1,35 @@ +package xyz.zhouxy.plusone.commons.util; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +class NumberUtilTest { + @Test + void testSum() { + long result = 0; + for (int i = 0; i < Integer.MAX_VALUE; i++) { + result += Short.MAX_VALUE; + } + System.out.println("Integer.MAX_VALUE: " + Integer.MAX_VALUE); + System.out.println("result: " + result); + assertFalse(Integer.MAX_VALUE > result); + + result = 0; + for (int i = 0; i < Integer.MAX_VALUE; i++) { + result += Short.MAX_VALUE; + } + System.out.println("Long.MAX_VALUE: " + Long.MAX_VALUE); + System.out.println("result: " + result); + assertTrue(Long.MAX_VALUE > result); + + result = 0; + for (int i = 0; i < Integer.MAX_VALUE; i++) { + result += Integer.MAX_VALUE; + } + System.out.println("Long.MAX_VALUE: " + Long.MAX_VALUE); + System.out.println("result: " + result); + assertTrue(Long.MAX_VALUE > result); + } +}