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 + '\'' + + '}'; + } +}