Java Doc for BreakIterator.java in  » 6.0-JDK-Modules » j2me » java » text » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » java.text 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.text.BreakIterator

All known Subclasses:   java.text.RuleBasedBreakIterator,
BreakIterator
abstract public class BreakIterator implements Cloneable(Code)
The BreakIterator class implements methods for finding the location of boundaries in text. Instances of BreakIterator maintain a current position and scan over text returning the index of characters where boundaries occur. Internally, BreakIterator scans text using a CharacterIterator, and is thus able to scan text held by any object implementing that protocol. A StringCharacterIterator is used to scan String objects passed to setText.

You use the factory methods provided by this class to create instances of various types of break iterators. In particular, use getWordIterator, getLineIterator, getSentenceIterator, and getCharacterIterator to create BreakIterators that perform word, line, sentence, and character boundary analysis respectively. A single BreakIterator can work only on one unit (word, line, sentence, and so on). You must use a different iterator for each unit boundary analysis you wish to perform.

Line boundary analysis determines where a text string can be broken when line-wrapping. The mechanism correctly handles punctuation and hyphenated words.

Sentence boundary analysis allows selection with correct interpretation of periods within numbers and abbreviations, and trailing punctuation marks such as quotation marks and parentheses.

Word boundary analysis is used by search and replace functions, as well as within text editing applications that allow the user to select words with a double click. Word selection provides correct interpretation of punctuation marks within and following words. Characters that are not part of a word, such as symbols or punctuation marks, have word-breaks on both sides.

Character boundary analysis allows users to interact with characters as they expect to, for example, when moving the cursor through a text string. Character boundary analysis provides correct navigation of through character strings, regardless of how the character is stored. For example, an accented character might be stored as a base character and a diacritical mark. What users consider to be a character can differ between languages.

BreakIterator is intended for use with natural languages only. Do not use this class to tokenize a programming language.

Examples:

Creating and using text boundaries

 public static void main(String args[]) {
 if (args.length == 1) {
 String stringToExamine = args[0];
 //print each word in order
 BreakIterator boundary = BreakIterator.getWordInstance();
 boundary.setText(stringToExamine);
 printEachForward(boundary, stringToExamine);
 //print each sentence in reverse order
 boundary = BreakIterator.getSentenceInstance(Locale.US);
 boundary.setText(stringToExamine);
 printEachBackward(boundary, stringToExamine);
 printFirst(boundary, stringToExamine);
 printLast(boundary, stringToExamine);
 }
 }
 
Print each element in order
 public static void printEachForward(BreakIterator boundary, String source) {
 int start = boundary.first();
 for (int end = boundary.next();
 end != BreakIterator.DONE;
 start = end, end = boundary.next()) {
 System.out.println(source.substring(start,end));
 }
 }
 
Print each element in reverse order
 public static void printEachBackward(BreakIterator boundary, String source) {
 int end = boundary.last();
 for (int start = boundary.previous();
 start != BreakIterator.DONE;
 end = start, start = boundary.previous()) {
 System.out.println(source.substring(start,end));
 }
 }
 
Print first element
 public static void printFirst(BreakIterator boundary, String source) {
 int start = boundary.first();
 int end = boundary.next();
 System.out.println(source.substring(start,end));
 }
 
Print last element
 public static void printLast(BreakIterator boundary, String source) {
 int end = boundary.last();
 int start = boundary.previous();
 System.out.println(source.substring(start,end));
 }
 
Print the element at a specified position
 public static void printAt(BreakIterator boundary, int pos, String source) {
 int end = boundary.following(pos);
 int start = boundary.previous();
 System.out.println(source.substring(start,end));
 }
 
