格式化代码。

This commit is contained in:
zhouxy108 2024-10-21 23:17:52 +08:00
parent 443116a5a2
commit f4b7005b92
16 changed files with 139 additions and 120 deletions

View File

@ -27,7 +27,7 @@ import java.lang.annotation.Documented;
* *
* <p>标识方法为不支持的操作该方法将抛出 {@link UnsupportedOperationException} * <p>标识方法为不支持的操作该方法将抛出 {@link UnsupportedOperationException}
* *
* @author zhouxy * @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
* @version 1.0 * @version 1.0
* @since 1.0 * @since 1.0
* @see UnsupportedOperationException * @see UnsupportedOperationException

View File

@ -55,7 +55,7 @@ public final class Ref<T> {
return this.value != null; return this.value != null;
} }
public void execute(Consumer<T> consumer) { public void execute(Consumer<? super T> consumer) {
consumer.accept(value); consumer.accept(value);
} }

View File

@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
package xyz.zhouxy.plusone.commons.model; package xyz.zhouxy.plusone.commons.model;
import java.time.LocalDate; import java.time.LocalDate;

View File

@ -20,6 +20,8 @@ import xyz.zhouxy.plusone.commons.util.AssertTools;
/** /**
* 性别 * 性别
*
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
*/ */
public enum Gender { public enum Gender {
UNKNOWN(0, "Unknown", "未知"), UNKNOWN(0, "Unknown", "未知"),

View File

@ -194,7 +194,7 @@ public abstract class UnifiedResponse {
/** /**
* 自定义结果 * 自定义结果
* *
* @author zhouxy * @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
*/ */
protected static class CustomResult extends UnifiedResponse { protected static class CustomResult extends UnifiedResponse {

View File

@ -21,7 +21,7 @@ import org.apache.ibatis.jdbc.AbstractSQL;
import com.google.common.annotations.Beta; import com.google.common.annotations.Beta;
/** /**
* @author ZhouXY * @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
*/ */
@Beta @Beta
public abstract class SQL<T> extends AbstractSQL<T> { public abstract class SQL<T> extends AbstractSQL<T> {

View File

@ -27,7 +27,7 @@ import xyz.zhouxy.plusone.commons.util.Numbers;
/** /**
* 季度 * 季度
* *
* @author zhouxy * @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
*/ */
public enum Quarter { public enum Quarter {
/** 第一季度 */ /** 第一季度 */

View File

@ -31,10 +31,12 @@ import javax.annotation.Nonnull;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.errorprone.annotations.Immutable; import com.google.errorprone.annotations.Immutable;
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
/** /**
* 表示年份与季度 * 表示年份与季度
* *
* @author zhouxy * @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
*/ */
@Immutable @Immutable
public final class YearQuarter implements Comparable<YearQuarter>, Serializable { public final class YearQuarter implements Comparable<YearQuarter>, Serializable {
@ -57,6 +59,8 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
this.lastDate = quarter.lastMonthDay().atYear(year); this.lastDate = quarter.lastMonthDay().atYear(year);
} }
// #region - StaticFactoryMethod
/** /**
* 根据指定年份与季度创建 {@link YearQuarter} 实例 * 根据指定年份与季度创建 {@link YearQuarter} 实例
* *
@ -64,6 +68,7 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
* @param quarter 季度 * @param quarter 季度
* @return {@link YearQuarter} 实例 * @return {@link YearQuarter} 实例
*/ */
@StaticFactoryMethod(YearQuarter.class)
public static YearQuarter of(int year, int quarter) { public static YearQuarter of(int year, int quarter) {
return of(year, Quarter.of(quarter)); return of(year, Quarter.of(quarter));
} }
@ -75,6 +80,7 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
* @param quarter 季度 * @param quarter 季度
* @return {@link YearQuarter} 实例 * @return {@link YearQuarter} 实例
*/ */
@StaticFactoryMethod(YearQuarter.class)
public static YearQuarter of(int year, @Nonnull Quarter quarter) { public static YearQuarter of(int year, @Nonnull Quarter quarter) {
return new YearQuarter(year, quarter); return new YearQuarter(year, quarter);
} }
@ -85,6 +91,7 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
* @param date 日期 * @param date 日期
* @return {@link YearQuarter} 实例 * @return {@link YearQuarter} 实例
*/ */
@StaticFactoryMethod(YearQuarter.class)
public static YearQuarter of(@Nonnull LocalDate date) { public static YearQuarter of(@Nonnull LocalDate date) {
return of(date.getYear(), Quarter.fromMonth(date.getMonth())); return of(date.getYear(), Quarter.fromMonth(date.getMonth()));
} }
@ -95,6 +102,7 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
* @param date 日期 * @param date 日期
* @return {@link YearQuarter} 实例 * @return {@link YearQuarter} 实例
*/ */
@StaticFactoryMethod(YearQuarter.class)
public static YearQuarter of(@Nonnull Date date) { public static YearQuarter of(@Nonnull Date date) {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
final int year = date.getYear() + 1900; final int year = date.getYear() + 1900;
@ -109,6 +117,7 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
* @param date 日期 * @param date 日期
* @return {@link YearQuarter} 实例 * @return {@link YearQuarter} 实例
*/ */
@StaticFactoryMethod(YearQuarter.class)
public static YearQuarter of(Calendar date) { public static YearQuarter of(Calendar date) {
return of(date.get(Calendar.YEAR), Quarter.fromMonth(date.get(Calendar.MONTH) + 1)); return of(date.get(Calendar.YEAR), Quarter.fromMonth(date.get(Calendar.MONTH) + 1));
} }
@ -119,11 +128,14 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
* @param yearMonth 年月 * @param yearMonth 年月
* @return {@link YearQuarter} 实例 * @return {@link YearQuarter} 实例
*/ */
@StaticFactoryMethod(YearQuarter.class)
public static YearQuarter of(YearMonth yearMonth) { public static YearQuarter of(YearMonth yearMonth) {
return of(yearMonth.getYear(), Quarter.fromMonth(yearMonth.getMonth())); return of(yearMonth.getYear(), Quarter.fromMonth(yearMonth.getMonth()));
} }
// Getters // #endregion
// #region - Getters
public int getYear() { public int getYear() {
return year; return year;
@ -165,9 +177,9 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
return lastDate; return lastDate;
} }
// Getters end // #endregion
// computes // #region - computes
public YearQuarter plusQuarters(long quartersToAdd) { // TODO 单元测试 public YearQuarter plusQuarters(long quartersToAdd) { // TODO 单元测试
if (quartersToAdd == 0) { if (quartersToAdd == 0) {
@ -196,9 +208,9 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
return plusYears(-yearsToAdd); return plusYears(-yearsToAdd);
} }
// computes end // #endregion
// hashCode & equals // #region - hashCode & equals
@Override @Override
public int hashCode() { public int hashCode() {
@ -217,7 +229,9 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
return year == other.year && quarter == other.quarter; return year == other.year && quarter == other.quarter;
} }
// compareTo // #endregion
// #region - compareTo
@Override @Override
public int compareTo(YearQuarter other) { public int compareTo(YearQuarter other) {
@ -236,7 +250,9 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
return this.compareTo(other) > 0; return this.compareTo(other) > 0;
} }
// toString // #endregion
// #region - toString
/** /**
* 返回 {@link YearQuarter} 的字符串表示形式 "2024 Q3" * 返回 {@link YearQuarter} 的字符串表示形式 "2024 Q3"
@ -247,4 +263,6 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
public String toString() { public String toString() {
return this.year + " " + this.quarter.name(); return this.year + " " + this.quarter.name();
} }
// #endregion
} }

View File

@ -24,17 +24,17 @@ import javax.annotation.Nonnull;
* 断言工具 * 断言工具
* *
* <p> * <p>
* 本工具类基本仅对表达式进行判断并在表达式为 {@code false} 时抛出对应异常 * 本工具类不封装过多判断逻辑鼓励充分使用项目中的工具类进行逻辑判断
* 不封装过多判断逻辑鼓励充分使用项目中的工具类进行逻辑判断
* </p> * </p>
* *
* <pre> * <pre>
* AssertTools.checkArgument(StringUtils.hasText(str), "The argument cannot be blank."); * AssertTools.checkArgument(StringUtils.hasText(str), "The argument cannot be blank.");
* AssertTools.checkState(ArrayUtils.isNotEmpty(result), "The result cannot be empty."); * AssertTools.checkState(ArrayUtils.isNotEmpty(result), "The result cannot be empty.");
* AssertTools.checkCondition(!CollectionUtils.isEmpty(roles), () -> new InvalidInputException("The roles cannot be empty.")); * AssertTools.checkCondition(!CollectionUtils.isEmpty(roles), () -> new InvalidInputException("The roles cannot be empty."));
* AssertTools.checkCondition(RegexTools.matches(email, PatternConsts.EMAIL), "must be a well-formed email address");
* </pre> * </pre>
* *
* @author ZhouXY * @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
*/ */
public class AssertTools { public class AssertTools {

View File

@ -21,9 +21,9 @@ import javax.annotation.Nullable;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
public class BigDecimals { import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
public static final BigDecimal ZERO = new BigDecimal("0.00"); public class BigDecimals {
public static boolean equalsValue(@Nullable BigDecimal a, @Nullable BigDecimal b) { public static boolean equalsValue(@Nullable BigDecimal a, @Nullable BigDecimal b) {
return (a == b) || (a != null && a.compareTo(b) == 0); return (a == b) || (a != null && a.compareTo(b) == 0);
@ -49,8 +49,9 @@ public class BigDecimals {
return lt(a, b) || equalsValue(a, b); return lt(a, b) || equalsValue(a, b);
} }
@StaticFactoryMethod(BigDecimal.class)
public static BigDecimal of(final String val) { public static BigDecimal of(final String val) {
return (StringTools.isNotBlank(val)) ? new BigDecimal(val) : ZERO; return (StringTools.isNotBlank(val)) ? new BigDecimal(val) : BigDecimal.ZERO;
} }
private BigDecimals() { private BigDecimals() {

View File

@ -41,7 +41,7 @@ import xyz.zhouxy.plusone.commons.time.YearQuarter;
/** /**
* 日期时间工具类 * 日期时间工具类
* *
* @author zhouxy * @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
*/ */
public class DateTimeTools { public class DateTimeTools {

View File

@ -19,6 +19,7 @@ package xyz.zhouxy.plusone.commons.util;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -27,12 +28,10 @@ import javax.annotation.Nullable;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import xyz.zhouxy.plusone.commons.collection.SafeConcurrentHashMap;
/** /**
* 封装一些常用的正则操作并可以缓存 {@link Pattern} 实例以复用最多缓存大概 256 * 封装一些常用的正则操作并可以缓存 {@link Pattern} 实例以复用最多缓存大概 256
* *
* @author ZhouXY * @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
* *
*/ */
public final class RegexTools { public final class RegexTools {
@ -40,7 +39,7 @@ public final class RegexTools {
private static final int DEFAULT_CACHE_INITIAL_CAPACITY = 64; private static final int DEFAULT_CACHE_INITIAL_CAPACITY = 64;
private static final int MAX_CACHE_SIZE = 256; private static final int MAX_CACHE_SIZE = 256;
private static final Map<String, Pattern> PATTERN_CACHE private static final Map<String, Pattern> PATTERN_CACHE
= new SafeConcurrentHashMap<>(DEFAULT_CACHE_INITIAL_CAPACITY); = new ConcurrentHashMap<>(DEFAULT_CACHE_INITIAL_CAPACITY);
/** /**
* 获取 {@link Pattern} 实例 * 获取 {@link Pattern} 实例