diff --git a/src/main/java/xyz/zhouxy/plusone/commons/base/IWithCode.java b/src/main/java/xyz/zhouxy/plusone/commons/base/IWithCode.java index 5c1ecbc..508e27b 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/base/IWithCode.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/base/IWithCode.java @@ -16,6 +16,8 @@ package xyz.zhouxy.plusone.commons.base; +import java.util.Objects; + import javax.annotation.Nonnull; /** @@ -28,4 +30,8 @@ import javax.annotation.Nonnull; public interface IWithCode { @Nonnull T getCode(); + + default boolean equalsCode(T code) { + return Objects.equals(getCode(), code); + } } diff --git a/src/main/java/xyz/zhouxy/plusone/commons/base/IWithIntCode.java b/src/main/java/xyz/zhouxy/plusone/commons/base/IWithIntCode.java index dcd9b03..0085bea 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/base/IWithIntCode.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/base/IWithIntCode.java @@ -25,4 +25,8 @@ package xyz.zhouxy.plusone.commons.base; */ public interface IWithIntCode { int getCode(); + + default boolean equalsCode(int code) { + return getCode() == code; + } } diff --git a/src/main/java/xyz/zhouxy/plusone/commons/base/IWithLongCode.java b/src/main/java/xyz/zhouxy/plusone/commons/base/IWithLongCode.java index 759ef21..3859d61 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/base/IWithLongCode.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/base/IWithLongCode.java @@ -25,4 +25,8 @@ package xyz.zhouxy.plusone.commons.base; */ public interface IWithLongCode { long getCode(); + + default boolean equalsCode(long code) { + return getCode() == code; + } }