org.sandev.basics.util
Class MatchUtil

java.lang.Object
  extended byorg.sandev.basics.util.MatchUtil

public class MatchUtil
extends java.lang.Object

Simple match expression evaluation. This class allows you to compare a a value to an expression through recursive evaluation of the tokenized expression form. This is NOT intended for use in

  1. situations involving repetitive comparisons which could benefit from formal comparison structures
  2. high criticality situations
  3. situations where treating an int as a long for matching purposes might cause problems due to boundary conditions
  4. situations involving complex expressions (use of constant names, use of parenthetical expressions etc)

For information on more advanced matchers, contact Structs And Nodes Development Services


Constructor Summary
MatchUtil()
           
 
Method Summary
static java.lang.String blend(java.lang.String attr, java.lang.String val)
          Given an attribute and a value in standard match expression form, convert the match expression to an infix form with the attribute specified.
static boolean eval(java.util.Date val, java.lang.String expr)
          Return true if the given value matches the given expression, false otherwise.
static boolean eval(java.util.Date val, java.lang.String[] expr, int index)
          Return true if the given value matches the tokenized expression, false otherwise.
static boolean eval(double val, java.lang.String expr)
          Return true if the given value matches the given expression, false otherwise.
static boolean eval(double val, java.lang.String[] expr, int index)
          Return true if the given value matches the tokenized expression, false otherwise.
static boolean eval(int val, java.lang.String expr)
          Return true if the given value matches the given expression, false otherwise.
static boolean eval(long val, java.lang.String expr)
          Return true if the given value matches the given expression, false otherwise.
static boolean eval(long val, java.lang.String[] expr, int index)
          Return true if the given value matches the tokenized expression, false otherwise.
static boolean eval(java.lang.String val, java.lang.String expr)
          Return true if the given value matches the given expression, false otherwise.
static boolean eval(java.lang.String val, java.lang.String[] expr, int index)
          Return true if the given value matches the tokenized expression, false otherwise.
static void insertImpliedEqualityOperators(java.util.ArrayList al)
          Given a tokenized expression, insert any missing implied equality operators.
static boolean isCompound(java.lang.String expr)
          Return true if this is a compound expression, false otherwise.
static boolean isOperator(java.lang.String oper)
          Return true if this is a valid operator, false otherwise.
static java.lang.String nextToken(java.util.StringTokenizer toker)
          Given a StringTokenizer, return the next token taking into account quoted string values.
static java.lang.String normalizeExprFormat(java.lang.String expr)
          Return the normalized form of the expression so that the returned expression can be tokenized on whitespace.
static int rangeDigitsInteger(java.lang.String rangeExpr, int defaultVal)
          Given an integer value range specification, return the likely number of digits necessary for display.
static boolean startsWithOp(java.lang.String expr)
          Returns true if the given expr string starts with an operator as defined by normalizeExprFormat.
static java.lang.String[] tokenize(java.lang.String expr)
          Given an expression, return an array of tokens.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatchUtil

public MatchUtil()
Method Detail

eval

public static boolean eval(int val,
                           java.lang.String expr)
Return true if the given value matches the given expression, false otherwise.


eval

public static boolean eval(long val,
                           java.lang.String expr)
Return true if the given value matches the given expression, false otherwise.


eval

public static boolean eval(double val,
                           java.lang.String expr)
Return true if the given value matches the given expression, false otherwise.


eval

public static boolean eval(java.lang.String val,
                           java.lang.String expr)
Return true if the given value matches the given expression, false otherwise.


eval

public static boolean eval(java.util.Date val,
                           java.lang.String expr)
Return true if the given value matches the given expression, false otherwise.


eval

public static boolean eval(long val,
                           java.lang.String[] expr,
                           int index)
Return true if the given value matches the tokenized expression, false otherwise.


eval

public static boolean eval(double val,
                           java.lang.String[] expr,
                           int index)
Return true if the given value matches the tokenized expression, false otherwise.


eval

public static boolean eval(java.lang.String val,
                           java.lang.String[] expr,
                           int index)
Return true if the given value matches the tokenized expression, false otherwise.


eval

public static boolean eval(java.util.Date val,
                           java.lang.String[] expr,
                           int index)
Return true if the given value matches the tokenized expression, false otherwise.


isOperator

public static boolean isOperator(java.lang.String oper)
Return true if this is a valid operator, false otherwise. Other matchers may support additional operators.


tokenize

public static java.lang.String[] tokenize(java.lang.String expr)
Given an expression, return an array of tokens. Quoted strings are converted into a single token, and the enclosing quotes are stripped. No explicit support for parens, operators and values must be space separated.


insertImpliedEqualityOperators

public static void insertImpliedEqualityOperators(java.util.ArrayList al)
Given a tokenized expression, insert any missing implied equality operators. So something like "NY or NJ or PA" has a chance of working. This works off the assumption that what we are reading is of the form:


nextToken

public static java.lang.String nextToken(java.util.StringTokenizer toker)
Given a StringTokenizer, return the next token taking into account quoted string values.


rangeDigitsInteger

public static int rangeDigitsInteger(java.lang.String rangeExpr,
                                     int defaultVal)
Given an integer value range specification, return the likely number of digits necessary for display. This allows a display to guess how much space to allocate for an input field. If the method can't figure out how many digits, then the default is returned.


normalizeExprFormat

public static java.lang.String normalizeExprFormat(java.lang.String expr)
Return the normalized form of the expression so that the returned expression can be tokenized on whitespace. This method does not pay attention to quoting and picks up on the operators: The operators are assumed to be whitespace surrounded and are not dealt with here.

This method may add additional whitespace around operators. Embedded whitespace is a possibility, and consuming methods must be prepared to handle any corresponding empty tokens from this formatting when tokenizing the resulting string on whitespace. This method ensures that operators are whitespace delimited, but does not trim whitespace or ensure minimum whitespace.


startsWithOp

public static boolean startsWithOp(java.lang.String expr)
Returns true if the given expr string starts with an operator as defined by normalizeExprFormat.


blend

public static java.lang.String blend(java.lang.String attr,
                                     java.lang.String val)
Given an attribute and a value in standard match expression form, convert the match expression to an infix form with the attribute specified. So for example given and "myAttr" this method returns

The value is assumed to be in normalized form so it can be tokenized on whitespace.


isCompound

public static boolean isCompound(java.lang.String expr)
Return true if this is a compound expression, false otherwise. This is most important for expressions containing OR, which are prone to misinterpretation without parenthesization.