From 756df334424feaf2078586f611048b28013bf14d Mon Sep 17 00:00:00 2001 From: LamGC Date: Sun, 21 Feb 2021 20:40:16 +0800 Subject: [PATCH] =?UTF-8?q?[Change]=20Framework-API=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=20NoFoundSenderException=20=E7=B1=BB=E5=90=8D,=20=E5=B9=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=AF=E6=8F=90=E4=BE=9B=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E7=9A=84=E6=9E=84=E9=80=A0=E5=99=A8;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Change] NoFoundSenderException -> NotFoundSenderException 更改类名; [Change] NotFoundSenderException 添加可提供消息的构造器; [Change] SenderFactory 适配更改; --- ...ption.java => NotFoundSenderException.java} | 18 +++++++++++++++--- .../lamgc/cgj/bot/framework/SenderFactory.java | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) rename ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/{NoFoundSenderException.java => NotFoundSenderException.java} (72%) diff --git a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/NoFoundSenderException.java b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/NotFoundSenderException.java similarity index 72% rename from ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/NoFoundSenderException.java rename to ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/NotFoundSenderException.java index e05a262..6567ea7 100644 --- a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/NoFoundSenderException.java +++ b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/NotFoundSenderException.java @@ -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; *

当 {@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; } diff --git a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/SenderFactory.java b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/SenderFactory.java index 52445a8..f1c6564 100644 --- a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/SenderFactory.java +++ b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/SenderFactory.java @@ -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; }