java.text
public
abstract
class
java.text.BreakIterator
This class is used to locate the boundaries of text. Instance of this class
can be got by some factory methods:
-
getCharacterInstance() returns a BreakIterator that iterate the
logical characters without worrying about how the character is stored. For
example, some character may be stored in more than one Unicode code point
according to Unicode specification, this character can handle the logical
characters with multi code points.
-
getWordInstance() returns a BreakIterator
that
iterate the word-breaks. The beginning and end of each word(including numbers)
is treated as boundary position. Whitespace and punctuation are kept separate
from real words.
-
getSentenceInstance()
returns a BreakIterator that iterate the
sentence-breaks.
getLineInstance()
returns a BreakIterator that iterate the
line-breaks which can be used to wrap lines. This iterator can handle whitespaces,
hyphens and punctuations.
BreakIterator
uses
CharacterIterator
to perform the
analysis, so that any storage which provides
CharacterIterator
interface.
Summary
Constants
|
|
|
Value |
|
int |
DONE |
This constant is returned by iterate methods like previous() or next() if
they have returned all valid boundaries. |
-1 |
0xffffffff |
Protected Constructors
Public Methods
Protected Methods
|
|
|
static |
|
int |
getInt(byte[] buf, int offset) |
|
|
|
static |
|
long |
getLong(byte[] buf, int offset) |
|
|
|
static |
|
short |
getShort(byte[] buf, int offset) |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
Constants
public
static
final
int
DONE
This constant is returned by iterate methods like previous() or next() if
they have returned all valid boundaries.
Constant Value:
-1
(0xffffffff)
Protected Constructors
protected
BreakIterator()
Default constructor, just for invocation by subclass.
Public Methods
public
Object
clone()
Create copy of this iterator, all status including current position is
kept.
public
abstract
int
current()
Return this iterator's current position.
Returns
- this iterator's current position
public
abstract
int
first()
Set this iterator's current position to the first boundary, and return
this position.
Returns
- the position of first boundary
public
abstract
int
following(int offset)
Set the position of the first boundary following the given offset, and
return this position. If there is no boundary after the given offset,
return DONE.
IllegalArgumentException
will be thrown if given offset is
invalid.
Parameters
offset
| the given position to be searched for |
Returns
- the position of the first boundary following the given offset
public
static
Locale[]
getAvailableLocales()
Return all supported locales.
public
static
BreakIterator
getCharacterInstance()
Return a new instance of BreakIterator used to iterate characters using
default locale.
Returns
- a new instance of BreakIterator used to iterate characters using
default locale.
public
static
BreakIterator
getCharacterInstance(Locale where)
Return a new instance of BreakIterator used to iterate characters using
given locale.
Returns
- a new instance of BreakIterator used to iterate characters using
given locale.
public
static
BreakIterator
getLineInstance()
Return a new instance of BreakIterator used to iterate line-breaks using
default locale.
Returns
- a new instance of BreakIterator used to iterate line-breaks using
default locale.
Return a new instance of BreakIterator used to iterate line-breaks using
given locale.
Returns
- a new instance of BreakIterator used to iterate line-breaks using
given locale.
public
static
BreakIterator
getSentenceInstance(Locale where)
Return a new instance of BreakIterator used to iterate sentence-breaks
using given locale.
Returns
- a new instance of BreakIterator used to iterate sentence-breaks
using given locale.
public
static
BreakIterator
getSentenceInstance()
Return a new instance of BreakIterator used to iterate sentence-breaks
using default locale.
Returns
- a new instance of BreakIterator used to iterate sentence-breaks
using default locale.
Return a
CharacterIterator
which represents the text being
analyzed. Please note that the returned value is probably the internal
iterator used by this object, so that if the invoker want to modify the
status of the returned iterator, a clone operation at first is
recommended.
Returns
- a
CharacterIterator
which represents the text
being analyzed.
public
static
BreakIterator
getWordInstance()
Return a new instance of BreakIterator used to iterate word-breaks using
default locale.
Returns
- a new instance of BreakIterator used to iterate word-breaks using
default locale.
Return a new instance of BreakIterator used to iterate word-breaks using
given locale.
Returns
- a new instance of BreakIterator used to iterate word-breaks using
given locale.
public
boolean
isBoundary(int offset)
Return true if the given offset is a boundary position. If this method
returns true, the current iteration position is set to the given
position; if the function returns false, the current iteration position
is set as though following() had been called.
Parameters
offset
| the given offset to check |
Returns
- true if the given offset is a boundary position
public
abstract
int
last()
Set this iterator's current position to the last boundary, and return
this position.
Returns
- the position of last boundary
public
abstract
int
next()
Set this iterator's current position to the next boundary after current
position, and return this position. Return
DONE
if no
boundary found after current position.
Returns
- the position of last boundary
public
abstract
int
next(int n)
Set this iterator's current position to the next boundary after the given
position, and return this position. Return
DONE
if no
boundary found after the given position.
Returns
- the position of last boundary
public
int
preceding(int offset)
Return the position of last boundary precede the given offset, and set
current position to returned value, or
DONE
if the given
offset specifies the starting position.
IllegalArgumentException
will be thrown if given offset is
invalid.
Parameters
offset
| the given start position to be searched for |
Returns
- the position of last boundary precede the given offset
public
abstract
int
previous()
Set this iterator's current position to the previous boundary before
current position, and return this position. Return
DONE
if
no boundary found before current position.
Returns
- the position of last boundary
public
void
setText(String newText)
Set the new text string to be analyzed, the current position will be
reset to beginning of this new string, and the old string will lost.
Parameters
newText
| the new text string to be analyzed
|
public
abstract
void
setText(CharacterIterator newText)
Set new text to be analyzed by given
CharacterIterator
.
The position will be reset to the beginning of the new text, and other
status of this iterator will be kept.
Parameters
newText
| the given CharacterIterator refer to the text
to be analyzed
|
Protected Methods
protected
static
int
getInt(byte[] buf, int offset)
Get an int value from the given byte array, start from given offset.
Parameters
buf
| the bytes to be converted |
offset
| the start position of conversion |
protected
static
long
getLong(byte[] buf, int offset)
Get a long value from the given byte array, start from given offset.
Parameters
buf
| the bytes to be converted |
offset
| the start position of conversion |
protected
static
short
getShort(byte[] buf, int offset)
Get a short value from the given byte array, start from given offset.
Parameters
buf
| the bytes to be converted |
offset
| the start position of conversion |
Returns
- the converted short value