org.pfsw.text
Class MatchAttribute

java.lang.Object
  extended by org.pfsw.text.MatchElement
      extended by org.pfsw.text.MatchAttribute
All Implemented Interfaces:
java.io.Serializable

public class MatchAttribute
extends MatchElement

An instance of this class holds the name and the pattern values for one attribute. With the matches() method it can be checked against a Map of attributes.

See Also:
Serialized Form

Constructor Summary
MatchAttribute()
          Initialize the new instance with default values.
MatchAttribute(java.lang.String name)
          Initialize the new instance with a name.
 
Method Summary
protected  void apply(MatchRuleVisitor visitor)
           
protected  void applyDatatypes(java.util.Map<java.lang.String,java.lang.Class<?>> datatypes)
           
protected  boolean compare(java.lang.Integer value, java.lang.String ruleValue)
          Returns true if the given value compared by using the current operator to the rule value evaluates to true.
protected  boolean compare(java.lang.String value, java.lang.String ruleValue, boolean ignoreCase)
          Returns true if the given value compared by using the current operator to the rule value evaluates to true.
protected  boolean compareIntegers(int a, int b)
           
protected  void convertToBigDecimal(java.lang.String[] strValues)
           
protected  void convertToDate(java.lang.String[] strValues, java.text.SimpleDateFormat dateFormat)
           
protected  void convertToDouble(java.lang.String[] strValues)
           
protected  void convertToFloat(java.lang.String[] strValues)
           
protected  void convertToInteger(java.lang.String[] strValues)
           
protected  void convertToLong(java.lang.String[] strValues)
           
protected  void convertToType(java.lang.Object type)
           
protected  MatchRuleException createTypeConversionException(java.lang.String value, java.lang.Class<?> type)
           
protected  boolean doBigDecimalMatch(java.lang.Object value)
           
protected  boolean doDateMatch(java.lang.Object value)
           
protected  boolean doDoubleMatch(java.lang.Object value)
           
protected  boolean doFloatMatch(java.lang.Object value)
           
protected  boolean doIntegerMatch(java.lang.Object value)
           
protected  boolean doLongMatch(java.lang.Object value)
           
protected  boolean doMatch(java.util.Map<java.lang.String,?> dictionary)
           
protected  boolean doTypedMatch(java.lang.Object object)
           
 java.lang.String getAttributeName()
          Returns the name of the attribute that will be checked by this rule element
 StringPattern[] getPatterns()
          Returns the value pattern(s) against that will be matched
protected  java.lang.Class<?> getTypeOf(java.lang.Object object)
          Returns the type of the given object or if it is an array or a list the type of its first element.
protected  java.lang.Object getValueType()
           
protected  void ignoreCase(boolean ignoreIt)
           
 boolean ignoreCaseInName()
          Returns true, if the attribute name should be treated not case-sensitive.
protected  void ignoreCaseInName(boolean newValue)
          Sets whether the attribute name should be treated not case-sensitive.
 boolean isAttribute()
          Returns true, if the element is an attribute element.
protected  boolean isCorrectType(java.lang.Object value)
           
protected  boolean isTyped()
           
protected  boolean matchValue(java.lang.Object value)
           
protected
<T> boolean
matchValueAgainstValues(java.lang.Comparable<T> value, T[] values)
           
protected  boolean matchValueArray(java.lang.Object[] values)
           
protected  boolean matchValueCollection(java.util.Collection<?> values)
           
protected  void multiCharWildcardMatchesEmptyString(boolean yesOrNo)
           
protected  java.lang.String nameOfAttribute(java.util.Map<java.lang.String,?> map)
           
protected  java.lang.String objectAsString(java.lang.Object object)
          Returns the string representation of the given object.
protected  MatchRuleCompareOperator operator()
           
