com.lonniepryor.blues.util
Class TokenizedStrings

java.lang.Object
  |
  +--com.lonniepryor.blues.util.Strings
        |
        +--com.lonniepryor.blues.util.TokenizedStrings

public abstract class TokenizedStrings
extends Strings

Specification interface for identifying Strings or parts of Strings that are delimeted by a paticular character. Canidate strings are parsed in the same form as by an instance of StringTokenizer set to not return tokens (leasding, trailing, and consecutive delimeters are ignored). Instances of this class may be logically combined using the AND, OR, and NOT operations. Instances may also be sequentially constructed using the Builder class. Many common use-cases are supplied via static accessor methods.

Version:
$Revision: 1.1 $
Author:
Lonnie Pryor

Nested Class Summary
static class TokenizedStrings.Builder
          Helper class for sequentially constructing the elements of a common TokenizedStrings specification.
 
Nested classes inherited from class com.lonniepryor.blues.util.Strings
Strings.Builder
 
Method Summary
static Strings anyTokens()
          Returns a specification satisfied by any non-null string.
protected  boolean evaluate(java.lang.String canidate, int begin, int end)
          Returns true if the specified range satisfies this specification.
static Strings matchingToken(java.lang.String stringPattern, char delimeter)
          Returns a specification satisfied by single-token strings matching the specified string pattern.
static Strings matchingToken(Strings specification, char delimeter)
          Returns a specification satisfied by single-token strings that satisfy the supplied specification.
static Strings parse(java.lang.String tokStringPattern, char delimeter)
          Parses a delimeted string pattern containing the '*' wildcard.
static Strings parseExpression(java.lang.String tokStringPatternExpr, char delimeter)
          Parses a logical expression as described in the Expression class, using this class's parse() method for creating values.
static TokenizedStrings.Builder startingWithAnyTokens()
          Returns a Builder whose resulting Strings specification will allow any number of inital tokens.
static TokenizedStrings.Builder startingWithAtLeastNumTokens(int minTokens)
          Returns a Builder whose resulting Strings specification will require at least the supplied number of inital tokens.
static TokenizedStrings.Builder startingWithToken(java.lang.String stringPattern)
          Returns a Builder whose resulting Strings specification will require the supplied pattern at the beginning of canidate strings.
static TokenizedStrings.Builder startingWithToken(Strings specification)
          Returns a Builder whose resulting Strings specification will require the supplied specification at the beginning of canidate strings.
static Strings withAtLeastNumTokens(int minTokens, char delimeter)
          Returns a specification satisfied by strings with the specified minimum number of tokens.
 
Methods inherited from class com.lonniepryor.blues.util.Strings
and, any, isSatisfiedBy, isSatisfiedBy, isSatisfiedByAll, isSatisfiedByAny, matching, matching, not, notEmpty, or, parse, parseExpression, selectAll, selectFirst, startingWith, startingWith, startingWithAny, startingWithAtLeastNumChars, withAtLeastNumChars
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

anyTokens

public static Strings anyTokens()
Returns a specification satisfied by any non-null string.

Returns:
A specification satisfied by any non-null string.

withAtLeastNumTokens

public static Strings withAtLeastNumTokens(int minTokens,
                                           char delimeter)
Returns a specification satisfied by strings with the specified minimum number of tokens.

Parameters:
minTokens - The minimum number of tokens in valid strings.
delimeter - The token delimeter.
Returns:
A specification satisfied by strings with the specified minimum number of tokens

matchingToken

public static Strings matchingToken(java.lang.String stringPattern,
                                    char delimeter)
Returns a specification satisfied by single-token strings matching the specified string pattern.

Parameters:
stringPattern - The pattern for the single token canidates.
delimeter - The token delimeter.
Returns:
A specification satisfied by single-token strings matching the specified string pattern.
See Also:
Strings.parse(String)

matchingToken

public static Strings matchingToken(Strings specification,
                                    char delimeter)
Returns a specification satisfied by single-token strings that satisfy the supplied specification.

Parameters:
specification - The specification for the single token canidates.
delimeter - The token delimeter.
Returns:
A specification satisfied by single-token strings that satisfy the supplied specification.

startingWithAnyTokens

public static TokenizedStrings.Builder startingWithAnyTokens()
Returns a Builder whose resulting Strings specification will allow any number of inital tokens.

Returns:
A Builder whose resulting Strings specification will allow any number of inital tokens.

startingWithAtLeastNumTokens

public static TokenizedStrings.Builder startingWithAtLeastNumTokens(int minTokens)
Returns a Builder whose resulting Strings specification will require at least the supplied number of inital tokens.

Parameters:
minTokens - The minimum number of tokens to require.
Returns:
A Builder whose resulting Strings specification will require at least the supplied number of inital tokens.

startingWithToken

public static TokenizedStrings.Builder startingWithToken(java.lang.String stringPattern)
Returns a Builder whose resulting Strings specification will require the supplied pattern at the beginning of canidate strings.

Parameters:
stringPattern - The pattern required at the beginning of canidates.
Returns:
A Builder whose resulting Strings specification will require the supplied pattern at the beginning of canidate strings.
See Also:
Strings.parse(String)

startingWithToken

public static TokenizedStrings.Builder startingWithToken(Strings specification)
Returns a Builder whose resulting Strings specification will require the supplied specification at the beginning of canidate strings.

Parameters:
specification - The specification required at the beginning of canidates.
Returns:
A Builder whose resulting Strings specification will require the supplied specification at the beginning of canidate strings.

parse

public static Strings parse(java.lang.String tokStringPattern,
                            char delimeter)
Parses a delimeted string pattern containing the '*' wildcard. Format:
   tok-strings   ::=  token [ delimiter token ]...
   token         ::=  See Strings.parse()
   delimiter     ::=  delim-char [ delim-char ]
   delim-char    ::=  Any single character
 
Astriks will match zero or more characters except the delimeter. Double delimeters will match any number of delimeted tokens, all other characters are matched exactly. Patterns may not start or end with the delimeter.

Parameters:
tokStringPattern - The content of the pattern.
delimeter - The token delimeter.
Returns:
A Strings specification from the supplied pattern.
Throws:
ParseException - if the pattern is invalid.
See Also:
Strings.parse(String)

parseExpression

public static Strings parseExpression(java.lang.String tokStringPatternExpr,
                                      char delimeter)
Parses a logical expression as described in the Expression class, using this class's parse() method for creating values.

Parameters:
tokStringPatternExpr - The content of the pattern expression.
delimeter - The token delimeter.
Returns:
A Strings specification from the supplied pattern expression.
Throws:
ParseException - if the pattern expression is invalid.
See Also:
Expression, parse(String, char)

evaluate

protected final boolean evaluate(java.lang.String canidate,
                                 int begin,
                                 int end)
Description copied from class: Strings
Returns true if the specified range satisfies this specification.

Specified by:
evaluate in class Strings
Parameters:
canidate - The String to test.
begin - The beginning of the range (inclusive).
end - The end of the range(excusive).
Returns:
True if the specified range satisfies this specification.


Copyright © 2003 Blues Framework. All Rights Reserved.