com.sas.util.transforms
Class FormatTransform

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

public class FormatTransform

Transform between numeric and String data using a Format. This transform converts between numeric data and Strings using the format method of a Format object, or converts a String to a number using the parse methods. 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.

You can create property links between two components such that one object's property is set to the formatted 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 B.Y to display the formatted value of A.X using the DecimalFormat #,###.##, you could use:

  com.sas.PropertyLinkAdaptor(A, "X", B, "Y", new FormatTransform(new java.text.DecimalFormat("#,###.##")));
 
See PropertyLinkAdaptor.addLink(Object, String, Object, String, com.sas.util.transforms.TransformInterface)

Since:
1.2
See Also:
ParseTransform, Serialized Form

Field Summary
static FormatTransform defaultInstance
          A default instance which transforms between numbers and strings using the Locale's default number format.
 
Fields inherited from class com.sas.util.transforms.BaseFormatTransform
format, SASpattern
 
Constructor Summary
FormatTransform()
          Construct a default FormatTransform which uses default rules to convert between number and String values.
FormatTransform(java.text.Format format)
          Construct a FormatTransform which uses the format/parse methods of the format object to convert between number and String values.
 
Method Summary
 java.lang.Object transform(java.lang.Object object)
          Transform an object by applying the format to it.
 
Methods inherited from class com.sas.util.transforms.BaseFormatTransform
getDateFormat, getDecimalFormat, getFormat, getSASFormat, setDateFormat, setDecimalFormat, setFormat, setSASFormat
 

Field Detail

defaultInstance

public static final FormatTransform defaultInstance
A default instance which transforms between numbers and strings using the Locale's default number format.

Constructor Detail

FormatTransform

public FormatTransform()
Construct a default FormatTransform which uses default rules to convert between number and String values.


FormatTransform

public FormatTransform(java.text.Format format)
Construct a FormatTransform which uses the format/parse methods of the format object to convert between number and String values.

Method Detail

transform

public java.lang.Object transform(java.lang.Object object)
                           throws com.sas.util.transforms.TransformException
Transform an object by applying the format to it.

Specified by:
transform in interface com.sas.util.transforms.TransformInterface
Specified by:
transform in class BaseFormatTransform
Parameters:
object - an object to format
Returns:
the value of getFormat().format(object), or if there is no format, the Object is converted to a String if it is a Number or if it implements one of DoubleDataInterface or FloatDataInterface, then the corresponding toString method will be invoked on the selected double or float value. For example, if the object implements DoubleDataInterface, then the value is formatted via DoubleData.toString(((DoubleDataInterface) object).getDoubleData()).

Else, if the object implements one of the other numeric interfaces in the com.sas.lang package, then the corresponding numeric value is read from the object and formatted as a string. For example, if the object implements IntegerDataInterface, then the value is formatted via Integer.toString(((IntegerDataInterface) object).getIntegerData()).

Throws:
com.sas.util.transforms.TransformException



Copyright © 2009 SAS Institute Inc. All Rights Reserved.