protected  void operator(MatchRuleCompareOperator newValue)
           
 void setAttributeName(java.lang.String newValue)
          Sets the name of the attribute that will be checked by this rule element
 void setDatatype(java.lang.Object type)
          Sets the datatype this attribute's value must have.
 void setEqualsOperator()
          Sets the operator for value comparisons of this attribute to EQUALS.
 void setGreaterOperator()
          Sets the operator for value comparisons of this attribute to GREATER.
 void setGreaterOrEqualOperator()
          Sets the operator for value comparisons of this attribute to GREATER OR EQUAL.
 void setLessOperator()
          Sets the operator for value comparisons of this attribute to LESS.
 void setLessOrEqualOperator()
          Sets the operator for value comparisons of this attribute to LESS OR EQUAL.
 void setPattern(StringPattern aPattern)
          Sets the specified pattern as the sole pattern to be checked when matching this attribute against a map.
 void setPatterns(StringPattern[] newValue)
          Sets the value pattern(s) against that will be matched
protected  void setValueType(java.lang.Object newValue)
           
protected
<T> T[]
toArray(java.lang.Object object, java.lang.Class<T> type)
           
 java.lang.String toString()
          Returns a string containing the attribute name, the operator and the value(s) set in this part of a match rule.
protected  java.lang.Object valueInMap(java.util.Map<java.lang.String,?> map)
           
 
Methods inherited from class org.pfsw.text.MatchElement
getAnd, getNot, isGroup, matches, setAnd, setNot
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MatchAttribute

public MatchAttribute()
Initialize the new instance with default values.


MatchAttribute

public MatchAttribute(java.lang.String name)
Initialize the new instance with a name.

Parameters:
name - The name of the attribute
Method Detail

getAttributeName

public java.lang.String getAttributeName()
Returns the name of the attribute that will be checked by this rule element


setAttributeName

public void setAttributeName(java.lang.String newValue)
Sets the name of the attribute that will be checked by this rule element


getPatterns

public StringPattern[] getPatterns()
Returns the value pattern(s) against that will be matched


setPatterns

public void setPatterns(StringPattern[] newValue)
Sets the value pattern(s) against that will be matched


ignoreCaseInName

public boolean ignoreCaseInName()
Returns true, if the attribute name should be treated not case-sensitive.


isAttribute

public boolean isAttribute()
Returns true, if the element is an attribute element.
Here this method always returns true.

Overrides:
isAttribute in class MatchElement

setPattern

public void setPattern(StringPattern aPattern)
Sets the specified pattern as the sole pattern to be checked when matching this attribute against a map.


toString

public java.lang.String toString()
Returns a string containing the attribute name, the operator and the value(s) set in this part of a match rule.

Overrides:
toString in class java.lang.Object

setEqualsOperator

public void setEqualsOperator()
Sets the operator for value comparisons of this attribute to EQUALS.


setGreaterOperator

public void setGreaterOperator()
Sets the operator for value comparisons of this attribute to GREATER.


setLessOperator

public void setLessOperator()
Sets the operator for value comparisons of this attribute to LESS.


setGreaterOrEqualOperator

public void setGreaterOrEqualOperator()
Sets the operator for value comparisons of this attribute to GREATER OR EQUAL.


setLessOrEqualOperator

public void setLessOrEqualOperator()
Sets the operator for value comparisons of this attribute to LESS OR EQUAL.


setDatatype

public void setDatatype(java.lang.Object type)
                 throws MatchRuleException
Sets the datatype this attribute's value must have. Implicitly the current value (pattern) gets converted to that datatype.

Currently supported datatypes are:

Parameters:
type - The type of the attribute's value
Throws:
MatchRuleException - if the current value (pattern) cannot be converted to the specified datatype

doMatch

protected boolean doMatch(java.util.Map<java.lang.String,?> dictionary)
Specified by:
doMatch in class MatchElement

doTypedMatch

protected boolean doTypedMatch(java.lang.Object object)

isCorrectType

protected boolean isCorrectType(java.lang.Object value)

doFloatMatch

protected boolean doFloatMatch(java.lang.Object value)

doDoubleMatch

protected boolean doDoubleMatch(java.lang.Object value)

doBigDecimalMatch

protected boolean doBigDecimalMatch(java.lang.Object value)

