com.lonniepryor.blues.util
Class Strings

java.lang.Object
  |
  +--com.lonniepryor.blues.util.Strings
Direct Known Subclasses:
TokenizedStrings

public abstract class Strings
extends java.lang.Object

Specification interface for identifying Strings or parts of Strings. 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 Strings.Builder
          Helper class for sequentially constructing the elements of a common Strings specification.
 
Constructor Summary
protected Strings()
          Creates a new Strings object.
 
Method Summary
 Strings and(Strings specification)
          Returns a specification representing a logical AND of this specification on the left and the supplied specification on the right.
static Strings any()
          Returns a specification satisfied by any non-null string.
protected abstract  boolean evaluate(java.lang.String canidate, int begin, int end)
          Returns true if the specified range satisfies this specification.
 boolean isSatisfiedBy(java.lang.String canidate)
          Returns true if the supplied String is not null and satisfies this specification.
 boolean isSatisfiedBy(java.lang.String canidate, int begin, int end)
          Returns true if the supplied String is not null and the specified range satisfies this specification.
 boolean isSatisfiedByAll(java.lang.String[] all)
          Returns true if all of the supplied Strings satisfy this specification.
 boolean isSatisfiedByAny(java.lang.String[] any)
          Returns true if any of the supplied Strings satisfy this specification.
static Strings matching(Characters specification)
          Returns a specification satisfied by strings with a single character that satisfies the specified specification.
static Strings matching(java.lang.String characters)
          Returns a specification satisfied by strings equal to the specified string.
 Strings not()
          Returns a specification representing a logical NOT of this specification.
static Strings notEmpty()
          Returns a specification satisfied by any non-empty string.
 Strings or(Strings specification)
          Returns a specification representing a logical OR of this specification on the left and the supplied specification on the right.
static Strings parse(java.lang.String stringPattern)
          Parses a string pattern containing the '' wildcard.
static Strings parseExpression(java.lang.String stringPatternExpr)
          Parses a logical expression as described in the Expression class, using this class's parse() method for creating values.
 java.lang.String[] selectAll(java.lang.String[] from)
          Selects all the Strings that satisfy this specification from the supplied array.
 java.lang.String selectFirst(java.lang.String[] from)
          Selects the first Strings that satisfies this specification from the supplied array.
static Strings.Builder startingWith(Characters specification)
          Returns a Builder whose resulting Strings specification will require the supplied character at the beginning of canidate strings.
static Strings.Builder startingWith(java.lang.String characters)
          Returns a Builder whose resulting Strings specification will require the supplied text at the beginning of canidate strings.
static Strings.Builder startingWithAny()
          Returns a Builder whose resulting Strings specification will allow any number of inital characters.
static Strings.Builder startingWithAtLeastNumChars(int minChars)
          Returns a Builder whose resulting Strings specification will require at least the supplied number of inital characters.
static Strings withAtLeastNumChars(int minChars)
          Returns a specification satisfied by strings of at least the specified length.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Strings

protected Strings()
Creates a new Strings object.

Method Detail

any

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

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

notEmpty

public static Strings notEmpty()
Returns a specification satisfied by any non-empty string.

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

withAtLeastNumChars

public static Strings withAtLeastNumChars(int minChars)
Returns a specification satisfied by strings of at least the specified length.

Parameters:
minChars - The minimum length of valid strings.
Returns:
A specification satisfied by strings of al least the specified length

matching

public static Strings matching(Characters specification)
Returns a specification satisfied by strings with a single character that satisfies the specified specification.

Parameters:
specification - The specification to match to.
Returns:
A specification satisfied by strings with a single character that satisfies the specified specification.

matching

public static Strings matching(java.lang.String characters)
Returns a specification satisfied by strings equal to the specified string.

Parameters:
characters - The string to match to.
Returns:
A specification satisfied by strings equal to the specified string.

startingWithAny

public static Strings.Builder startingWithAny()
Returns a Builder whose resulting Strings specification will allow any number of inital characters.

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

startingWithAtLeastNumChars

public static Strings.Builder startingWithAtLeastNumChars(int minChars)
Returns a Builder whose resulting Strings specification will require at least the supplied number of inital characters.

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

startingWith

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

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

startingWith

public static Strings.Builder startingWith(java.lang.String characters)
Returns a Builder whose resulting Strings specification will require the supplied text at the beginning of canidate strings.

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

parse

public static Strings parse(java.lang.String stringPattern)
Parses a string pattern containing the '' wildcard. Format:
   strings     ::=  wildcard | ( [ wildcard ] pattern )
   pattern     ::=  characters [ wildcard [ pattern ] ]
   wildcard    ::=  "*"
   characters  ::=  Any sequence of characters except "*"
 
Astriks will match zero or more characters, all other characters are matched exactly.

Parameters:
stringPattern - The content of the pattern.
Returns:
A Strings specification from the supplied pattern.
Throws:
ParseException - if the pattern is invalid.

parseExpression

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

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

isSatisfiedBy

public final boolean isSatisfiedBy(java.lang.String canidate)
Returns true if the supplied String is not null and satisfies this specification.

Parameters:
canidate - The String to test.
Returns:
True if the supplied String is not null and satisfies this specification.

isSatisfiedBy

public final boolean isSatisfiedBy(java.lang.String canidate,
                                   int begin,
                                   int end)
Returns true if the supplied String is not null and the specified range satisfies this specification.

Parameters:
canidate - The String to test.
begin - The beginning of the range (inclusive).
end - The end of the range(excusive).
Returns:
True if the supplied String is not null and the specified range satisfies this specification.

evaluate

protected abstract boolean evaluate(java.lang.String canidate,
                                    int begin,
                                    int end)
Returns true if the specified range satisfies this specification.

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.

isSatisfiedByAll

public final boolean isSatisfiedByAll(java.lang.String[] all)
Returns true if all of the supplied Strings satisfy this specification.

Parameters:
all - The array of Strings to test.
Returns:
True if all of the supplied Strings satisfy this specification.

isSatisfiedByAny

public final boolean isSatisfiedByAny(java.lang.String[] any)
Returns true if any of the supplied Strings satisfy this specification.

Parameters:
any - The array of Strings to test.
Returns:
True if any of the supplied Strings satisfy this specification.

selectFirst

public final java.lang.String selectFirst(java.lang.String[] from)
Selects the first Strings that satisfies this specification from the supplied array.

Parameters:
from - The array to select from.
Returns:
The first Strings that satisfies this specification from the supplied array.

selectAll

public final java.lang.String[] selectAll(java.lang.String[] from)
Selects all the Strings that satisfy this specification from the supplied array.

Parameters:
from - The array to select from.
Returns:
All the Strings that satisfy this specification from the supplied array.

and

public final Strings and(Strings specification)
Returns a specification representing a logical AND of this specification on the left and the supplied specification on the right.

Parameters:
specification - The specification to AND with.
Returns:
A specification representing a logical AND of this specification on the left and the supplied specification on the right.

or

public final Strings or(Strings specification)
Returns a specification representing a logical OR of this specification on the left and the supplied specification on the right.

Parameters:
specification - The specification to OR with.
Returns:
A specification representing a logical OR of this specification on the left and the supplied specification on the right.

not

public final Strings not()
Returns a specification representing a logical NOT of this specification.

Returns:
A specification representing a logical NOT of this specification.


Copyright © 2003 Blues Framework. All Rights Reserved.