java.lang.Object
javax.swing.text.Segment
- 所有已实现的接口:
-
CharSequence,Cloneable,CharacterIterator
代表文本片段的字符数组段。即使可以直接访问数组,应将其视为不可变的。这样可以快速访问文本片段,而无需复制字符。实际上,这是一个未受保护的String。
Segment实现了java.text.CharacterIterator接口,以支持与i18n支持一起使用,而无需将文本复制到字符串中。
-
Field Summary
FieldsModifier and TypeFieldDescriptionchar[]包含感兴趣文本的数组。int构成感兴趣文本的数组元素数量。int所需文本开始的数组偏移量。Fields declared in interface java.text.CharacterIterator
DONE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncharcharAt(int index) 返回指定索引处的char值。clone()创建一个浅拷贝。charcurrent()获取当前位置的字符(由getIndex()返回)。charfirst()将位置设置为getBeginIndex()并返回该位置的字符。int返回文本的起始索引。int返回文本的结束索引。intgetIndex()返回当前索引。boolean指示部分返回是否有效的标志。charlast()将位置设置为getEndIndex()-1(如果文本为空,则为getEndIndex()),并返回该位置的字符。intlength()返回此字符序列的长度。charnext()将迭代器的索引增加一,并返回新索引处的字符。如果结果索引大于或等于getEndIndex(),则当前索引将重置为getEndIndex(),并返回DONE值。charprevious()将迭代器的索引减少一,并返回新索引处的字符。如果当前索引为getBeginIndex(),则索引保持在getBeginIndex(),并返回DONE值。charsetIndex(int position) 将位置设置为文本中的指定位置,并返回该字符。voidsetPartialReturn(boolean p) 指示部分返回是否有效的标志。subSequence(int start, int end) 返回此序列的子序列。toString()将片段转换为String。Methods declared in class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods declared in interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Field Details
-
array
public char[] array包含感兴趣文本的数组。此数组不应更改;仅供效率使用。 -
offset
public int offset所需文本开始的数组偏移量。 -
count
public int count构成感兴趣文本的数组元素数量。
-
-
Constructor Details
-
Segment
public Segment()创建一个新的片段。 -
Segment
public Segment(char[] array, int offset, int count) 创建一个引用现有数组的新片段。- 参数:
-
array- 要引用的数组 -
offset- 数组中的偏移量 -
count- 字符数
-
-
Method Details
-
setPartialReturn
public void setPartialReturn(boolean p) 指示部分返回是否有效的标志。如果标志为true,则接口方法Document.getText(position,length,Segment)的实现应尽可能返回文本,而无需进行复制。标志的默认状态为false,这将导致Document.getText(position,length,Segment)提供与以往相同的返回行为,具体取决于请求是否复制文本。- 参数:
-
p- 部分返回是否有效。 - 自:
- 1.4
-
isPartialReturn
public boolean isPartialReturn()指示部分返回是否有效的标志。- 返回:
- 部分返回是否有效。
- 自:
- 1.4
-
toString
将片段转换为String。- 指定者:
-
toString在接口CharSequence中 - 覆盖:
-
toString在类Object中 - 返回:
- 字符串
-
first
public char first()将位置设置为getBeginIndex()并返回该位置的字符。- 指定者:
-
first在接口CharacterIterator中 - 返回:
- 文本中的第一个字符,如果文本为空则返回DONE
- 自:
- 1.3
- 参见:
-
last
public char last()将位置设置为getEndIndex()-1(如果文本为空则为getEndIndex()),并返回该位置的字符。- 指定者:
-
last在接口CharacterIterator中 - 返回:
- 文本中的最后一个字符,如果文本为空则返回DONE
- 自:
- 1.3
- 参见:
-
current
public char current()获取当前位置的字符(由getIndex()返回)。- 指定者:
-
current在接口CharacterIterator中 - 返回:
- 当前位置的字符,如果当前位置超出文本末尾则返回DONE
- 自:
- 1.3
- 参见:
-
next
public char next()将迭代器的索引增加一,并返回新索引处的字符。如果结果索引大于或等于getEndIndex(),则当前索引将重置为getEndIndex(),并返回DONE值。- 指定者:
-
next在接口CharacterIterator中 - 返回:
- 新位置处的字符,如果新位置超出文本范围则返回DONE
- 自:
- 1.3
-
previous
public char previous()将迭代器的索引减少一,并返回新索引处的字符。如果当前索引为getBeginIndex(),则索引保持在getBeginIndex(),并返回DONE值。- 指定者:
-
previous在接口CharacterIterator中 - 返回:
- 新位置处的字符,如果当前位置等于getBeginIndex()则返回DONE
- 自:
- 1.3
-
setIndex
public char setIndex(int position) 将位置设置为文本中的指定位置,并返回该字符。- 指定者:
-
setIndex在接口CharacterIterator中 - 参数:
-
position- 文本中的位置。有效值范围从getBeginIndex()到getEndIndex()。如果提供了无效值,则会抛出IllegalArgumentException。 - 返回:
- 指定位置处的字符,如果指定位置等于getEndIndex()则返回DONE
- 自:
- 1.3
-
getBeginIndex
public int getBeginIndex()返回文本的起始索引。- 指定者:
-
getBeginIndex在接口CharacterIterator中 - 返回:
- 文本开始的索引。
- 自:
- 1.3
-
getEndIndex
public int getEndIndex()返回文本的结束索引。该索引是文本结束后第一个字符的索引。- 指定者:
-
getEndIndex在接口CharacterIterator中 - 返回:
- 文本中最后一个字符之后的索引
- 自:
- 1.3
-
getIndex
public int getIndex()返回当前索引。- 指定者:
-
getIndex在接口CharacterIterator中 - 返回:
- 当前索引。
- 自:
- 1.3
-
charAt
public char charAt(int index) 返回指定索引处的char值。索引范围从零到length() - 1。序列的第一个char值在索引零处,下一个在索引一处,依此类推,就像数组索引一样。如果索引指定的char值是一个代理,则返回代理值。
- 指定由:
-
charAt在接口CharSequence - 参数:
-
index- 要返回的char值的索引 - 返回:
-
指定的
char值 - 自版本:
- 1.6
-
length
public int length()返回此字符序列的长度。长度是序列中16位char的数量。- 指定由:
-
length在接口CharSequence - 返回:
-
此序列中
char的数量 - 自版本:
- 1.6
-
subSequence
返回此序列的子序列CharSequence。子序列从指定索引处的char值开始,并以索引end - 1处的char值结束。返回序列的长度(以char为单位)为end - start,因此如果start == end,则返回一个空序列。- 指定由:
-
subSequence在接口CharSequence - 参数:
-
start- 起始索引,包括 -
end- 结束索引,不包括 - 返回:
- 指定的子序列
- 自版本:
- 1.6
-
clone
创建一个浅拷贝。- 指定由:
-
clone在接口CharacterIterator - 覆盖:
-
clone在类Object - 返回:
- 复制品
- 参见:
-