Java Doc for SearchIterator.java in  » Internationalization-Localization » icu4j » com » ibm » icu » 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 » Internationalization Localization » icu4j » com.ibm.icu.text 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.ibm.icu.text.SearchIterator

All known Subclasses:   com.ibm.icu.text.StringSearch,
SearchIterator
abstract public class SearchIterator (Code)

SearchIterator is an abstract base class that defines a protocol for text searching. Subclasses provide concrete implementations of various search algorithms. A concrete subclass, StringSearch, is provided that implements language-sensitive pattern matching based on the comparison rules defined in a RuleBasedCollator object. Instances of SearchIterator maintain a current position and scan over the target text, returning the indices where a match is found and the length of each match. Generally, the sequence of forward matches will be equivalent to the sequence of backward matches.One case where this statement may not hold is when non-overlapping mode is set on and there are continuous repetitive patterns in the text. Consider the case searching for pattern "aba" in the text "ababababa", setting overlapping mode off will produce forward matches at offsets 0, 4. However when a backwards search is done, the results will be at offsets 6 and 2.

If matches searched for have boundary restrictions. BreakIterators can be used to define the valid boundaries of such a match. Once a BreakIterator is set, potential matches will be tested against the BreakIterator to determine if the boundaries are valid and that all characters in the potential match are equivalent to the pattern searched for. For example, looking for the pattern "fox" in the text "foxy fox" will produce match results at offset 0 and 5 with length 3 if no BreakIterators were set. However if a WordBreakIterator is set, the only match that would be found will be at the offset 5. Since, the SearchIterator guarantees that if a BreakIterator is set, all its matches will match the given pattern exactly, a potential match that passes the BreakIterator might still not produce a valid match. For instance the pattern "e" will not be found in the string "\u00e9" (latin small letter e with acute) if a CharacterBreakIterator is used. Even though "e" is a part of the character "\u00e9" and the potential match at offset 0 length 1 passes the CharacterBreakIterator test, "\u00e9" is not equivalent to "e", hence the SearchIterator rejects the potential match. By default, the SearchIterator does not impose any boundary restriction on the matches, it will return all results that match the pattern. Illustrating with the above example, "e" will be found in the string "\u00e9" if no BreakIterator is specified.

SearchIterator also provides a means to handle overlapping matches via the API setOverlapping(boolean). For example, if overlapping mode is set, searching for the pattern "abab" in the text "ababab" will match at positions 0 and 2, whereas if overlapping is not set, SearchIterator will only match at position 0. By default, overlapping mode is not set.

The APIs in SearchIterator are similar to that of other text iteration classes such as BreakIterator. Using this class, it is easy to scan through text looking for all occurances of a match.

Example of use:

 String target = "The quick brown fox jumped over the lazy fox";
 String pattern = "fox";
 SearchIterator iter = new StringSearch(pattern, target);
 for (int pos = iter.first(); pos != SearchIterator.DONE; 
 pos = iter.next()) {
 // println matches at offset 16 and 41 with length 3
 System.out.println("Found match at " + pos + ", length is " 
 + iter.getMatchLength());
 }
 target = "ababababa";
 pattern = "aba";
 iter.setTarget(new StringCharacterIterator(pattern));
 iter.setOverlapping(false);
 System.out.println("Overlapping mode set to false");
 System.out.println("Forward matches of pattern " + pattern + " in text "
 + text + ": ");
 for (int pos = iter.first(); pos != SearchIterator.DONE; 
 pos = iter.next()) {
 // println matches at offset 0 and 4 with length 3
 System.out.println("offset " + pos + ", length " 
 + iter.getMatchLength());
 }
 System.out.println("Backward matches of pattern " + pattern + " in text "
 + text + ": ");
 for (int pos = iter.last(); pos != SearchIterator.DONE; 
 pos = iter.previous()) {
 // println matches at offset 6 and 2 with length 3
 System.out.println("offset " + pos + ", length " 
 + iter.getMatchLength());
 }
 System.out.println("Overlapping mode set to true");
 System.out.println("Index set to 2");
 iter.setIndex(2);
 iter.setOverlapping(true);
 System.out.println("Forward matches of pattern " + pattern + " in text "
 + text + ": ");
 for (int pos = iter.first(); pos != SearchIterator.DONE; 
 pos = iter.next()) {
 // println matches at offset 2, 4 and 6 with length 3
 System.out.println("offset " + pos + ", length " 
 + iter.getMatchLength());
 }
 System.out.println("Index set to 2");
 iter.setIndex(2);
 System.out.println("Backward matches of pattern " + pattern + " in text "
 + text + ": ");
 for (int pos = iter.last(); pos != SearchIterator.DONE; 
 pos = iter.previous()) {
 // println matches at offset 0 with length 3
 System.out.println("offset " + pos + ", length " 
 + iter.getMatchLength());
 }
 


