net.sf.tuplespace.simple
Class SimpleTemplate

java.lang.Object
  extended bynet.sf.tuplespace.simple.SimpleTemplate
All Implemented Interfaces:
Template

public class SimpleTemplate
extends Object
implements Template

An implementation of Template which considers null as matching anything, and Class matching objects of the specified class.


Field Summary
protected  org.apache.commons.logging.Log logger
          A Log instance that this class and subclasses can use to log their actions.
 
Constructor Summary
SimpleTemplate(Object template0)
          Instantiate a template with a single parameter.
SimpleTemplate(Object[] templates)
          The general constructor–instantiate a template with a variable number of parameters.
SimpleTemplate(Object template0, Object template1)
          Instantiate a template with two parameters.
SimpleTemplate(Object template0, Object template1, Object template2)
          Instantiate a template with three parameters.
 
Method Summary
 boolean equals(Object o)
          Templates can be equal to each other if they follow the same template, that is they have the same formal and actual parameters in the same order.
 int hashCode()
           
protected  boolean isTemplateATypeMatch(Object templateValue)
          Determines if templateValue represents a type match.
protected  boolean isTemplateAValueMatch(Object templateValue)
          Determines if templateValue represents a value match.
protected  boolean isTemplateAWildcardMatch(Object templateValue)
          Determines if templateValue is a wildcard match.
protected  boolean isTypeMatch(Object templateValue, Object tupleValue)
          Determines if both values match according to a type match.
protected  boolean isValueMatch(Object templateValue, Object tupleValue)
          Determines if both values are equal, according to some definition of equal.
protected  boolean isWildcardMatch(Object templateValue, Object tupleValue)
          Determines if tupleValue is acceptable as a wildcard value.
 boolean matches(Tuple tuple)
          Attempt to match tuple with this template.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
A Log instance that this class and subclasses can use to log their actions.

Constructor Detail

SimpleTemplate

public SimpleTemplate(Object template0)
Instantiate a template with a single parameter.

Parameters:
template0 - The template value.

SimpleTemplate

public SimpleTemplate(Object template0,
                      Object template1)
Instantiate a template with two parameters.

Parameters:
template0 - A template value.
template1 - A template value.

SimpleTemplate

public SimpleTemplate(Object template0,
                      Object template1,
                      Object template2)
Instantiate a template with three parameters.

Parameters:
template0 - A template value.
template1 - A template value.
template2 - A template value.

SimpleTemplate

public SimpleTemplate(Object[] templates)
The general constructor–instantiate a template with a variable number of parameters.

Parameters:
templates - The template values.
Method Detail

matches

public final boolean matches(Tuple tuple)
Attempt to match tuple with this template.

This implementation allows nulls in the template to match anything. If the template's value at the same position is a Class, any objects of the specified class (or a subtype) will match.

The following table explains the relationships:

Template value Tuple value Result Description
null Any true null always matches
String.class new Integer(4) false Object not of same type
String.class null false Object not of same type
new Integer(32) null false Object not of same type
Number.class new Integer(4) true Object assignable to template class
"abc "123" false Not equal, according to String.equals(java.lang.Object)
"abc "Abc" false Not equal, according to String.equals(java.lang.Object)

Specified by:
matches in interface Template
Parameters:
tuple - The tuple to match.
Returns:
true if the tuple matches.

isTemplateAWildcardMatch

protected boolean isTemplateAWildcardMatch(Object templateValue)
Determines if templateValue is a wildcard match.

Parameters:
templateValue - The value, as retrieved from the template.
Returns:
true if this is a wildcard match, false if not.

isWildcardMatch

protected boolean isWildcardMatch(Object templateValue,
                                  Object tupleValue)
Determines if tupleValue is acceptable as a wildcard value.

Parameters:
templateValue - The value, as retrieved from the template.
tupleValue - The value, as retrieved from the tuple.
Returns:
true if tupleValue matches the wildcard pattern, false if not.

isTemplateATypeMatch

protected boolean isTemplateATypeMatch(Object templateValue)
Determines if templateValue represents a type match.

Type matches are matches based on types, not on values.

Parameters:
templateValue - The value, as retrieved from the template.
Returns:
true if this is a type match, false if not.

isTypeMatch

protected boolean isTypeMatch(Object templateValue,
                              Object tupleValue)
Determines if both values match according to a type match.

Parameters:
templateValue - The value, as retrieved from the template.
tupleValue - The value, as retrieved from the tuple.
Returns:
true if tupleValue matches, based only on the parameters types, false if not.

isTemplateAValueMatch

protected boolean isTemplateAValueMatch(Object templateValue)
Determines if templateValue represents a value match.

Parameters:
templateValue - The value, as retrieved from the template.
Returns:
true if this is a value match, false if not.

isValueMatch

protected boolean isValueMatch(Object templateValue,
                               Object tupleValue)
Determines if both values are equal, according to some definition of equal.

Parameters:
templateValue - The value, as retrieved from the template.
tupleValue - The value, as retrieved from the tuple.
Returns:
true if tupleValue matches, based on the object's values, false if not.

equals

public boolean equals(Object o)
Templates can be equal to each other if they follow the same template, that is they have the same formal and actual parameters in the same order.

Parameters:
o - The other template to test equality against.
Returns:
true if both templates have the same formal and actual parameters in the same order.

hashCode

public int hashCode()

toString

public String toString()