com.sas.util.transforms
Class ParseTransform

com.sas.util.transforms.ParseTransform
All Implemented Interfaces:
com.sas.util.transforms.TransformInterface, java.io.Serializable

public class ParseTransform

Transform from String to numeric data using a Format. This transform converts between a String to a number using the parseObject() method of the format object. The Format can be a NumberFormat, any Format instance returned from SASFormat (if you wish to format using SAS formats), or any other class that extends from Format.

Note that in the current release of the class libraries, parsing using the SASFormat classes in the com.sas.text package is not implemented.

You can create property links between two components such that one object's property is set to the parsed value of another property. For example, if component A has a property X of type double, and component B has a property Y of type String and you want A.X to display the parsed numeric value of B.Y using the DecimalFormat #,###.##, you could use:

  com.sas.PropertyLinkAdaptor(B, "Y", A, "X", new ParseTransform(new java.text.DecimalFormat("#,###.##")));
 

Since:
1.2
See Also:
FormatTransform, Serialized Form

Field Summary
static ParseTransform defaultInstance
          A default instance which converts Strings to numbers using the Locale's default number format.
protected  java.text.ParsePosition pp
          Parameter passed to parseObject; it is reset to position 0 before each call.
 
Fields inherited from class com.sas.util.transforms.BaseFormatTransform
format, SASpattern
 
Constructor Summary
ParseTransform()
          Construct a default FormatTransform which uses default rules to convert Strings to numeric values.
ParseTransform(java.text.Format format)
          Construct a FormatTransform which uses the parseObject method of the format object to convert Strings to numeric values.
 
Method Summary
 void setSASFormat(java.lang.String pattern)
          Set the SAS format pattern to use for parsing.
 java.lang.Object transform(java.lang.Object object)
          Transform an object (a String) into another object by invoking the parseObject() method of the format property available via getFormat() If no format exists, the string is assumed to represent a number and is parsed using DoubleData.valueOf(String).
 
Methods inherited from class com.sas.util.transforms.BaseFormatTransform
getDateFormat, getDecimalFormat, getFormat, getSASFormat, setDateFormat, setDecimalFormat, setFormat
 

Field Detail

defaultInstance

public static final ParseTransform defaultInstance
A default instance which converts Strings to numbers using the Locale's default number format.


pp

protected java.text.ParsePosition pp
Parameter passed to parseObject; it is reset to position 0 before each call. By Using of this field, we don't have to allocate a new ParsePosition for each parseObject call.

Constructor Detail

ParseTransform

public ParseTransform()
Construct a default FormatTransform which uses default rules to convert Strings to numeric values.


ParseTransform

public ParseTransform(java.text.Format format)
Construct a FormatTransform which uses the parseObject method of the format object to convert Strings to numeric values.

Method Detail

transform

public java.lang.Object transform(java.lang.Object object)
                           throws com.sas.util.transforms.TransformException
Transform an object (a String) into another object by invoking the parseObject() method of the format property available via getFormat() If no format exists, the string is assumed to represent a number and is parsed using DoubleData.valueOf(String).

Specified by:
transform in interface com.sas.util.transforms.TransformInterface
Specified by:
transform in class BaseFormatTransform
Parameters:
object - an object, normally a String, from which another object (normally a number) is parsed. If the object is not a String, it's toString() method is invoked and the result is parsed.
Returns:
the pared value, normally a Number, but it can be whatever is returned by getFormat().parseObject(object).
Throws:
com.sas.util.transforms.TransformException - if the value cannot be parsed (i.e. parseObject() throws an exception).

setSASFormat

public void setSASFormat(java.lang.String pattern)
Set the SAS format pattern to use for parsing. This will set the date and decimal format to null and set the format to a new SASFormat instance. Note that in the current release of the class libraries, parsing using the SASFormat classes in the com.sas.text package is not implemented. Thus, this method will throw an IllegalStateException..

Overrides:
setSASFormat in class BaseFormatTransform
Throws:
java.lang.IllegalStateException - in all cases, as SAS formats are not yet implemented.



Copyright © 2009 SAS Institute Inc. All Rights Reserved.