author:
   Laura Werner, synwee
See Also:   BreakIterator


Field Summary
final public static  intDONE
     DONE is returned by previous() and next() after all valid matches have been returned, and by first() and last() if there are no matches at all.
protected  BreakIteratorbreakIterator
     The BreakIterator to define the boundaries of a logical match.
protected  intmatchLength
     Length of the most current match in target text.
protected  CharacterIteratortargetText
     Target text for searching.

Constructor Summary
protected  SearchIterator(CharacterIterator target, BreakIterator breaker)
     Protected constructor for use by subclasses. Initializes the iterator with the argument target text for searching and sets the BreakIterator. See class documentation for more details on the use of the target text and BreakIterator.
Parameters:
  target - The target text to be searched.
Parameters:
  breaker - A BreakIterator that is used to determine the boundaries of a logical match.

Method Summary
final public  intfirst()
     Return the index of the first forward match in the target text.
final public  intfollowing(int position)
     Return the index of the first forward match in target text that is at or after argument position.
public  BreakIteratorgetBreakIterator()
     Returns the BreakIterator that is used to restrict the indexes at which matches are detected.
abstract public  intgetIndex()
     Return the index in the target text at which the iterator is currently positioned.
public  intgetMatchLength()
    

Returns the length of the most recent match in the target text.

public  intgetMatchStart()
    

Returns the index of the most recent match in the target text. This call returns a valid result only after a successful call to SearchIterator.first , SearchIterator.next , SearchIterator.previous , or SearchIterator.last . Just after construction, or after a searching method returns DONE, this method will return DONE.

Use getMatchLength to get the length of the matched text. getMatchedText will return the subtext in the searched target text from index getMatchStart() with length getMatchLength().

public  StringgetMatchedText()
     Returns the text that was matched by the most recent call to SearchIterator.first , SearchIterator.next , SearchIterator.previous , or SearchIterator.last .
public  CharacterIteratorgetTarget()
     Return the target text that is being searched.
abstract protected  inthandleNext(int start)
    

Abstract method that subclasses override to provide the mechanism for finding the next forwards match in the target text.

abstract protected  inthandlePrevious(int startAt)
    

Abstract method which subclasses override to provide the mechanism for finding the next backwards match in the target text.

public  booleanisOverlapping()
     Return true if the overlapping property has been set.
final public  intlast()
     Return the index of the first backward match in target text.
public  intnext()
     Search forwards in the target text for the next valid match, starting the search from the current iterator position.
final public  intpreceding(int position)
     Return the index of the first backwards match in target text that ends at or before argument position.
public  intprevious()
     Search backwards in the target text for the next valid match, starting the search from the current iterator position.
public  voidreset()
    

Resets the search iteration.

public  voidsetBreakIterator(BreakIterator breakiter)
     Set the BreakIterator that is used to restrict the points at which matches are detected.
public  voidsetIndex(int position)
    

Sets the position in the target text at which the next search will start.

protected  voidsetMatchLength(int length)
     Sets the length of the most recent match in the target text.
public  voidsetOverlapping(boolean allowOverlap)
    

Determines whether overlapping matches are returned.

public  voidsetTarget(CharacterIterator text)
     Set the target text to be searched.

