删除 ImmutableObject,使用 com.google.errorprone.annotations.Immutable

dev
ZhouXY108 2024-10-21 00:26:06 +08:00
parent fa5b8aba7d
commit 85939e4fc4
3 changed files with 18 additions and 62 deletions

View File

@ -1,48 +0,0 @@
/*
* Copyright 2024 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.annotation;
import java.lang.annotation.Target;
import com.google.common.annotations.Beta;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
*
* <pre>@ImmutableObject
* class Foo {
* private final @Getter int intVal;
* private final @Getter String stringVal;
* private final @Getter LocalDate dateVal;
* private final @Getter BigDecimal decimalVal;
* }
* </pre>
* <p>
* guava ImmutableListImmutableMap
* <p>
*
* @author <a href="http://zhouxy.xyz:3000/ZhouXY108">ZhouXY</a>
* @since 0.1.0
*/
@Beta
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ImmutableObject {
}

View File

@ -21,9 +21,11 @@ import java.util.Optional;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.errorprone.annotations.Immutable;
import xyz.zhouxy.plusone.commons.util.Numbers; import xyz.zhouxy.plusone.commons.util.Numbers;
@Immutable
public class Interval<T extends Comparable<T>> { public class Interval<T extends Comparable<T>> {
@Nonnull @Nonnull
private final IntervalType intervalType; private final IntervalType intervalType;
@ -50,29 +52,29 @@ public class Interval<T extends Comparable<T>> {
} }
@Nonnull @Nonnull
public IntervalType getIntervalType() { public final IntervalType getIntervalType() {
return intervalType; return intervalType;
} }
@Nonnull @Nonnull
public Optional<T> getLowerBound() { public final Optional<T> getLowerBound() {
return Optional.ofNullable(lowerBound); return Optional.ofNullable(lowerBound);
} }
@Nonnull @Nonnull
public Optional<T> getUpperBound() { public final Optional<T> getUpperBound() {
return Optional.ofNullable(upperBound); return Optional.ofNullable(upperBound);
} }
public boolean isLeftClosed() { public final boolean isLeftClosed() {
return this.intervalType.isLeftClosed(); return this.intervalType.isLeftClosed();
} }
public boolean isRightClosed() { public final boolean isRightClosed() {
return this.intervalType.isRightClosed(); return this.intervalType.isRightClosed();
} }
public boolean validValue(@Nonnull T value) { public final boolean validValue(@Nonnull T value) {
return Numbers.between(value, this.lowerBound, this.upperBound, this.intervalType); return Numbers.between(value, this.lowerBound, this.upperBound, this.intervalType);
} }
} }

View File

@ -29,12 +29,14 @@ import java.util.Objects;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.errorprone.annotations.Immutable;
/** /**
* *
* *
* @author zhouxy * @author zhouxy
*/ */
@Immutable
public final class YearQuarter implements Comparable<YearQuarter>, Serializable { public final class YearQuarter implements Comparable<YearQuarter>, Serializable {
private static final long serialVersionUID = 3804145964419489753L; private static final long serialVersionUID = 3804145964419489753L;
@ -57,7 +59,7 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
/** /**
* {@link YearQuarter} * {@link YearQuarter}
* *
* @param year * @param year
* @param quarter * @param quarter
* @return {@link YearQuarter} * @return {@link YearQuarter}
@ -68,7 +70,7 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
/** /**
* {@link YearQuarter} * {@link YearQuarter}
* *
* @param year * @param year
* @param quarter * @param quarter
* @return {@link YearQuarter} * @return {@link YearQuarter}
@ -79,7 +81,7 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
/** /**
* {@link YearQuarter} * {@link YearQuarter}
* *
* @param date * @param date
* @return {@link YearQuarter} * @return {@link YearQuarter}
*/ */
@ -89,7 +91,7 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
/** /**
* {@link YearQuarter} * {@link YearQuarter}
* *
* @param date * @param date
* @return {@link YearQuarter} * @return {@link YearQuarter}
*/ */
@ -103,7 +105,7 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
/** /**
* {@link YearQuarter} * {@link YearQuarter}
* *
* @param date * @param date
* @return {@link YearQuarter} * @return {@link YearQuarter}
*/ */
@ -113,7 +115,7 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
/** /**
* {@link YearQuarter} * {@link YearQuarter}
* *
* @param yearMonth * @param yearMonth
* @return {@link YearQuarter} * @return {@link YearQuarter}
*/ */
@ -238,7 +240,7 @@ public final class YearQuarter implements Comparable<YearQuarter>, Serializable
/** /**
* {@link YearQuarter} "2024 Q3" * {@link YearQuarter} "2024 Q3"
* *
* @return {@link YearQuarter} * @return {@link YearQuarter}
*/ */
@Override @Override