mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-07-01 04:47:26 +00:00
[Change] Framework-API 在 Message 中添加 CharSequence 的三个抽象方法的默认实现;
[Change] Message 添加 CharSequence 中 'length()', 'charAt(int)' 和 'subSequence(int, int)' 的默认实现, 以降低测试复杂度; [Change] MessageChain, CharSequenceMessage, AbstractBotCode 适配 Message 更改;
This commit is contained in:
@ -116,19 +116,4 @@ public abstract class AbstractBotCode implements BotCode {
|
||||
return Collections.unmodifiableSet(functionProperties.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return contentToString().length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public char charAt(int index) {
|
||||
return contentToString().charAt(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence subSequence(int start, int end) {
|
||||
return contentToString().subSequence(start, end);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,21 +39,6 @@ public final class CharSequenceMessage implements Message {
|
||||
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{" +
|
||||
|
@ -29,4 +29,39 @@ public interface Message extends CharSequence {
|
||||
*/
|
||||
String contentToString();
|
||||
|
||||
/**
|
||||
* 返回该消息经过 {@link #contentToString()} 后的字符串长度.
|
||||
* @return 返回 {@link #contentToString()} 返回字符串的长度.
|
||||
* @see CharSequence#length()
|
||||
*/
|
||||
@Override
|
||||
default int length() {
|
||||
return contentToString().length();
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 {@link #contentToString()} 所返回的字符串中取出指定索引的字符.
|
||||
* @param index 字符索引.
|
||||
* @return 返回字符串指定索引对应的字符.
|
||||
* @throws IndexOutOfBoundsException 如果索引参数为负数或不小于此字符串的长度.
|
||||
* @see CharSequence#charAt(int)
|
||||
*/
|
||||
@Override
|
||||
default char charAt(int index) {
|
||||
return contentToString().charAt(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* 截取从 {@link #contentToString()} 中返回字符串内的一段字符序列.
|
||||
* @param start 截取起始索引.
|
||||
* @param end 截取终止索引.
|
||||
* @return 返回新的字符序列对象.
|
||||
* @throws IndexOutOfBoundsException 如果 beginIndex 或 endIndex 为负,
|
||||
* endIndex 大于 {@link #length()}, 或者 beginIndex 大于 endIndex 时抛出.
|
||||
* @see CharSequence#subSequence(int, int)
|
||||
*/
|
||||
@Override
|
||||
default CharSequence subSequence(int start, int end) {
|
||||
return contentToString().subSequence(start, end);
|
||||
}
|
||||
}
|
||||
|
@ -85,19 +85,4 @@ public final class MessageChain implements Message {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return contentToString().length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public char charAt(int index) {
|
||||
return contentToString().charAt(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence subSequence(int start, int end) {
|
||||
return contentToString().subSequence(start, end);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user