Field Detail
DONE
final public static int DONE(Code)
DONE is returned by previous() and next() after all valid matches have been returned, and by first() and last() if there are no matches at all.
See Also:   SearchIterator.previous
See Also:   SearchIterator.next



breakIterator
protected BreakIterator breakIterator(Code)
The BreakIterator to define the boundaries of a logical match. This value can be a null. See class documentation for more information.
See Also:   SearchIterator.setBreakIterator(BreakIterator)
See Also:   SearchIterator.getBreakIterator
See Also:   BreakIterator



matchLength
protected int matchLength(Code)
Length of the most current match in target text. Value 0 is the default value.
See Also:   SearchIterator.setMatchLength
See Also:   SearchIterator.getMatchLength



targetText
protected CharacterIterator targetText(Code)
Target text for searching.
See Also:   SearchIterator.setTarget(CharacterIterator)
See Also:   SearchIterator.getTarget




Constructor Detail
SearchIterator
protected SearchIterator(CharacterIterator target, BreakIterator breaker)(Code)
Protected constructor for use by subclasses. Initializes the iterator with the argument target text for searching and sets the BreakIterator. See class documentation for more details on the use of the target text and BreakIterator.
Parameters:
  target - The target text to be searched.
Parameters:
  breaker - A BreakIterator that is used to determine the boundaries of a logical match. This argument can be null.
exception:
  IllegalArgumentException - thrown when argument target is null,or of length 0
See Also:   BreakIterator
See Also:   




Method Detail
first
final public int first()(Code)
Return the index of the first forward match in the target text. This method sets the iteration to begin at the start of the target text and searches forward from there. The index of the first forward match, or DONE if there are no matches.
See Also:   SearchIterator.getMatchStart
See Also:   SearchIterator.getMatchLength
See Also:   SearchIterator.getMatchedText
See Also:   SearchIterator.following
See Also:   SearchIterator.preceding
See Also:   SearchIterator.next
See Also:   SearchIterator.previous
See Also:   SearchIterator.last
See Also:   SearchIterator.DONE



following
final public int following(int position)(Code)
Return the index of the first forward match in target text that is at or after argument position. This method sets the iteration to begin at the specified position in the the target text and searches forward from there. The index of the first forward match, or DONE if there are no matches.
See Also:   SearchIterator.getMatchStart
See Also:   SearchIterator.getMatchLength
See Also:   SearchIterator.getMatchedText
See Also:   SearchIterator.first
See Also:   SearchIterator.preceding
See Also:   SearchIterator.next
See Also:   SearchIterator.previous
See Also:   SearchIterator.last
See Also:   SearchIterator.DONE



getBreakIterator
public BreakIterator getBreakIterator()(Code)
Returns the BreakIterator that is used to restrict the indexes at which matches are detected. This will be the same object that was passed to the constructor or to setBreakIterator. If the BreakIterator has not been set, null will be returned. See setBreakIterator for more information. the BreakIterator set to restrict logic matches
See Also:   SearchIterator.setBreakIterator
See Also:   BreakIterator



getIndex
abstract public int getIndex()(Code)
Return the index in the target text at which the iterator is currently positioned. If the iteration has gone past the end of the target text, or past the beginning for a backwards search, SearchIterator.DONE is returned. index in the target text at which the iterator is currently positioned.
See Also:   SearchIterator.first
See Also:   SearchIterator.next
See Also:   SearchIterator.previous
See Also:   SearchIterator.last
See Also:   SearchIterator.DONE



getMatchLength
public int getMatchLength()(Code)

Returns the length of the most recent match in the target text. This call returns a valid result only after a successful call to SearchIterator.first , SearchIterator.next , SearchIterator.previous , or SearchIterator.last . Just after construction, or after a searching method returns DONE, this method will return 0. See getMatchStart() for more details.