doIntegerMatch

protected boolean doIntegerMatch(java.lang.Object value)

doLongMatch

protected boolean doLongMatch(java.lang.Object value)

doDateMatch

protected boolean doDateMatch(java.lang.Object value)

matchValueArray

protected boolean matchValueArray(java.lang.Object[] values)

matchValueCollection

protected boolean matchValueCollection(java.util.Collection<?> values)

matchValue

protected boolean matchValue(java.lang.Object value)

matchValueAgainstValues

protected <T> boolean matchValueAgainstValues(java.lang.Comparable<T> value,
                                              T[] values)

compare

protected boolean compare(java.lang.String value,
                          java.lang.String ruleValue,
                          boolean ignoreCase)
Returns true if the given value compared by using the current operator to the rule value evaluates to true.


compare

protected boolean compare(java.lang.Integer value,
                          java.lang.String ruleValue)
Returns true if the given value compared by using the current operator to the rule value evaluates to true.


compareIntegers

protected boolean compareIntegers(int a,
                                  int b)

ignoreCase

protected void ignoreCase(boolean ignoreIt)
Specified by:
ignoreCase in class MatchElement

multiCharWildcardMatchesEmptyString

protected void multiCharWildcardMatchesEmptyString(boolean yesOrNo)
Specified by:
multiCharWildcardMatchesEmptyString in class MatchElement

apply

protected void apply(MatchRuleVisitor visitor)
Specified by:
apply in class MatchElement

valueInMap

protected java.lang.Object valueInMap(java.util.Map<java.lang.String,?> map)

nameOfAttribute

protected java.lang.String nameOfAttribute(java.util.Map<java.lang.String,?> map)

convertToType

protected void convertToType(java.lang.Object type)
                      throws MatchRuleException
Throws:
MatchRuleException

convertToFloat

protected void convertToFloat(java.lang.String[] strValues)
                       throws MatchRuleException
Throws:
MatchRuleException

convertToDouble

protected void convertToDouble(java.lang.String[] strValues)
                        throws MatchRuleException
Throws:
MatchRuleException

convertToBigDecimal

protected void convertToBigDecimal(java.lang.String[] strValues)
                            throws MatchRuleException
Throws:
MatchRuleException

convertToInteger

protected void convertToInteger(java.lang.String[] strValues)
                         throws MatchRuleException
Throws:
MatchRuleException

convertToLong

protected void convertToLong(java.lang.String[] strValues)
                      throws MatchRuleException
Throws:
MatchRuleException

convertToDate

protected void convertToDate(java.lang.String[] strValues,
                             java.text.SimpleDateFormat dateFormat)
                      throws MatchRuleException
Throws:
MatchRuleException

createTypeConversionException

protected MatchRuleException createTypeConversionException(java.lang.String value,
                                                           java.lang.Class<?> type)

isTyped

protected boolean isTyped()

getTypeOf

protected java.lang.Class<?> getTypeOf(java.lang.Object object)
Returns the type of the given object or if it is an array or a list the type of its first element.


toArray

protected <T> T[] toArray(java.lang.Object object,
                          java.lang.Class<T> type)

applyDatatypes

protected void applyDatatypes(java.util.Map<java.lang.String,java.lang.Class<?>> datatypes)
                       throws MatchRuleException
Specified by:
applyDatatypes in class MatchElement
Throws:
MatchRuleException

objectAsString

protected java.lang.String objectAsString(java.lang.Object object)
Returns the string representation of the given object.

Parameters:
object - The object to get the string representation of (may be null).
Returns:
A string representation of the given object or null if the given object was null.

ignoreCaseInName

protected void ignoreCaseInName(boolean newValue)
Sets whether the attribute name should be treated not case-sensitive.

Specified by:
ignoreCaseInName in class MatchElement

getValueType

protected java.lang.Object getValueType()

setValueType

protected void setValueType(java.lang.Object newValue)

operator

protected MatchRuleCompareOperator operator()

operator

protected void operator(MatchRuleCompareOperator newValue)