From 9a0b6404cb78c6e55c0e7c9ea7f903529a9fcb0e Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Fri, 15 Mar 2024 09:19:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20equalsCode=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/xyz/zhouxy/plusone/commons/base/IWithCode.java | 6 ++++++ .../java/xyz/zhouxy/plusone/commons/base/IWithIntCode.java | 4 ++++ .../java/xyz/zhouxy/plusone/commons/base/IWithLongCode.java | 4 ++++ 3 files changed, 14 insertions(+) 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; + } }