The length of the most recent match in the target text, or 0 if there is no match.
See Also:   SearchIterator.getMatchStart
See Also:   SearchIterator.getMatchedText
See Also:   SearchIterator.first
See Also:   SearchIterator.next
See Also:   SearchIterator.previous
See Also:   SearchIterator.last
See Also:   SearchIterator.DONE



getMatchStart
public int getMatchStart()(Code)

Returns the index of the most recent match in the target text. This call returns a valid result only after a successful call to SearchIterator.first , SearchIterator.next , SearchIterator.previous , or SearchIterator.last . Just after construction, or after a searching method returns DONE, this method will return DONE.

Use getMatchLength to get the length of the matched text. getMatchedText will return the subtext in the searched target text from index getMatchStart() with length getMatchLength().

index to a substring within the text string that is being searched.
See Also:   SearchIterator.getMatchLength
See Also:   SearchIterator.getMatchedText
See Also:   SearchIterator.first
See Also:   SearchIterator.next
See Also:   SearchIterator.previous
See Also:   SearchIterator.last
See Also:   SearchIterator.DONE



getMatchedText
public String getMatchedText()(Code)
Returns the text that was matched by the most recent call to SearchIterator.first , SearchIterator.next , SearchIterator.previous , or SearchIterator.last . If the iterator is not pointing at a valid match, for instance just after construction or after DONE has been returned, an empty String will be returned. See getMatchStart for more information
See Also:   SearchIterator.getMatchStart
See Also:   SearchIterator.getMatchLength
See Also:   SearchIterator.first
See Also:   SearchIterator.next
See Also:   SearchIterator.previous
See Also:   SearchIterator.last
See Also:   SearchIterator.DONE the substring in the target text of the most recent match



getTarget
public CharacterIterator getTarget()(Code)
Return the target text that is being searched. target text being searched.
See Also:   SearchIterator.setTarget



handleNext
abstract protected int handleNext(int start)(Code)

Abstract method that subclasses override to provide the mechanism for finding the next forwards match in the target text. This allows different subclasses to provide different search algorithms.

If a match is found, this function must call setMatchLength(int) to set the length of the result match. The iterator is adjusted so that its current index, as returned by SearchIterator.getIndex , is the starting position of the match if one was found. If a match is not found, DONE will be returned.


Parameters:
  start - index in the target text at which the forwards search should begin. the starting index of the next forwards match if found, DONE otherwise
See Also:   SearchIterator.setMatchLength(int)
See Also:   SearchIterator.handlePrevious(int)
See Also:   SearchIterator.DONE



handlePrevious
abstract protected int handlePrevious(int startAt)(Code)

Abstract method which subclasses override to provide the mechanism for finding the next backwards match in the target text. This allows different subclasses to provide different search algorithms.

If a match is found, this function must call setMatchLength(int) to set the length of the result match. The iterator is adjusted so that its current index, as returned by SearchIterator.getIndex , is the starting position of the match if one was found. If a match is not found, DONE will be returned.


Parameters:
  startAt - index in the target text at which the backwards search should begin. the starting index of the next backwards match if found, DONE otherwise
See Also:   SearchIterator.setMatchLength(int)
See Also:   SearchIterator.handleNext(int)
See Also:   SearchIterator.DONE



isOverlapping
public boolean isOverlapping()(Code)
Return true if the overlapping property has been set. See setOverlapping(boolean) for more information.
See Also:   SearchIterator.setOverlapping true if the overlapping property has been set, false otherwise



last
final public int last()(Code)
Return the index of the first backward match in target text. This method sets the iteration to begin at the end of the target text and searches backwards from there. The starting index of the first backward match, or DONE if there are no matches.
See Also:   SearchIterator.getMatchStart
See Also:   SearchIterator.getMatchLength
See Also:   SearchIterator.getMatchedText
See Also:   SearchIterator.first
See Also:   SearchIterator.preceding
See Also:   SearchIterator.next
See Also:   SearchIterator.previous
See Also:   SearchIterator.following
See Also:   SearchIterator.DONE



