[Change] Framework-API 调整 NoFoundSenderException 类名, 并添加可提供消息的构造器;

[Change] NoFoundSenderException -> NotFoundSenderException 更改类名;
[Change] NotFoundSenderException 添加可提供消息的构造器;
[Change] SenderFactory 适配更改;
This commit is contained in:
LamGC 2021-02-21 20:40:16 +08:00
parent f945b52fa4
commit 756df33442
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D
2 changed files with 17 additions and 5 deletions

View File

@ -17,6 +17,7 @@
package net.lamgc.cgj.bot.framework;
import com.google.common.base.Strings;
import net.lamgc.cgj.bot.framework.message.MessageSource;
/**
@ -24,7 +25,7 @@ import net.lamgc.cgj.bot.framework.message.MessageSource;
* <p> {@link SenderFactory} 无法通过传入的 {@link MessageSource} Id 找到对应消息源时, 将抛出本异常.
* @see SenderFactory
*/
public class NoFoundSenderException extends RuntimeException {
public class NotFoundSenderException extends RuntimeException {
private final MessageSource source;
private final long id;
@ -34,8 +35,19 @@ public class NoFoundSenderException extends RuntimeException {
* @param source 传入的消息源类型.
* @param id 传入的消息源 Id.
*/
public NoFoundSenderException(MessageSource source, long id) {
super("Source Type: " + source + ", id: " + id);
public NotFoundSenderException(MessageSource source, long id) {
this(source, id, null);
}
/**
* 构造异常.
* @param source 传入的消息源类型.
* @param id 传入的消息源 Id.
*/
public NotFoundSenderException(MessageSource source, long id, String message) {
super(Strings.isNullOrEmpty(message) ?
"Source Type: " + source + ", id: " + id :
message + " (" + "Source Type: " + source + ", id: " + id + ")");
this.source = source;
this.id = id;
}

View File

@ -39,8 +39,8 @@ public interface SenderFactory extends ExtensionPoint {
* @param source 消息源类型.
* @param id 消息源 Id.
* @return 返回消息发送器, 本方法不允许返回 null.
* @throws NoFoundSenderException 当无法获取对应的消息源发送器时, 将抛出该异常.
* @throws NotFoundSenderException 当无法获取对应的消息源发送器时, 将抛出该异常.
*/
MessageSender getSender(MessageSource source, long id) throws NoFoundSenderException;
MessageSender getSender(MessageSource source, long id) throws NotFoundSenderException;
}