From b21e6957a518b1efabfac3cf2b99a62a072714e1 Mon Sep 17 00:00:00 2001 From: LamGC Date: Thu, 19 Nov 2020 22:17:58 +0800 Subject: [PATCH] =?UTF-8?q?[Add]=20Framework-API=20=E8=A1=A5=E5=85=85?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=AD=97=E7=AC=A6=E5=BA=8F=E5=88=97=20Messag?= =?UTF-8?q?e=20=E5=AE=9E=E7=8E=B0;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Add] CharSequenceMessage 添加一个单调的实现(用于装 String, StringBuilder 或 StringBuffer 之类的); --- .../message/CharSequenceMessage.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/message/CharSequenceMessage.java diff --git a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/message/CharSequenceMessage.java b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/message/CharSequenceMessage.java new file mode 100644 index 0000000..9114fd6 --- /dev/null +++ b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/message/CharSequenceMessage.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2020 LamGC + * + * ContentGrabbingJi is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * ContentGrabbingJi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package net.lamgc.cgj.bot.framework.message; + +/** + * 字符序列消息对象. + *

仅包含了一段字符串. + * @author LamGC + */ +public final class CharSequenceMessage implements Message { + + private final CharSequence content; + + public CharSequenceMessage(CharSequence content) { + if (content instanceof Message) { + this.content = ((Message) content).contentToString(); + } else { + this.content = content; + } + } + + @Override + public String contentToString() { + return content.toString(); + } + + @Override + public int length() { + return content.length(); + } + + @Override + public char charAt(int index) { + return content.charAt(index); + } + + @Override + public CharSequence subSequence(int start, int end) { + return content.subSequence(start, end); + } + + @Override + public String toString() { + return "CharSequenceMessage{" + + "content='" + content + '\'' + + '}'; + } +}