mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-04-30 06:37:36 +00:00
[Add] Framework-API 补充一个字符序列 Message 实现;
[Add] CharSequenceMessage 添加一个单调的实现(用于装 String, StringBuilder 或 StringBuffer 之类的);
This commit is contained in:
parent
b2fc196830
commit
b21e6957a5
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.lamgc.cgj.bot.framework.message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字符序列消息对象.
|
||||||
|
* <p> 仅包含了一段字符串.
|
||||||
|
* @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 + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user