javax.swing.text

Class Segment

public class Segment extends Object implements Cloneable, CharacterIterator

A text fragment represented by a sequence of characters stored in an array.
Field Summary
char[]array
Storage for the characters (may contain additional characters).
intcount
The number of characters in the segment.
intoffset
The offset of the first character in the segment.
Constructor Summary
Segment()
Creates a new Segment.
Segment(char[] array, int offset, int count)
Creates a new Segment.
Method Summary
Objectclone()
Clones the segment (note that the underlying character array is not cloned, just the reference to it).
charcurrent()
Returns the character at the current index.
charfirst()
Sets the current index to the first character in the segment and returns that character.
intgetBeginIndex()
Returns the index of the first character in the segment.
intgetEndIndex()
Returns the end index for the segment (one position beyond the last character in the segment - note that this can be outside the range of the underlying character array).
intgetIndex()
Returns the index of the current character in the segment.
booleanisPartialReturn()
Returns the partial return flag.
charlast()
Sets the current index to point to the last character in the segment and returns that character.
charnext()
Sets the current index to point to the next character in the segment and returns that character.
charprevious()
Sets the current index to point to the previous character in the segment and returns that character.
charsetIndex(int position)
Sets the current index and returns the character at that position (or {@link #DONE} if the index is equal to {@link #getEndIndex()}.
voidsetPartialReturn(boolean p)
Sets the partial return flag.
StringtoString()
Returns a String containing the same characters as this Segment.

Field Detail

array

public char[] array
Storage for the characters (may contain additional characters).

count

public int count
The number of characters in the segment.

offset

public int offset
The offset of the first character in the segment.

Constructor Detail

Segment

public Segment()
Creates a new Segment.

Segment

public Segment(char[] array, int offset, int count)
Creates a new Segment.

Parameters: array the underlying character data. offset the offset of the first character in the segment. count the number of characters in the segment.

Method Detail

clone

public Object clone()
Clones the segment (note that the underlying character array is not cloned, just the reference to it).

Returns: A clone of the segment.

current

public char current()
Returns the character at the current index. If the segment consists of zero characters, or the current index has passed the end of the characters in the segment, this method returns {@link #DONE}.

Returns: The character at the current index.

first

public char first()
Sets the current index to the first character in the segment and returns that character. If the segment contains zero characters, this method returns {@link #DONE}.

Returns: The first character in the segment, or {@link #DONE} if the segment contains zero characters.

getBeginIndex

public int getBeginIndex()
Returns the index of the first character in the segment.

Returns: The index of the first character.

getEndIndex

public int getEndIndex()
Returns the end index for the segment (one position beyond the last character in the segment - note that this can be outside the range of the underlying character array).

Returns: The end index for the segment.

getIndex

public int getIndex()
Returns the index of the current character in the segment.

Returns: The index of the current character.

isPartialReturn

public boolean isPartialReturn()
Returns the partial return flag.

Returns: The partial return flag.

Since: 1.4

last

public char last()
Sets the current index to point to the last character in the segment and returns that character. If the segment contains zero characters, the current index is set to {@link #getEndIndex()} and this method returns {@link #DONE}.

Returns: The last character in the segment, or {@link #DONE} if the segment contains zero characters.

next

public char next()
Sets the current index to point to the next character in the segment and returns that character. If the next character position is past the end of the segment, the index is set to {@link #getEndIndex()} and the method returns {@link #DONE}. If the segment contains zero characters, this method returns {@link #DONE}.

Returns: The next character in the segment or {@link #DONE} (if the next character position is past the end of the segment or if the segment contains zero characters).

previous

public char previous()
Sets the current index to point to the previous character in the segment and returns that character. If the current index is equal to {@link #getBeginIndex()}, or if the segment contains zero characters, this method returns {@link #DONE}.

Returns: The previous character in the segment or {@link #DONE} (if the current character position is at the beginning of the segment or if the segment contains zero characters).

setIndex

public char setIndex(int position)
Sets the current index and returns the character at that position (or {@link #DONE} if the index is equal to {@link #getEndIndex()}.

Parameters: position the current position.

Returns: The character at the specified position, or {@link #DONE} if position is equal to {@link #getEndIndex()}.

Throws: IllegalArgumentException if position is not in the range {@link #getBeginIndex()} to {@link #getEndIndex()}.

setPartialReturn

public void setPartialReturn(boolean p)
Sets the partial return flag.

Parameters: p the new value of the flag.

Since: 1.4

toString

public String toString()
Returns a String containing the same characters as this Segment.

Returns: A String containing the same characters as this Segment.