com.lonniepryor.blues.util
Class Parameters

java.lang.Object
  |
  +--com.lonniepryor.blues.util.Parameters

public abstract class Parameters
extends java.lang.Object

Specification interface for identifying ordered sequences of Types. 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 Parameters.Builder
          Helper class for sequentially constructing the elements of a common TokenizedStrings specification.
 
Constructor Summary
protected Parameters()
          Creates a new Parameters object.
 
Method Summary
 Parameters and(Parameters specification)
          Returns a specification representing a logical AND of this specification on the left and the supplied specification on the right.
static Parameters any()
          Returns a specification satified by non-null Class arrays.
protected abstract  boolean evaluate(java.lang.Class[] paramTypes, int index)
          Returns true if the supplied parameter array satisfies this specification.
 boolean isSatisfiedBy(java.lang.Class[] paramTypes)
          Returns true if the supplied parameter array is not null and satisfies this specification.
 boolean isSatisifiedByAll(java.lang.Class[][] all)
          Returns true if all of the supplied Class arrays satisfy this specification.
 boolean isSatisifiedByAny(java.lang.Class[][] any)
          Returns true if any of the supplied Class arrays satisfy this specification.
 Parameters not()
          Returns a specification representing a logical NOT of this specification.
 Parameters or(Parameters specification)
          Returns a specification representing a logical OR of this specification on the left and the supplied specification on the right.
static Parameters parse(java.lang.String parametersPattern)
          Parses a pattern string into a complete Parameters specification.
 java.lang.Class[][] selectAll(java.lang.Class[][] from)
          Selects all the Class arrays that satisfy this specification from the supplied array.
 java.lang.Class[] selectFirst(java.lang.Class[][] from)
          Selects the first Class array that satisfies this specification from the supplied array.
static Parameters.Builder startingWithAny()
          Returns a Builder whose resulting Parameters specification will allow any number of inital elements.
static Parameters.Builder startingWithElement(Types specification)
          Returns a Builder whose resulting Parameters specification will require the supplied inital element.
static Parameters.Builder startingWithElements(Types[] specifications)
          Returns a Builder whose resulting Parameters specification will require the supplied inital elements.
static Parameters withElement(Types specification)
          Creates a new specification satified by Class arrays with one element that satisifies the supplied specification.
static Parameters withElements(Types[] specifications)
          Creates a new specification satified by Class arrays with elements that satisify the supplied specifications, in order.
static Parameters withNoElements()
          Returns a specification satified by empty Class arrays.
static Parameters withNumElements(int numberOfElements)
          Creates a new specification satified by Class arrays with the specified number of elements.
static Parameters withOneElement()
          Returns a specification satified by Class arrays with exactly one element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Parameters

protected Parameters()
Creates a new Parameters object.

Method Detail

any

public static Parameters any()
Returns a specification satified by non-null Class arrays.

Returns:
A specification satified by non-null Class arrays.

withNoElements

public static Parameters withNoElements()
Returns a specification satified by empty Class arrays.

Returns:
A specification satified by empty Class arrays.

withOneElement

public static Parameters withOneElement()
Returns a specification satified by Class arrays with exactly one element.

Returns:
A specification satified by Class arrays with exactly one element.

withNumElements

public static Parameters withNumElements(int numberOfElements)
Creates a new specification satified by Class arrays with the specified number of elements.

Parameters:
numberOfElements - The number of elements to test for.
Returns:
A new specification satified by Class arrays with the specified number of elements.

withElement

public static Parameters withElement(Types specification)
Creates a new specification satified by Class arrays with one element that satisifies the supplied specification.

Parameters:
specification - The specification to match the single parameter class to.
Returns:
A new specification satified by Class arrays with one element that satisifies the supplied specification.

withElements

public static Parameters withElements(Types[] specifications)
Creates a new specification satified by Class arrays with elements that satisify the supplied specifications, in order.

Parameters:
specifications - The specifications to match the parameter classes to.
Returns:
A new specification satified by Class arrays with elements that satisify the supplied specifications, in order.

startingWithAny

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

Returns:
A Builder whose resulting Parameters specification will allow any number of inital elements.

startingWithElement

public static Parameters.Builder startingWithElement(Types specification)
Returns a Builder whose resulting Parameters specification will require the supplied inital element.

Parameters:
specification - The specification the inital element must match.
Returns:
A Builder whose resulting Parameters specification will require the supplied inital element.

startingWithElements

public static Parameters.Builder startingWithElements(Types[] specifications)
Returns a Builder whose resulting Parameters specification will require the supplied inital elements.

Parameters:
specifications - The specifications the inital elements must match.
Returns:
A Builder whose resulting Parameters specification will require the supplied inital elements.

parse

public static Parameters parse(java.lang.String parametersPattern)
Parses a pattern string into a complete Parameters specification. Format:
   parameters  ::=  element [ "," element ]...
   element     ::=  ".." | types-expr
 
'..' matches zero or more parameter types, everything else will be treated as a Types expression.

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

isSatisfiedBy

public final boolean isSatisfiedBy(java.lang.Class[] paramTypes)
Returns true if the supplied parameter array is not null and satisfies this specification.

Parameters:
paramTypes - The parameter List to test.
Returns:
True if the supplied parameter array is not null and satisfies this specification.

evaluate

protected abstract boolean evaluate(java.lang.Class[] paramTypes,
                                    int index)
Returns true if the supplied parameter array satisfies this specification.

Parameters:
paramTypes - The parameter List to test.
Returns:
True if the supplied parameter array satisfies this specification.

isSatisifiedByAll

public final boolean isSatisifiedByAll(java.lang.Class[][] all)
Returns true if all of the supplied Class arrays satisfy this specification.

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

isSatisifiedByAny

public final boolean isSatisifiedByAny(java.lang.Class[][] any)
Returns true if any of the supplied Class arrays satisfy this specification.

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

selectFirst

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

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

selectAll

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

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

and

public final Parameters and(Parameters 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 Parameters or(Parameters 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 Parameters 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.