next
public int next()(Code)
Search forwards in the target text for the next valid match, starting the search from the current iterator position. The iterator is adjusted so that its current index, as returned by SearchIterator.getIndex , is the starting position of the match if one was found. If a match is found, the index of the match is returned, otherwise DONE is returned. If overlapping mode is set, the beginning of the found match can be before the end of the current match, if any. The starting index of the next forward match after the current iterator position, or DONE if there are no more matches.
See Also:   SearchIterator.getMatchStart
See Also:   SearchIterator.getMatchLength
See Also:   SearchIterator.getMatchedText
See Also:   SearchIterator.following
See Also:   SearchIterator.preceding
See Also:   SearchIterator.previous
See Also:   SearchIterator.first
See Also:   SearchIterator.last
See Also:   SearchIterator.DONE



preceding
final public int preceding(int position)(Code)
Return the index of the first backwards match in target text that ends at or before argument position. This method sets the iteration to begin at the argument position index of the target text and searches backwards from there. The starting index of the first backwards match, or DONE if there are no matches.
See Also:   SearchIterator.getMatchStart
See Also:   SearchIterator.getMatchLength
See Also:   SearchIterator.getMatchedText
See Also:   SearchIterator.first
See Also:   SearchIterator.following
See Also:   SearchIterator.next
See Also:   SearchIterator.previous
See Also:   SearchIterator.last
See Also:   SearchIterator.DONE



previous
public int previous()(Code)
Search backwards in the target text for the next valid match, starting the search from the current iterator position. The iterator is adjusted so that its current index, as returned by SearchIterator.getIndex , is the starting position of the match if one was found. If a match is found, the index is returned, otherwise DONE is returned. If overlapping mode is set, the end of the found match can be after the beginning of the previous match, if any. The starting index of the next backwards match after the current iterator position, or DONE if there are no more matches.
See Also:   SearchIterator.getMatchStart
See Also:   SearchIterator.getMatchLength
See Also:   SearchIterator.getMatchedText
See Also:   SearchIterator.following
See Also:   SearchIterator.preceding
See Also:   SearchIterator.next
See Also:   SearchIterator.first
See Also:   SearchIterator.last
See Also:   SearchIterator.DONE



reset
public void reset()(Code)

Resets the search iteration. All properties will be reset to their default values.

If a forward iteration is initiated, the next search will begin at the start of the target text. Otherwise, if a backwards iteration is initiated, the next search will begin at the end of the target text.




setBreakIterator
public void setBreakIterator(BreakIterator breakiter)(Code)
Set the BreakIterator that is used to restrict the points at which matches are detected. Using null as the parameter is legal; it means that break detection should not be attempted. See class documentation for more information.
Parameters:
  breakiter - A BreakIterator that will be used to restrict the points at which matches are detected.
See Also:   SearchIterator.getBreakIterator
See Also:   BreakIterator



setIndex
public void setIndex(int position)(Code)

Sets the position in the target text at which the next search will start. This method clears any previous match.


Parameters:
  position - position from which to start the next search
exception:
  IndexOutOfBoundsException - thrown if argument position is outof the target text range.
See Also:   SearchIterator.getIndex



setMatchLength
protected void setMatchLength(int length)(Code)
Sets the length of the most recent match in the target text. Subclasses' handleNext() and handlePrevious() methods should call this after they find a match in the target text.
Parameters:
  length - new length to set
See Also:   SearchIterator.handleNext
See Also:   SearchIterator.handlePrevious



setOverlapping
public void setOverlapping(boolean allowOverlap)(Code)

Determines whether overlapping matches are returned. See the class documentation for more information about overlapping matches.

The default setting of this property is false


Parameters:
  allowOverlap - flag indicator if overlapping matches are allowed
See Also:   SearchIterator.isOverlapping



setTarget
public void setTarget(CharacterIterator text)(Code)
Set the target text to be searched. Text iteration will then begin at the start of the text string. This method is useful if you want to reuse an iterator to search within a different body of text.
Parameters:
  text - new text iterator to look for match,
exception:
  IllegalArgumentException - thrown when text is null or has0 length
See Also:   SearchIterator.getTarget



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(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.