Rules for classifying data by content.
Classes and Interfaces |
DataTypeParseRuleBase |
Base class for data type parse rule classes, defines commonalities. |
IDataTypeParseRule |
Defines a rule for recognizing and parsing a data type from a string-based
input format (e.g., "-123") into the native type (e.g., Integer ). |
IntegerParseRule |
Data type rule for parsing an integer from an input string. |
LongParseRule |
Data type rule for parsing a long integer from an input string. |
NoopParseRule |
Data type rule for parsing an integer from an input string. |
Class: DataTypeParseRuleBase
next
package
Base class for data type parse rule classes, defines commonalities.
Although this class is technically "thread-hostile" since there is no synchronization
around state changes, in practice instances are immutable once created.
public abstract class com.arsi.mj.datatype.parse.DataTypeParseRuleBase
extends java.lang.Object
Fields |
Format for parsing canonical string form into native type. protected java.text.Format canonicalToNativeParseFormat
|
List of regular expressions for recognizing and transforming input strings. protected java.util.List listInputToCanonicalRegex
|
Name of this rule. protected java.lang.String ruleName
|
Constructors |
public DataTypeParseRuleBase()
|
Methods |
Add regular expression that provides recognition that an input string
is of this data type.
- Parameters:
aRegex - regular expression.
public void addInputToCanonicalRegex(com.arsi.mj.datatype.parse.IDataTypeParseRule.InputToCanonicalRegex aRegex)
|
Parse canonical input string into native type.
- Parameters:
anInput - canonical string form of data type.
- Throws:
ParseException - if canonical input string cannot be parsed.
- Returns:
- native type as Java wrapper or other standard data type instance.
protected java.lang.Object doCanonicalStringToNativeType(java.lang.String anInput) throws java.text.ParseException
|
Get java.text.Format -derived instance for parsing canonical
input string into native value.
- Returns:
- format instance.
protected java.text.Format doGetCanonicalToNativeParseFormat()
|
Set format instance for parsing canonical input string into native value.
- Parameters:
aFmt - format instance.
protected void doSetCanonicalToNativeParseFormat(java.text.Format aFmt)
|
Get regular expressions that provide recognition that an input string
is of this data type and (optionally) transform the input into it's
canonical (normalized) string form.
- Returns:
- list of regular expressions.
public java.util.List getInputToCanonicalRegex()
|
Get comparator that can be used to determine if two rules are equal.
- Parameters:
anAppCtx - application context for looking up data type as JavaBean.
- Returns:
- rule comparator.
public java.util.Comparator getRuleComparator(org.springframework.context.ApplicationContext anAppCtx)
|
Get the name this rule for debug and identification purposes (name is
not guaranteed to be unique and this is not useful as a true rule
identifier or for comparison).
- Returns:
- rule name.
public java.lang.String getRuleName()
|
Attempt to recognize an input string as being of the data type associated
with this rule, optionally transforming the input into it's canonical form.
- Parameters:
anInput - a raw input string.
- Returns:
- canonical string form for parsing into a native type, or NULL
if the input does not appear to be of the data type associated
with this rule.
public java.lang.String inputStringToCanonical(java.lang.String anInput)
|
Set regular expressions that provide recognition that an input string
is of this data type.
- Parameters:
someRegex - list of regular expressions.
public void setInputToCanonicalRegex(java.util.List someRegex)
|
Set the name this rule.
- Parameters:
aName - rule name.
public void setRuleName(java.lang.String aName)
|
Defines a rule for recognizing and parsing a data type from a string-based
input format (e.g., "-123") into the native type (e.g.,
Integer
).
- Parameters:
<T>
- native type as a Java type wrapper class (e.g., Integer
)
or standard JDK type (e.g., String
, BigDecimal
)
<F>
- java.text.Format
-derived class for converting canonical (i.e.,
normalized) string representation to native type. For example, a
SimpleDateFormat
is appropriate for converting a canonical
string (e.g., "YYYYMMDD") to native type java.util.Date
.
public interface com.arsi.mj.datatype.parse.IDataTypeParseRule
Methods |
Parse canonical input string into native type.
- Parameters:
aCanonicalInput - canonical string form of data type (e.g., "-123" for Integer ).
- Throws:
ParseException - if canonical input string cannot be parsed.
- Returns:
- native type as Java wrapper (e.g.,
Integer ) or other
standard data type instance (e.g., java.math.BigDecimal ).
public java.lang.Object canonicalStringToNativeType(java.lang.String aCanonicalInput) throws java.text.ParseException
|
Get java.text.Format -derived instance for parsing canonical
input string into native value.
- Returns:
- format instance.
public java.text.Format getCanonicalToNativeParseFormat()
|
Get data type associated with this rule.
- Parameters:
anAppCtx - application context for looking up data type as JavaBean.
- Returns:
- the rule's data type.
public com.arsi.mj.datatype.IDataType getDataType(org.springframework.context.ApplicationContext anAppCtx)
|
Get regular expressions that provide recognition that an input string
is of this data type and (optionally) transform the input into it's
canonical (normalized) string form.
- Returns:
- list of regular expressions.
public java.util.List getInputToCanonicalRegex()
|
Get comparator that can be used to determine if two rules are equal (less
than and greater than comparisons have no meaning).
- Parameters:
anAppCtx - application context for looking up data type as JavaBean.
- Returns:
- rule comparator
public java.util.Comparator getRuleComparator(org.springframework.context.ApplicationContext anAppCtx)
|
Get name of rule for identification purposes, not guaranteed to be unique
and this is not useful as a true rule identifier or for comparison.
- Returns:
- arbitrary rule name.
public java.lang.String getRuleName()
|
Attempt to recognize an input string as being of the data type associated
with this rule, optionally transforming the input into it's canonical form.
The expressions returned by getInputToCanonicalRegex are
are evaluated in the order of the returned list. All expressions that
require a match must evaluate completely for the input to be considered
of the data type.
- Parameters:
anInput - a raw input string.
- Returns:
- canonical string form for parsing into a native type, or NULL
if the input does not appear to be of the data type associated
with this rule.
public java.lang.String inputStringToCanonical(java.lang.String anInput)
|
Data type rule for parsing an integer from an input string.
Although this class is technically "thread-hostile" since there is no synchronization
around state changes, in practice instances are immutable once created.
Constructors |
public IntegerParseRule()
|
Methods |
public java.lang.Integer canonicalStringToNativeType(java.lang.String anInput) throws java.text.ParseException
|
public java.text.DecimalFormat getCanonicalToNativeParseFormat()
|
public com.arsi.mj.datatype.IDataType getDataType(org.springframework.context.ApplicationContext anAppCtx)
|
public static void main(java.lang.String args) throws java.lang.Exception
|
Set format instance for parsing canonical input string into native value.
- Parameters:
aFmt - format instance.
public void setCanonicalToNativeParseFormat(java.text.DecimalFormat aFmt)
|
Data type rule for parsing a long integer from an input string.
Although this class is technically "thread-hostile" since there is no synchronization
around state changes, in practice instances are immutable once created.
Constructors |
public LongParseRule()
|
Methods |
public java.lang.Long canonicalStringToNativeType(java.lang.String anInput) throws java.text.ParseException
|
public java.text.DecimalFormat getCanonicalToNativeParseFormat()
|
public com.arsi.mj.datatype.IDataType getDataType(org.springframework.context.ApplicationContext anAppCtx)
|
public static void main(java.lang.String args) throws java.lang.Exception
|
Set format instance for parsing canonical input string into native value.
- Parameters:
aFmt - format instance.
public void setCanonicalToNativeParseFormat(java.text.DecimalFormat aFmt)
|
Data type rule for parsing an integer from an input string.
Although this class is technically "thread-hostile" since there is no synchronization
around state changes, in practice instances are immutable once created.
Constructors |
public NoopParseRule()
|
Methods |
public java.lang.String canonicalStringToNativeType(java.lang.String anInput) throws java.text.ParseException
|
public java.text.MessageFormat getCanonicalToNativeParseFormat()
|
public com.arsi.mj.datatype.IDataType getDataType(org.springframework.context.ApplicationContext anAppCtx)
|
public static void main(java.lang.String args) throws java.lang.Exception
|
Set format instance for parsing canonical input string into native value.
- Parameters:
aFmt - format instance.
public void setCanonicalToNativeParseFormat(java.text.MessageFormat aFmt)
|