Class TextBuilder

java.lang.Object
org.aoju.bus.core.text.TextBuilder
All Implemented Interfaces:
Serializable, Appendable, CharSequence, Builder<String>

public class TextBuilder extends Object implements CharSequence, Appendable, Builder<String>
提供比StringBuffer更灵活和更强大的API
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Field Details

    • CAPACITY

      public static final int CAPACITY
      默认容量
      See Also:
    • buffer

      public char[] buffer
      存放的字符数组
    • indexes

      public int indexes
      当前指针位置
  • Constructor Details

    • TextBuilder

      public TextBuilder()
      构造
    • TextBuilder

      public TextBuilder(int initialCapacity)
      构造
      Parameters:
      initialCapacity - 初始容量
    • TextBuilder

      public TextBuilder(String text)
      构造
      Parameters:
      text - 初始字符串
    • TextBuilder

      public TextBuilder(CharSequence... texts)
      创建字符串构建器
      Parameters:
      texts - 初始字符串
  • Method Details

    • create

      public static TextBuilder create()
      创建字符串构建器
      Returns:
      TextBuilder
    • create

      public static TextBuilder create(int initialCapacity)
      创建字符串构建器
      Parameters:
      initialCapacity - 初始容量
      Returns:
      TextBuilder
    • create

      public static TextBuilder create(CharSequence... texts)
      创建字符串构建器
      Parameters:
      texts - 初始字符串
      Returns:
      TextBuilder
    • totalLength

      public static int totalLength(CharSequence... texts)
      给定字符串数组的总长度 null字符长度定义为0
      Parameters:
      texts - 字符串数组
      Returns:
      总长度
    • length

      public int length()
      Specified by:
      length in interface CharSequence
    • charAt

      public char charAt(int index)
      Specified by:
      charAt in interface CharSequence
    • getNewLineText

      public String getNewLineText()
    • setNewLineText

      public TextBuilder setNewLineText(String newLine)
    • getNullText

      public String getNullText()
    • setNullText

      public TextBuilder setNullText(String nullText)
    • setLength

      public TextBuilder setLength(int length)
      通过删除最后一个字符或添加Unicode 0的填充来更新生成器的长度
      Parameters:
      length - 要设置的长度必须为0或正
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - 如果长度是负的
    • capacity

      public int capacity()
    • ensureCapacity

      public TextBuilder ensureCapacity(int capacity)
      检查容量并确保它至少是指定的大小
      Parameters:
      capacity - 确保大小
      Returns:
      this
    • indexes

      public int indexes()
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface CharSequence
    • clear

      public TextBuilder clear()
    • reset

      public TextBuilder reset()
      删除全部字符,位置归零
      Returns:
      this
    • setCharAt

      public TextBuilder setCharAt(int index, char ch)
      在指定的索引处设置字符
      Parameters:
      index - 要设置的索引
      ch - 新字符
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - 如果索引无效
      See Also:
    • deleteCharAt

      public TextBuilder deleteCharAt(int index)
      删除指定索引处的字符
      Parameters:
      index - 要删除的索引
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - 如果索引无效
      See Also:
    • getChars

      public char[] getChars(char[] destination)
      将字符数组复制到指定的数组中.
      Parameters:
      destination - 目标数组,null将导致创建一个数组
      Returns:
      输入数组,除非它是null或太小
    • getChars

      public void getChars(int startIndex, int endIndex, char[] destination, int destinationIndex)
      将字符数组复制到指定的数组中
      Parameters:
      startIndex - 要复制的第一个索引(包括)必须有效
      endIndex - 最后一个索引(exclusive)必须有效
      destination - 目标数组不能为空或太小
      destinationIndex - 要在目的地开始复制的索引
      Throws:
      NullPointerException - 如果数组为空
      IndexOutOfBoundsException - 如果任何索引无效
    • readFrom

      public int readFrom(Readable readable) throws IOException
      如果可能,从提供的Readable直接将字符读入底层字符缓冲区,而不进行额外的复制
      Parameters:
      readable - 读取对象
      Returns:
      读取的字符数
      Throws:
      IOException - 如果发生I/O错误
    • appendNewLine

      public TextBuilder appendNewLine()
      将新行字符串附加到此字符串生成器
      Returns:
      this
    • appendNull

      public TextBuilder appendNull()
      将表示null的文本附加到此字符串生成器.
      Returns:
      this
    • append

      public TextBuilder append(Object object)
      将对象附加到此字符串生成器 附加null将调用appendNull().
      Parameters:
      object - 要追加的对象
      Returns:
      this
    • append

      public TextBuilder append(CharSequence seq)
      将对象附加到此字符串生成器 附加null将调用appendNull().
      Specified by:
      append in interface Appendable
      Parameters:
      seq - 要附加的字符序列
      Returns:
      this
    • append

      public TextBuilder append(CharSequence seq, int startIndex, int length)
      将对象附加到此字符串生成器 附加null将调用appendNull().
      Specified by:
      append in interface Appendable
      Parameters:
      seq - 要附加的字符序列
      startIndex - 起始索引(包括起始索引)必须有效
      length - 要追加的长度必须有效
      Returns:
      this
    • append

      public TextBuilder append(String text)
      将对象附加到此字符串生成器 附加null将调用appendNull().
      Parameters:
      text - 要追加的字符串
      Returns:
      this
    • append

      public TextBuilder append(String text, int startIndex, int length)
      将对象附加到此字符串生成器 附加null将调用appendNull().
      Parameters:
      text - 要追加的字符串
      startIndex - 起始索引(包括起始索引)必须有效
      length - 要追加的长度必须有效
      Returns:
      this
    • append

      public TextBuilder append(String format, Object... objs)
      调用 String.format(String, Object...)并附加结果
      Parameters:
      format - 格式字符串
      objs - 要在格式字符串中使用的对象
      Returns:
      this
      See Also:
    • append

      public TextBuilder append(CharBuffer buf)
      将char缓冲区的内容附加到此字符串生成器 附加null将调用appendNull().
      Parameters:
      buf - 要附加的字符缓冲区
      Returns:
      this
    • append

      public TextBuilder append(CharBuffer buf, int startIndex, int length)
      将char缓冲区的内容附加到此字符串生成器 附加null将调用appendNull().
      Parameters:
      buf - 要附加的字符缓冲区
      startIndex - 起始索引(包括起始索引)必须有效
      length - 要追加的长度必须有效
      Returns:
      this
    • append

      public TextBuilder append(StringBuffer text)
      将对象附加到此字符串生成器 附加null将调用appendNull().
      Parameters:
      text - 要追加的字符串
      Returns:
      this
    • append

      public TextBuilder append(StringBuffer text, int startIndex, int length)
      将对象附加到此字符串生成器 附加null将调用appendNull().
      Parameters:
      text - 要追加的字符串
      startIndex - 起始索引(包括起始索引)必须有效
      length - 要追加的长度必须有效
      Returns:
      this
    • append

      public TextBuilder append(StringBuilder text)
      将对象附加到此字符串生成器 附加null将调用appendNull().
      Parameters:
      text - 要追加的字符串
      Returns:
      this
    • append

      public TextBuilder append(StringBuilder text, int startIndex, int length)
      将StringBuilder的一部分附加到此字符串生成器 附加null将调用appendNull()
      Parameters:
      text - 要追加的字符串
      startIndex - 起始索引(包括起始索引)必须有效
      length - 要追加的长度必须有效
      Returns:
      this
    • append

      public TextBuilder append(TextBuilder text)
      将String的一部分附加到此字符串生成器 附加null将调用appendNull()
      Parameters:
      text - 要追加的字符串
      Returns:
      this
    • append

      public TextBuilder append(TextBuilder text, int startIndex, int length)
      将字符串生成器的一部分附加到此字符串生成器 附加null将调用appendNull().
      Parameters:
      text - 要追加的字符串
      startIndex - 起始索引(包括起始索引)必须有效
      length - 要追加的长度必须有效
      Returns:
      this
    • append

      public TextBuilder append(char[] chars)
      向字符串生成器追加一个char数组 附加null将调用appendNull().
      Parameters:
      chars - 要附加的字符数组
      Returns:
      this
    • append

      public TextBuilder append(char[] chars, int startIndex, int length)
      向字符串生成器追加一个char数组 附加null将调用appendNull()
      Parameters:
      chars - 要附加的字符数组
      startIndex - 起始索引(包括起始索引)必须有效
      length - 要追加的长度必须有效
      Returns:
      this
    • append

      public TextBuilder append(boolean value)
      将布尔值附加到字符串生成器.
      Parameters:
      value - 要附加的值
      Returns:
      this
    • append

      public TextBuilder append(char ch)
      将char值附加到字符串生成器.
      Specified by:
      append in interface Appendable
      Parameters:
      ch - 要附加的值
      Returns:
      this
    • append

      public TextBuilder append(int value)
      使用String.valueOf向字符串生成器追加一个int值
      Parameters:
      value - 要附加的值
      Returns:
      this
    • append

      public TextBuilder append(long value)
      使用String.valueOf向字符串生成器追加一个long值
      Parameters:
      value - 要附加的值
      Returns:
      this
    • append

      public TextBuilder append(float value)
      使用String.valueOf向字符串生成器追加一个float值
      Parameters:
      value - 要附加的值
      Returns:
      this
    • append

      public TextBuilder append(double value)
      使用String.valueOf向字符串生成器追加一个double值
      Parameters:
      value - 要附加的值
      Returns:
      this
    • appendln

      public TextBuilder appendln(Object object)
      将对象后接新行追加到此字符串生成器 附加null将调用appendNull()
      Parameters:
      object - 要附加的值
      Returns:
      this
    • appendln

      public TextBuilder appendln(String text)
      将对象后接新行追加到此字符串生成器 附加null将调用appendNull()
      Parameters:
      text - 要附加的值
      Returns:
      this
    • appendln

      public TextBuilder appendln(String text, int startIndex, int length)
      将对象后接新行追加到此字符串生成器 附加null将调用appendNull()
      Parameters:
      text - 要附加的值
      startIndex - 起始索引(包括起始索引)必须有效
      length - 要追加的长度必须有效
      Returns:
      this
    • appendln

      public TextBuilder appendln(String format, Object... objs)
      Parameters:
      format - 格式字符串
      objs - 要在格式字符串中使用的对象
      Returns:
      this
      See Also:
    • appendln

      public TextBuilder appendln(StringBuffer text)
      向此字符串生成器追加一个字符串缓冲区,后跟新行 附加null将调用appendNull()
      Parameters:
      text - 要追加的字符串缓冲区
      Returns:
      this
    • appendln

      public TextBuilder appendln(StringBuilder text)
      向此字符串生成器追加一个字符串缓冲区,后跟新行 * 附加null将调用appendNull()
      Parameters:
      text - t他附加字符串生成器
      Returns:
      this
    • appendln

      public TextBuilder appendln(StringBuilder text, int startIndex, int length)
      向此字符串生成器追加一个字符串缓冲区,后跟新行 附加null将调用appendNull()
      Parameters:
      text - 要追加的字符串缓冲区
      startIndex - 起始索引(包括起始索引)必须有效
      length - 要追加的长度必须有效
      Returns:
      this
    • appendln

      public TextBuilder appendln(StringBuffer text, int startIndex, int length)
      向此字符串生成器追加一个字符串缓冲区,后跟新行 附加null将调用appendNull()
      Parameters:
      text - 要追加的字符串缓冲区
      startIndex - 起始索引(包括起始索引)必须有效
      length - 要追加的长度必须有效
      Returns:
      this
    • appendln

      public TextBuilder appendln(TextBuilder text)
      向此字符串生成器追加一个字符串缓冲区,后跟新行 附加null将调用appendNull()
      Parameters:
      text - 要追加的字符串缓冲区
      Returns:
      this
    • appendln

      public TextBuilder appendln(TextBuilder text, int startIndex, int length)
      向此字符串生成器追加一个字符串缓冲区,后跟新行 附加null将调用appendNull()
      Parameters:
      text - 要追加的字符串缓冲区
      startIndex - 起始索引(包括起始索引)必须有效
      length - 要追加的长度必须有效
      Returns:
      this
    • appendln

      public TextBuilder appendln(char[] chars)
      向此字符串生成器追加一个字符串缓冲区,后跟新行 附加null将调用appendNull()
      Parameters:
      chars - 要附加的字符数组
      Returns:
      this
    • appendln

      public TextBuilder appendln(char[] chars, int startIndex, int length)
      向字符串生成器追加一个字符数组,后跟一个新行 附加null将调用appendNull()
      Parameters:
      chars - 要追加的字符串缓冲区
      startIndex - 起始索引(包括起始索引)必须有效
      length - 要追加的长度必须有效
      Returns:
      this
    • appendln

      public TextBuilder appendln(boolean value)
      将布尔值后跟新行追加到字符串生成器.
      Parameters:
      value - 要附加的值
      Returns:
      this
    • appendln

      public TextBuilder appendln(char ch)
      向字符串生成器追加一个字符值,后跟一个新行.
      Parameters:
      ch - 要附加的值
      Returns:
      this
    • appendln

      public TextBuilder appendln(int value)
      使用String.valueOf向字符串生成器追加一个int值,后面跟一个新行
      Parameters:
      value - 要附加的值
      Returns:
      this
    • appendln

      public TextBuilder appendln(long value)
      使用String.valueOf向字符串生成器追加一个long值,后面跟一个新行
      Parameters:
      value - 要附加的值
      Returns:
      this
    • appendln

      public TextBuilder appendln(float value)
      使用String.valueOf向字符串生成器追加一个float值,后面跟一个新行
      Parameters:
      value - 要附加的值
      Returns:
      this
    • appendln

      public TextBuilder appendln(double value)
      使用String.valueOf向字符串生成器追加一个double值,后面跟一个新行
      Parameters:
      value - 要附加的值
      Returns:
      this
    • appendAll

      public <T> TextBuilder appendAll(T... array)
      不使用任何分隔符将数组中的每个项添加到生成器 附加一个空数组将没有效果 每个对象都使用append(Object)进行追加
      Type Parameters:
      T - 元素类型
      Parameters:
      array - 要追加的数组
      Returns:
      this
    • appendAll

      public TextBuilder appendAll(Iterable<?> iterable)
      在不使用任何分隔符的情况下将迭代中的每个项附加到生成器 附加一个null iterable将没有效果 每个对象都使用append(Object)进行追加
      Parameters:
      iterable - 可追加的迭代
      Returns:
      this
    • appendAll

      public TextBuilder appendAll(Iterator<?> it)
      在不使用任何分隔符的情况下将迭代器中的每个项附加到生成器 附加一个空迭代器将没有效果 每个对象都使用append(Object)进行追加.
      Parameters:
      it - 要追加的迭代器
      Returns:
      this
    • appendWithSeparators

      public TextBuilder appendWithSeparators(Object[] array, String separator)
      在每个值之间追加放置分隔符的数组,但不在第一个值之前或最后一个值之后追加 附加一个空数组将没有效果 每个对象都使用append(Object)进行追加
      Parameters:
      array - 要追加的数组
      separator - 要使用的分隔符,null表示没有分隔符
      Returns:
      this
    • appendWithSeparators

      public TextBuilder appendWithSeparators(Iterable<?> iterable, String separator)
      在每个值之间追加一个可迭代的放置分隔符,但不是在第一个值之前或最后一个值之后 附加一个null iterable将没有效果 每个对象都使用append(Object)进行追加.
      Parameters:
      iterable - 可追加的迭代
      separator - 要使用的分隔符,null表示没有分隔符
      Returns:
      this
    • appendWithSeparators

      public TextBuilder appendWithSeparators(Iterator<?> it, String separator)
      在每个值之间添加分隔符,但不在第一个值之前或最后一个值之后添加迭代器 附加一个空迭代器将没有效果 每个对象都使用append(Object)进行追加.
      Parameters:
      it - 要追加的迭代器
      separator - 要使用的分隔符,null表示没有分隔符
      Returns:
      this
    • appendFixedWidthPadLeft

      public TextBuilder appendFixedWidthPadLeft(Object object, int width, char padChar)
      将一个对象附加到左侧的生成器内边距上,使其具有固定的宽度。 使用对象的toString 如果对象的长度大于长度,则左手边就会丢失 如果对象为空,则使用空文本值
      Parameters:
      object - 要追加的对象null使用空文本
      width - 固定的字段宽度,零或负没有影响
      padChar - 要使用的填充字符
      Returns:
      this
    • appendFixedWidthPadLeft

      public TextBuilder appendFixedWidthPadLeft(int value, int width, char padChar)
      将一个对象附加到左侧的生成器内边距上,使其具有固定的宽度 使用String.valueOf字符串,使用int 如果格式化的值大于长度,则左侧边将丢失
      Parameters:
      value - 要附加的值
      width - 固定的字段宽度,零或负没有影响
      padChar - 要使用的填充字符
      Returns:
      this
    • appendFixedWidthPadRight

      public TextBuilder appendFixedWidthPadRight(Object object, int width, char padChar)
      将对象附加到右侧的生成器内边距,使其具有固定的长度 使用对象的toString 如果物体比长度大,右边的部分就会丢失 如果对象为空,则使用空文本值
      Parameters:
      object - 要追加的对象null使用空文本
      width - 固定的字段宽度,零或负没有影响
      padChar - 要使用的填充字符
      Returns:
      this
    • appendFixedWidthPadRight

      public TextBuilder appendFixedWidthPadRight(int value, int width, char padChar)
      将对象附加到右侧的生成器内边距,使其具有固定的长度 使用String.valueOf字符串,使用int 如果格式化的值大于长度,则右侧将丢失
      Parameters:
      value - 要附加的值
      width - 固定的字段宽度,零或负没有影响
      padChar - 要使用的填充字符
      Returns:
      this
    • insert

      public TextBuilder insert(int index, Object object)
      将对象的字符串表示形式插入到此生成器中 插入null将使用存储的空文本值
      Parameters:
      index - 要添加的索引必须有效
      object - 要插入的对象
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - 如果索引无效
    • insert

      public TextBuilder insert(int index, String text)
      将字符串插入到此生成器中. 插入null将使用存储的空文本值.
      Parameters:
      index - 要添加的索引必须有效
      text - 要插入的字符串
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - 如果索引无效
    • insert

      public TextBuilder insert(int index, char[] chars)
      将字符数组插入到此生成器中. 插入null将使用存储的空文本值.
      Parameters:
      index - 要添加的索引必须有效
      chars - 要插入的char数组
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - 如果索引无效
    • insert

      public TextBuilder insert(int index, char[] chars, int offset, int length)
      将字符数组的一部分插入到此生成器中. 插入null将使用存储的空文本值.
      Parameters:
      index - 要添加的索引必须有效
      chars - 要插入的char数组
      offset - 字符数组中要开始的偏移量必须有效
      length - 要复制的字符数组部分的长度必须为正
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - 如果任何索引无效
    • insert

      public TextBuilder insert(int index, boolean value)
      将值插入此生成器.
      Parameters:
      index - 要添加的索引必须有效
      value - 要插入的值
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - 如果索引无效
    • insert

      public TextBuilder insert(int index, char value)
      将值插入此生成器.
      Parameters:
      index - 要添加的索引必须有效
      value - 要插入的值
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - 如果索引无效
    • insert

      public TextBuilder insert(int index, int value)
      将值插入此生成器.
      Parameters:
      index - 要添加的索引必须有效
      value - 要插入的值
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - 如果索引无效
    • insert

      public TextBuilder insert(int index, long value)
      将值插入此生成器.
      Parameters:
      index - 要添加的索引必须有效
      value - 要插入的值
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - 如果索引无效
    • insert

      public TextBuilder insert(int index, float value)
      将值插入此生成器.
      Parameters:
      index - 要添加的索引必须有效
      value - 要插入的值
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - 如果索引无效
    • insert

      public TextBuilder insert(int index, double value)
      将值插入此生成器.
      Parameters:
      index - 要添加的索引必须有效
      value - 要插入的值
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - 如果索引无效
    • delete

      public TextBuilder delete(int startIndex, int endIndex)
      删除两个指定索引之间的字符
      Parameters:
      startIndex - 起始索引(包括起始索引)必须有效
      endIndex - 唯一的结束索引必须有效,除非太大,否则将被视为字符串的结束
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - 如果索引无效
    • deleteAll

      public TextBuilder deleteAll(char ch)
      删除在生成器中出现的字符.
      Parameters:
      ch - 要删除的字符
      Returns:
      this
    • deleteFirst

      public TextBuilder deleteFirst(char ch)
      删除在生成器中出现的字符
      Parameters:
      ch - 要删除的字符
      Returns:
      this
    • deleteAll

      public TextBuilder deleteAll(String text)
      删除生成器中出现的字符串
      Parameters:
      text - 若要删除的字符串为空,则不执行任何操作
      Returns:
      this
    • deleteFirst

      public TextBuilder deleteFirst(String text)
      删除生成器中出现的字符串
      Parameters:
      text - 若要删除的字符串为空,则不执行任何操作
      Returns:
      this
    • deleteAll

      public TextBuilder deleteAll(Matchers matcher)
      删除匹配程序匹配的生成器的所有部分. 匹配器可用于执行高级删除行为。例如, 您可以编写一个匹配器来删除字符“a”后面跟一个数字的所有匹配项
      Parameters:
      matcher - 要使用的matcher来查找删除,null不导致任何操作
      Returns:
      this
    • deleteFirst

      public TextBuilder deleteFirst(Matchers matcher)
      使用指定的匹配器删除生成器中的第一个匹配项.

      匹配器可用于执行高级删除行为。例如,您可以编写一个匹配器来删除字符“a”后面跟着一个数字的地方.

      Parameters:
      matcher - 要使用的matcher来查找删除,null不导致任何操作
      Returns:
      this
    • replace

      public TextBuilder replace(int startIndex, int endIndex, String replaceStr)
      将字符串生成器的一部分替换为另一个字符串 插入字符串的长度不必与删除的长度匹配
      Parameters:
      startIndex - 开始索引,必须是有效的
      endIndex - 唯一的结束索引必须有效,除非太大,否则将被视为字符串的结束
      replaceStr - 要替换的字符串null表示删除范围
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - 如果索引无效
    • replaceAll

      public TextBuilder replaceAll(char search, char replace)
      在整个生成器中使用替换字符替换搜索字符
      Parameters:
      search - 搜索字符
      replace - 替换字符
      Returns:
      this
    • replaceFirst

      public TextBuilder replaceFirst(char search, char replace)
      用生成器中的替换字符替换搜索字符的第一个实例.
      Parameters:
      search - 搜索字符
      replace - 替换字符
      Returns:
      this
    • replaceAll

      public TextBuilder replaceAll(String searchStr, String replaceStr)
      在整个生成器中使用替换字符串替换搜索字符串
      Parameters:
      searchStr - 如果搜索字符串为空,则不执行任何操作
      replaceStr - 替换字符串null相当于空字符串
      Returns:
      this
    • replaceFirst

      public TextBuilder replaceFirst(String searchStr, String replaceStr)
      用替换字符串替换搜索字符串的第一个实例
      Parameters:
      searchStr - 如果搜索字符串为空,则不执行任何操作
      replaceStr - 替换字符串null相当于空字符串
      Returns:
      this
    • replaceAll

      public TextBuilder replaceAll(Matchers matcher, String replaceStr)
      用替换字符串替换生成器中的所有匹配项
      Parameters:
      matcher - 要使用的matcher来查找删除,null不导致任何操作
      replaceStr - 替换字符串null相当于空字符串
      Returns:
      this
    • replaceFirst

      public TextBuilder replaceFirst(Matchers matcher, String replaceStr)
      用替换字符串替换生成器中的所有匹配项
      Parameters:
      matcher - 要使用的matcher来查找删除,null不导致任何操作
      replaceStr - 替换字符串null相当于空字符串
      Returns:
      this
    • replace

      public TextBuilder replace(Matchers matcher, String replaceStr, int startIndex, int endIndex, int replaceCount)
      高级搜索并在构建器中使用匹配器进行替换
      Parameters:
      matcher - 要使用的matcher来查找删除,null不导致任何操作
      replaceStr - 将匹配项替换为null的字符串是delete
      startIndex - 起始索引(包括起始索引)必须有效
      endIndex - 唯一的结束索引必须有效,除非太大,否则将被视为字符串的结束
      replaceCount - 要替换的次数,-1表示替换所有
      Returns:
      this
      Throws:
      IndexOutOfBoundsException - 如果开始索引无效
    • reverse

      public TextBuilder reverse()
      反转将每个字符放在相反索引中的字符串生成器
      Returns:
      this
    • trim

      public TextBuilder trim()
      通过从开头和结尾删除小于或等于空格的字符来修剪生成器
      Returns:
      this
    • startsWith

      public boolean startsWith(String text)
      检查此生成器是否以指定的字符串开始
      Parameters:
      text - 要搜索的字符串null返回false
      Returns:
      如果生成器从字符串开始,则为真
    • endsWith

      public boolean endsWith(String text)
      检查此生成器是否以指定的字符串结束
      Parameters:
      text - 要搜索的字符串null返回false
      Returns:
      如果生成器以字符串结束,则为真
    • subSequence

      public CharSequence subSequence(int start, int end)
      Specified by:
      subSequence in interface CharSequence
    • subString

      public String subString(int start)
      返回自定段的字符串
      Parameters:
      start - 开始位置(包括)
      Returns:
      this
    • subString

      public String subString(int start, int end)
      返回自定段的字符串
      Parameters:
      start - 开始位置(包括)
      end - 结束位置(不包括)
      Returns:
      this
    • leftString

      public String leftString(int length)
      从字符串生成器中提取最左边的字符而不引发异常.
      Parameters:
      length - 要提取的字符数,负返回空字符串
      Returns:
      新的字符串
    • rightString

      public String rightString(int length)
      从字符串生成器中提取最右边的字符而不引发异常.
      Parameters:
      length - 要提取的字符数,负返回空字符串
      Returns:
      新的字符串
    • midString

      public String midString(int index, int length)
      从字符串生成器中间提取一些字符而不引发异常
      Parameters:
      index - 下标从-开始,表示0
      length - 要提取的字符数,负返回空字符串
      Returns:
      新的字符串
    • contains

      public boolean contains(char ch)
      检查字符串生成器是否包含指定的字符
      Parameters:
      ch - 要找的字符
      Returns:
      如果生成器包含该字符,则为真
    • contains

      public boolean contains(String text)
      检查字符串生成器是否包含指定的字符串
      Parameters:
      text - 要找的字符
      Returns:
      如果生成器包含该字符,则为真
    • contains

      public boolean contains(Matchers matcher)
      检查字符串生成器是否包含使用指定匹配器匹配的字符串
      Parameters:
      matcher - 要使用的匹配器,如果为null返回-1
      Returns:
      如果匹配器在生成器中找到匹配项,则为真
    • indexOf

      public int indexOf(char ch)
      搜索字符串生成器以查找指定char类型的第一个引用.
      Parameters:
      ch - 要找的字符
      Returns:
      字符的第一个索引,如果没有找到则为-1
    • indexOf

      public int indexOf(char ch, int startIndex)
      搜索字符串生成器以查找指定char类型的第一个引用.
      Parameters:
      ch - 要找的字符
      startIndex - 从索引开始,无效的索引四舍五入到边缘
      Returns:
      字符的第一个索引,如果没有找到则为-1
    • indexOf

      public int indexOf(String text)
      搜索字符串生成器以查找指定字符串的第一个引用
      Parameters:
      text - 要查找的字符串,如果为null返回-1
      Returns:
      字符的第一个索引,如果没有找到则为-1
    • indexOf

      public int indexOf(String text, int startIndex)
      从给定索引开始搜索,搜索字符串生成器以查找指定字符串的第一个引用
      Parameters:
      text - 要查找的字符串,如果为null返回-1
      startIndex - 从索引开始,无效的索引四舍五入到边缘
      Returns:
      字符的第一个索引,如果没有找到则为-1
    • indexOf

      public int indexOf(Matchers matcher)
      使用matcher搜索字符串生成器以查找第一个匹配项.
      Parameters:
      matcher - 要使用的匹配器,null返回-1
      Returns:
      第一个索引匹配,如果没有找到,则为-1
    • indexOf

      public int indexOf(Matchers matcher, int startIndex)
      使用matcher搜索字符串生成器,以查找从给定索引中搜索的第一个匹配项.
      Parameters:
      matcher - 要使用的匹配器,null返回-1
      startIndex - 从索引开始,无效的索引四舍五入到边缘
      Returns:
      第一个索引匹配,如果没有找到,则为-1
    • lastIndexOf

      public int lastIndexOf(char ch)
      搜索字符串生成器以查找对指定字符的最后一个引用.
      Parameters:
      ch - 要找的字符
      Returns:
      字符的最后一个索引,如果没有找到,则为-1
    • lastIndexOf

      public int lastIndexOf(char ch, int startIndex)
      搜索字符串生成器以查找对指定字符的最后一个引用.
      Parameters:
      ch - 要找的字符
      startIndex - 从索引开始,无效的索引四舍五入到边缘
      Returns:
      字符的最后一个索引,如果没有找到,则为-1
    • lastIndexOf

      public int lastIndexOf(String text)
      搜索字符串生成器以查找对指定字符串的最后引用
      Parameters:
      text - 要查找的字符串,null返回-1
      Returns:
      字符串的最后一个索引,如果没有找到,则为-1
    • lastIndexOf

      public int lastIndexOf(String text, int startIndex)
      从给定索引开始搜索,搜索字符串生成器以查找指定字符串的最后一个引用
      Parameters:
      text - 要查找的字符串,null返回-1
      startIndex - 从索引开始,无效的索引四舍五入到边缘
      Returns:
      字符串的最后一个索引,如果没有找到,则为-1
    • lastIndexOf

      public int lastIndexOf(Matchers matcher)
      使用matcher搜索字符串生成器以查找最后一个匹配项
      Parameters:
      matcher - 要使用的匹配器,null返回-1
      Returns:
      最后一个索引匹配,如果没有找到,则为-1
    • lastIndexOf

      public int lastIndexOf(Matchers matcher, int startIndex)
      使用matcher搜索字符串生成器,以查找从给定索引中搜索的最后一个匹配项
      Parameters:
      matcher - 要使用的匹配器,null返回-1
      startIndex - 从索引开始,无效的索引四舍五入到边缘
      Returns:
      最后一个索引匹配,如果没有找到,则为-1
    • equalsIgnoreCase

      public boolean equalsIgnoreCase(TextBuilder other)
      检查此生成器的内容与另一个生成器的内容是否包含相同的字符内容(忽略大小写)
      Parameters:
      other - 要检查的对象null返回false
      Returns:
      如果生成器以相同的顺序包含相同的字符,则为真
    • equals

      public boolean equals(TextBuilder other)
      检查此生成器的内容与另一个生成器的内容是否包含相同的字符内容.
      Parameters:
      other - 要检查的对象null返回false
      Returns:
      如果生成器以相同的顺序包含相同的字符,则为真
    • build

      public String build()
      实现Builder接口
      Specified by:
      build in interface Builder<String>
      Returns:
      构建器一个 String
      See Also:
    • equals

      public boolean equals(Object object)
      检查此生成器的内容与另一个生成器的内容是否包含相同的字符内容.
      Overrides:
      equals in class Object
      Parameters:
      object - 要检查的对象null返回false
      Returns:
      如果生成器以相同的顺序包含相同的字符,则为真
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class Object
    • toString

      public String toString(boolean isReset)
      生成字符串
      Parameters:
      isReset - 是否重置,重置后相当于空的构建器
      Returns:
      生成的字符串
    • toStringBuffer

      public StringBuffer toStringBuffer()
      获取字符串生成器的StringBuffer版本,在每次调用该方法时创建一个新实例
      Returns:
      构建器一个 StringBuffer
    • toStringBuilder

      public StringBuilder toStringBuilder()
      获取字符串生成器的StringBuilder版本,在每次调用该方法时创建一个新实例
      Returns:
      构建器一个 StringBuilder
    • validateRange

      protected int validateRange(int startIndex, int endIndex)
      验证定义生成器范围的参数
      Parameters:
      startIndex - 起始索引(包括起始索引)必须有效
      endIndex - 唯一的结束索引必须有效,除非太大,否则将被视为字符串的结束
      Returns:
      新的字符串
      Throws:
      IndexOutOfBoundsException - 如果索引无效
    • validateIndex

      protected void validateIndex(int index)
      验证在生成器中定义单个索引的参数
      Parameters:
      index - 索引,必须是有效的
      Throws:
      IndexOutOfBoundsException - 如果索引无效