viper.filters
Class Rules

java.lang.Object
  extended byviper.filters.Rules

public class Rules
extends java.lang.Object

This class is simply a bunch of factory classes for standard rule types.


Constructor Summary
Rules()
           
 
Method Summary
static Filterable.Rule getComparisonRelation(java.lang.Object o, java.lang.String relation)
          Gets a relation operation.
static Filterable.Rule getComplexRule(Filterable f, java.lang.String complexRule, ErrorWriter err)
          Parses a rule of the form rule "value" (|| / &&) ...
static Filterable.Rule getEquality(java.lang.Object o)
          Gets a rule that tests for equality with the target object.
static Filterable.Rule getFalse()
          Gets a rule that always returns false.
static Filterable.Rule getInequality(java.lang.Object o)
          Tests to see if two objects are not equal.
static Filterable.Rule getTrue()
          Gets a rule that always returns true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Rules

public Rules()
Method Detail

getFalse

public static Filterable.Rule getFalse()
Gets a rule that always returns false.

Returns:
the rule that always fails

getTrue

public static Filterable.Rule getTrue()
Gets a rule that always returns true.

Returns:
the rule that always passes

getEquality

public static Filterable.Rule getEquality(java.lang.Object o)
Gets a rule that tests for equality with the target object.

Parameters:
o - The object to test against.
Returns:
rule that tests for equality

getInequality

public static Filterable.Rule getInequality(java.lang.Object o)
Tests to see if two objects are not equal.

Parameters:
o - the object to test against.
Returns:
true iff o != the tested object.

getComparisonRelation

public static Filterable.Rule getComparisonRelation(java.lang.Object o,
                                                    java.lang.String relation)
                                             throws BadDataException
Gets a relation operation. If relation is == or !=, it uses the equals method of the object; otherwise, it casts the object to java.lang.Comparable.

Parameters:
o - The object to compare.
relation - String representing the relation, eg "<" or ">="
Returns:
the given comparison rule
Throws:
BadDataException

getComplexRule

public static Filterable.Rule getComplexRule(Filterable f,
                                             java.lang.String complexRule,
                                             ErrorWriter err)
                                      throws java.lang.IllegalArgumentException
Parses a rule of the form rule "value" (|| / &&) ...
The conjunctions and disjunctions have same precedence; to specify precedence, use parentheses

Parameters:
f - the rule type
complexRule - the string describing the rule
err - the error stream
Returns:
the complex rule
Throws:
java.lang.IllegalArgumentException - if the first rule was not valid. If a later rule is in error, it prints an error to the error writer and returns the valid rule so far. To get an exception on all errors, set err to null. Note that in this case, warnings (lack of quotes) will be ignored.