[Change] Framework-API 补充 Platform 的文档, 并添加 equals 和 hashCode 方法覆写;

[Change] Platform 为构造方法添加非空检查, 补充文档并添加 equals/hashCode 方法;
This commit is contained in:
LamGC 2020-11-19 22:09:33 +08:00
parent 76371b3257
commit 1853461f09
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D
2 changed files with 37 additions and 5 deletions

View File

@ -17,18 +17,32 @@
package net.lamgc.cgj.bot.framework; package net.lamgc.cgj.bot.framework;
import java.util.Objects;
/** /**
* 框架平台DO. * 框架所属平台.
* <p> 用于标识一个平台, 每个平台有唯一的 {@link #platformIdentify PlatformIdentify}.
* <p> {@link #platformName PlatformName} 是允许不同的,
* 只要 {@link #platformIdentify PlatformIdentify} 唯一即可.
*
* <p> {@link #platformIdentify PlatformIdentify}
* 遵循 Camel-Case (骆峰命名法, 每个单词之间无空格, 单词首字母大写),
* 对于平台标识由少量字母组成的则全大写(例如腾讯QQ的平台标识则为 'QQ' 而不是 'qq' 'Qq').
* @author LamGC * @author LamGC
*/ */
public class Platform { public final class Platform {
private final String platformName; private final String platformName;
private final String platformIdentify; private final String platformIdentify;
/**
* 构造一个 Platform 对象.
* @param platformName 平台名
* @param platformIdentify 平台唯一标识名.
*/
public Platform(String platformName, String platformIdentify) { public Platform(String platformName, String platformIdentify) {
this.platformName = platformName; this.platformName = Objects.requireNonNull(platformName, "PlatformName is null");
this.platformIdentify = platformIdentify; this.platformIdentify = Objects.requireNonNull(platformIdentify, "PlatformIdentify is null");
} }
@Override @Override
@ -56,4 +70,20 @@ public class Platform {
return platformIdentify; 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);
}
} }

View File

@ -31,7 +31,9 @@ public abstract class AbstractBotCode implements BotCode {
private String functionName; private String functionName;
private final Map<String, String> functionProperties = new Hashtable<>(); private final Map<String, String> functionProperties = new Hashtable<>();
public AbstractBotCode() {} public AbstractBotCode(String functionName) {
this.functionName = functionName;
}
/** /**
* 将其他实现的 BotCode 转换成该实现的 BotCode. * 将其他实现的 BotCode 转换成该实现的 BotCode.