From 1853461f098f046b62c8690d3f3de13002d4ea52 Mon Sep 17 00:00:00 2001 From: LamGC Date: Thu, 19 Nov 2020 22:09:33 +0800 Subject: [PATCH] =?UTF-8?q?[Change]=20Framework-API=20=E8=A1=A5=E5=85=85?= =?UTF-8?q?=20Platform=20=E7=9A=84=E6=96=87=E6=A1=A3,=20=E5=B9=B6=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20equals=20=E5=92=8C=20hashCode=20=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E8=A6=86=E5=86=99;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Change] Platform 为构造方法添加非空检查, 补充文档并添加 equals/hashCode 方法; --- .../net/lamgc/cgj/bot/framework/Platform.java | 38 +++++++++++++++++-- .../framework/message/AbstractBotCode.java | 4 +- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/Platform.java b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/Platform.java index 7a03733..4ad006e 100644 --- a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/Platform.java +++ b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/Platform.java @@ -17,18 +17,32 @@ package net.lamgc.cgj.bot.framework; +import java.util.Objects; + /** - * 框架平台DO. + * 框架所属平台. + *

用于标识一个平台, 每个平台有唯一的 {@link #platformIdentify PlatformIdentify}. + *

{@link #platformName PlatformName} 是允许不同的, + * 只要 {@link #platformIdentify PlatformIdentify} 唯一即可. + * + *

{@link #platformIdentify PlatformIdentify} + * 遵循 Camel-Case (骆峰命名法, 每个单词之间无空格, 单词首字母大写), + * 对于平台标识由少量字母组成的则全大写(例如腾讯QQ的平台标识则为 'QQ' 而不是 'qq' 或 'Qq'). * @author LamGC */ -public class Platform { +public final class Platform { private final String platformName; private final String platformIdentify; + /** + * 构造一个 Platform 对象. + * @param platformName 平台名 + * @param platformIdentify 平台唯一标识名. + */ public Platform(String platformName, String platformIdentify) { - this.platformName = platformName; - this.platformIdentify = platformIdentify; + this.platformName = Objects.requireNonNull(platformName, "PlatformName is null"); + this.platformIdentify = Objects.requireNonNull(platformIdentify, "PlatformIdentify is null"); } @Override @@ -56,4 +70,20 @@ public class Platform { return platformIdentify; } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Platform platform = (Platform) o; + return platformIdentify.equals(platform.platformIdentify); + } + + @Override + public int hashCode() { + return Objects.hash(platformIdentify); + } } diff --git a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/message/AbstractBotCode.java b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/message/AbstractBotCode.java index 37b7e39..0548f69 100644 --- a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/message/AbstractBotCode.java +++ b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/message/AbstractBotCode.java @@ -31,7 +31,9 @@ public abstract class AbstractBotCode implements BotCode { private String functionName; private final Map functionProperties = new Hashtable<>(); - public AbstractBotCode() {} + public AbstractBotCode(String functionName) { + this.functionName = functionName; + } /** * 将其他实现的 BotCode 转换成该实现的 BotCode.