Find the next word
 public static int nextWordStartAfter(int pos, String text) {
 BreakIterator wb = BreakIterator.getWordInstance();
 wb.setText(text);
 int last = wb.following(pos);
 int current = wb.next();
 while (current != BreakIterator.DONE) {
 for (int p = last; p < current; p++) {
 if (Character.isLetter(text.charAt(p))
 return last;
 }
 last = current;
 current = wb.next();
 }
 return BreakIterator.DONE;
 }
 
(The iterator returned by BreakIterator.getWordInstance() is unique in that the break positions it returns don't represent both the start and end of the thing being iterated over. That is, a sentence-break iterator returns breaks that each represent the end of one sentence and the beginning of the next. With the word-break iterator, the characters between two boundaries might be a word, or they might be the punctuation or whitespace between two words. The above code uses a simple heuristic to determine which boundary is the beginning of a word: If the characters between this boundary and the next boundary include at least one letter (this can be an alphabetical letter, a CJK ideograph, a Hangul syllable, a Kana character, etc.), then the text between this boundary and the next is a word; otherwise, it's the material between words.)

See Also:   CharacterIterator


Field Summary
final public static  intDONE
     DONE is returned by previous() and next() after all valid boundaries have been returned.

Constructor Summary
protected  BreakIterator()
     Constructor.

Method Summary
public  Objectclone()
    
abstract public  intcurrent()
    
abstract public  intfirst()
     Return the first boundary.
abstract public  intfollowing(int offset)
     Return the first boundary following the specified offset. The value returned is always greater than the offset or the value BreakIterator.DONE
Parameters:
  offset - the offset to begin scanning.
public static synchronized  Locale[]getAvailableLocales()
    
public static  BreakIteratorgetCharacterInstance()
     Create BreakIterator for character-breaks using default locale Returns an instance of a BreakIterator implementing character breaks.
public static  BreakIteratorgetCharacterInstance(Locale where)
     Create BreakIterator for character-breaks using specified locale Returns an instance of a BreakIterator implementing character breaks. Character breaks are boundaries of combining character sequences.
Parameters:
  where - the local.
public static  BreakIteratorgetLineInstance()
     Create BreakIterator for line-breaks using default locale. Returns an instance of a BreakIterator implementing line breaks.
public static  BreakIteratorgetLineInstance(Locale where)
     Create BreakIterator for line-breaks using specified locale. Returns an instance of a BreakIterator implementing line breaks.
public static  BreakIteratorgetSentenceInstance()
     Create BreakIterator for sentence-breaks using default locale Returns an instance of a BreakIterator implementing sentence breaks.
public static  BreakIteratorgetSentenceInstance(Locale where)
     Create BreakIterator for sentence-breaks using specified locale Returns an instance of a BreakIterator implementing sentence breaks.
Parameters:
  where - the local.
abstract public  CharacterIteratorgetText()
    
public static  BreakIteratorgetWordInstance()
     Create BreakIterator for word-breaks using default locale. Returns an instance of a BreakIterator implementing word breaks. WordBreak is usefull for word selection (ex.
public static  BreakIteratorgetWordInstance(Locale where)
     Create BreakIterator for word-breaks using specified locale. Returns an instance of a BreakIterator implementing word breaks. WordBreak is usefull for word selection (ex.
public  booleanisBoundary(int offset)
     Return true if the specified position is a boundary position.
Parameters:
  offset - the offset to check.
abstract public  intlast()
     Return the last boundary.
abstract public  intnext(int n)
     Return the nth boundary from the current boundary
Parameters:
  n - which boundary to return.
abstract public  intnext()
     Return the boundary following the current boundary. The character index of the next text boundary or DONE if allboundaries have been returned.
public  intpreceding(int offset)
     Return the last boundary preceding the specfied offset. The value returned is always less than the offset or the value BreakIterator.DONE.
Parameters:
  offset - the offset to begin scanning.
abstract public  intprevious()
     Return the boundary preceding the current boundary.
public  voidsetText(String newText)
     Set a new text string to be scanned.
abstract public  voidsetText(CharacterIterator newText)
     Set a new text for scanning.

Field Detail
DONE
final public static int DONE(Code)
DONE is returned by previous() and next() after all valid boundaries have been returned.




Constructor Detail
BreakIterator
protected BreakIterator()(Code)
Constructor. BreakIterator is stateless and has no default behavior.




Method Detail
clone
public Object clone()(Code)
Create a copy of this iterator A copy of this



current
abstract public int current()(Code)
Return character index of the text boundary that was most recently returned by next(), previous(), first(), or last() The boundary most recently returned.



first
abstract public int first()(Code)
Return the first boundary. The iterator's current position is set to the first boundary. The character index of the first text boundary.



following
abstract public int following(int offset)(Code)
Return the first boundary following the specified offset. The value returned is always greater than the offset or the value BreakIterator.DONE
Parameters:
  offset - the offset to begin scanning. Valid valuesare determined by the CharacterIterator passed tosetText(). Invalid values causean IllegalArgumentException to be thrown. The first boundary after the specified offset.



getAvailableLocales
public static synchronized Locale[] getAvailableLocales()(Code)
Get the set of Locales for which BreakIterators are installed available locales



getCharacterInstance
public static BreakIterator getCharacterInstance()(Code)
Create BreakIterator for character-breaks using default locale Returns an instance of a BreakIterator implementing character breaks. Character breaks are boundaries of combining character sequences. A BreakIterator for character-breaks
See Also:   Locale.getDefault



getCharacterInstance
public static BreakIterator getCharacterInstance(Locale where)(Code)
Create BreakIterator for character-breaks using specified locale Returns an instance of a BreakIterator implementing character breaks. Character breaks are boundaries of combining character sequences.
Parameters:
  where - the local. If a specific character break is notavaliable for the specified local, a default character break is returned. A BreakIterator for character-breaks



getLineInstance
public static BreakIterator getLineInstance()(Code)
Create BreakIterator for line-breaks using default locale. Returns an instance of a BreakIterator implementing line breaks. Line breaks are logically possible line breaks, actual line breaks are usually determined based on display width. LineBreak is useful for word wrapping text. A BreakIterator for line-breaks
See Also:   java.util.Locale.getDefault



getLineInstance
public static BreakIterator getLineInstance(Locale where)(Code)
Create BreakIterator for line-breaks using specified locale. Returns an instance of a BreakIterator implementing line breaks. Line breaks are logically possible line breaks, actual line breaks are usually determined based on display width. LineBreak is useful for word wrapping text.
Parameters:
  where - the local. If a specific LineBreak is notavaliable for the specified locale, a default LineBreak is returned. A BreakIterator for line-breaks



getSentenceInstance
public static BreakIterator getSentenceInstance()(Code)
Create BreakIterator for sentence-breaks using default locale Returns an instance of a BreakIterator implementing sentence breaks. A BreakIterator for sentence-breaks
See Also:   java.util.Locale.getDefault



getSentenceInstance
public static BreakIterator getSentenceInstance(Locale where)(Code)
Create BreakIterator for sentence-breaks using specified locale Returns an instance of a BreakIterator implementing sentence breaks.
Parameters:
  where - the local. If a specific SentenceBreak is notavaliable for the specified local, a default SentenceBreak is returned. A BreakIterator for sentence-breaks



getText
abstract public CharacterIterator getText()(Code)
Get the text being scanned the text being scanned



getWordInstance
public static BreakIterator getWordInstance()(Code)
Create BreakIterator for word-breaks using default locale. Returns an instance of a BreakIterator implementing word breaks. WordBreak is usefull for word selection (ex. double click) A BreakIterator for word-breaks
See Also:   java.util.Locale.getDefault



getWordInstance
public static BreakIterator getWordInstance(Locale where)(Code)
Create BreakIterator for word-breaks using specified locale. Returns an instance of a BreakIterator implementing word breaks. WordBreak is usefull for word selection (ex. double click)
Parameters:
  where - the local. If a specific WordBreak is notavaliable for the specified locale, a default WordBreak is returned. A BreakIterator for word-breaks



isBoundary
public boolean isBoundary(int offset)(Code)
Return true if the specified position is a boundary position.
Parameters:
  offset - the offset to check. True if "offset" is a boundary position.
since:
   1.2



last
abstract public int last()(Code)
Return the last boundary. The iterator's current position is set to the last boundary. The character index of the last text boundary.



next
abstract public int next(int n)(Code)
Return the nth boundary from the current boundary
Parameters:
  n - which boundary to return. A value of 0does nothing. Negative values move to previous boundariesand positive values move to later boundaries. The index of the nth boundary from the current position.



next
abstract public int next()(Code)
Return the boundary following the current boundary. The character index of the next text boundary or DONE if allboundaries have been returned. Equivalent to next(1).



preceding
public int preceding(int offset)(Code)
Return the last boundary preceding the specfied offset. The value returned is always less than the offset or the value BreakIterator.DONE.
Parameters:
  offset - the offset to begin scanning. Valid values aredetermined by the CharacterIterator passed to setText().Invalid values cause an IllegalArgumentException to be thrown. The last boundary before the specified offset.
since:
   1.2



previous
abstract public int previous()(Code)
Return the boundary preceding the current boundary. The character index of the previous text boundary or DONE if allboundaries have been returned.



setText
public void setText(String newText)(Code)
Set a new text string to be scanned. The current scan position is reset to first().
Parameters:
  newText - new text to scan.



setText
abstract public void setText(CharacterIterator newText)(Code)
Set a new text for scanning. The current scan position is reset to first().
Parameters:
  newText - new text to scan.



Methods inherited from java.lang.Object
public boolean equals(Object obj)(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.