net.rim.device.api.util
Class StringMatch

java.lang.Object
  extended by net.rim.device.api.util.StringMatch
All Implemented Interfaces:
Persistable

public final class StringMatch
extends Object
implements Persistable

Checks for matching of substring patterns in strings. The pattern will match a string only if it is an exact match.

Behaviour
You can concatenate a number of substring patterns together, attempting to match against each substring pattern in the conglomerate; separate your patterns with spaces only.

A string matches if it contains all of the patterns. The match is the first instance of any pattern found in the string.

Note that you can search against a substring pattern that is the empty string.


Constructor Summary
StringMatch(String pattern)
          Constructs a new, case-sensitive StringMatch instance.
StringMatch(String patternToMatch, boolean caseSensitivity)
          Constructs a new StringMatch instance.
StringMatch(String patternToMatch, boolean caseSensitivity, boolean spaceDelimitsNewPattern)
          Constructs a new StringMatch instance.
StringMatch(String patternToMatch, boolean caseSensitivity, boolean spaceDelimitsNewPattern, boolean allMatch)
          Constructs a new StringMatch instance.
StringMatch(String[] patterns, boolean caseSensitivity, boolean allMatch)
          Constructs a new StringMatch instance.
 
Method Summary
 int getLastMatchedPattern()
          Retrieves position of the last matched pattern.
 int indexOf(String text)
          Retrieves position of first match in target string.
 int indexOf(String text, int offset)
          Retrieves position of first match in section of target string.
 int indexOf(StringBuffer text, int offset)
          Retrieves position of first match in section of target StringBuffer.
 int numStringsInPattern()
          Retrieves number of substring patterns used in matching.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 



Constructor Detail

StringMatch

public StringMatch(String patternToMatch,
                   boolean caseSensitivity)
Constructs a new StringMatch instance.

This builds a string match object, digesting the provided substring pattern for optimized future use.

Parameters:
pattern - Substring pattern to use in match checking.
caseSensitiviy - If true, matching observes case; if false, disregard case in substring pattern and target string.

StringMatch

public StringMatch(String patternToMatch,
                   boolean caseSensitivity,
                   boolean spaceDelimitsNewPattern)
Constructs a new StringMatch instance.

This builds a string match object, digesting the provided substring pattern for optimized future use.

Parameters:
pattern - Substring pattern to use in match checking.
caseSensitivity - If true, matching observes case; if false, disregard case in substring pattern and target string.
spaceDelimitsNewPattern - If true, patternToMatch is broken into subpatters using space as a delimiter. If false, whole patternToMatch string is used as the pattern, including spaces.
Since:
BlackBerry API 3.6.0

StringMatch

public StringMatch(String patternToMatch,
                   boolean caseSensitivity,
                   boolean spaceDelimitsNewPattern,
                   boolean allMatch)
Constructs a new StringMatch instance.

This builds a string match object, digesting the provided substring pattern for optimized future use.

Parameters:
pattern - Substring pattern to use in match checking.
caseSensitivity - If true, matching observes case; if false, disregard case in substring pattern and target string.
spaceDelimitsNewPattern - If true, patternToMatch is broken into subpatters using space as a delimiter. If false, whole patternToMatch string is used as the pattern, including spaces.
Since:
BlackBerry API 4.0.0

StringMatch

public StringMatch(String[] patterns,
                   boolean caseSensitivity,
                   boolean allMatch)
Constructs a new StringMatch instance.

This builds a string match object, digesting the provided substring pattern for optimized future use.

Parameters:
pattern - Substring pattern to use in match checking.
caseSensitivity - If true, matching observes case; if false, disregard case in substring pattern and target string.
allMatch - If true, all patterns must match for pattern to match.
Since:
BlackBerry API 4.0.0

StringMatch

public StringMatch(String pattern)
Constructs a new, case-sensitive StringMatch instance.

This builds a string match object, digesting the provided substring pattern for optimized future use. This object observes case when matching.

Parameters:
pattern - Substring pattern to use in match checking.


Method Detail

indexOf

public int indexOf(String text)
Retrieves position of first match in target string.

Parameters:
text - Target string.
Returns:
Position of first match of substring pattern(s) in target string, or -1 to indicate no match.

indexOf

public int indexOf(String text,
                   int offset)
            throws IllegalArgumentException
Retrieves position of first match in section of target string.

Parameters:
text - Text containing the section to match against.
offset - Position of first character in section to match against.
Returns:
Position of first match of substring pattern(s) in target string, or -1 to indicate no match.
Throws:
IllegalArgumentException - If offset parameter is not contained in the target string.

indexOf

public int indexOf(StringBuffer text,
                   int offset)
            throws IllegalArgumentException
Retrieves position of first match in section of target StringBuffer.

Parameters:
text - Text containing the section to match against.
offset - Position of first character in section to match against.
Returns:
Position of first match of substring pattern(s) in target string, or -1 to indicate no match.
Throws:
IllegalArgumentException - If offset parameter is not contained in the target string.
Since:
BlackBerry API 3.7.0

numStringsInPattern

public int numStringsInPattern()
Retrieves number of substring patterns used in matching.

Returns:
Number of substring patterns used to match.

getLastMatchedPattern

public int getLastMatchedPattern()
Retrieves position of the last matched pattern.

Returns:
The position of the last matched pattern.
Since:
BlackBerry API 4.0.0





Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal