com.sas.util.transforms
Class StringToDictionaryInterfaceTransform

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

public class StringToDictionaryInterfaceTransform
implements com.sas.util.transforms.TransformInputOutputInterface

A transform for converting a String to a DictionaryInterface. This works by tokenizing the input. Data that looks like an int is converted to a Integer; long ints are converted to Long objects; floating point values are converted to Double objects, true/false are converted to Boolean, character literals are converted to a Character object, and pretty much everything else is converted to a String. String values may be quoted if they contain leading or trailing spaces, quotes, or commas.

Each item should be of the form key=value. For example, the String

 a=5,b=9,c=4.5,d="a string","a string, no?"=d,100=max
 
will create a Dictionary with 6 items:
KeyKey typeValueValue type
"a"java.lang.String5java.lang.Integer
"b"java.lang.String9java.lang.Integer
"c"java.lang.String4.5java.lang.Double
"d"java.lang.String"a string"java.lang.String
"a string, no?"java.lang.String"d"java.lang.String
100java.lang.Integer"max"java.lang.String

See Also:
DictionaryInterfaceToStringTransform, Serialized Form

Field Summary
static StringToDictionaryInterfaceTransform defaultInstance
          A default instance which can perform the transformation.
 java.lang.Class dictionaryClass
          Which class to use to make DictionaryInterface instances.
 
Constructor Summary
StringToDictionaryInterfaceTransform()
          Default constructor which uses a ',' delimiter.
StringToDictionaryInterfaceTransform(char delimiter)
          Construct a transform which uses a specific delimiter.
StringToDictionaryInterfaceTransform(char delimiter, char separator)
          Construct a transform which uses a specific delimiter.
 
Method Summary
protected static char defaultDelimiterChar()
           
 java.lang.Class getInputClass()
           
 java.lang.Class getOutputClass()
           
protected  com.sas.collection.DictionaryInterface newDictionary()
          Factory method to create a DictionaryInterface instance when transforming an object.
 com.sas.collection.DictionaryInterface transform(com.sas.collection.DictionaryInterface dictionary, java.lang.String text)
          Transform a text string into a Dictionary
 java.lang.Object transform(java.lang.Object object)
          Transform a String to a DictionaryInterface
 

Field Detail

defaultInstance

public static final StringToDictionaryInterfaceTransform defaultInstance
A default instance which can perform the transformation.


dictionaryClass

public java.lang.Class dictionaryClass
Which class to use to make DictionaryInterface instances. Defaults to com.sas.collection.Dictionary.class, but subclasses may prefer another class that implements DictionaryInterface. The class must have a public no-arg constructor.

Constructor Detail

StringToDictionaryInterfaceTransform

public StringToDictionaryInterfaceTransform()
Default constructor which uses a ',' delimiter.


StringToDictionaryInterfaceTransform

public StringToDictionaryInterfaceTransform(char delimiter)
Construct a transform which uses a specific delimiter.

Parameters:
delimiter - the item delimiter.

StringToDictionaryInterfaceTransform

public StringToDictionaryInterfaceTransform(char delimiter,
                                            char separator)
Construct a transform which uses a specific delimiter.

Parameters:
delimiter - the item delimiter.
Method Detail

defaultDelimiterChar

protected static char defaultDelimiterChar()

transform

public java.lang.Object transform(java.lang.Object object)
                           throws com.sas.util.transforms.TransformException
Transform a String to a DictionaryInterface

Specified by:
transform in interface com.sas.util.transforms.TransformInterface
Parameters:
object - null or a String; it contains a comma separated list of items. Individual items need not be quoted, but quotes are required to preserve leading and/or trailing space, or of the item contains special characters, such as escaped characters, a comma, or a '"' double quote.
Throws:
com.sas.util.transforms.TransformException - if the transform(dictionary, Object) method throws an exception
java.lang.ClassCastException - if object is not a String

newDictionary

protected com.sas.collection.DictionaryInterface newDictionary()
Factory method to create a DictionaryInterface instance when transforming an object. Creates an instance of the class referenced in dictionaryClass, or Dictionary if that is null.

Returns:
a new instance of of the dictionaryClass.

transform

public com.sas.collection.DictionaryInterface transform(com.sas.collection.DictionaryInterface dictionary,
                                                        java.lang.String text)
                                                 throws com.sas.util.transforms.TransformException
Transform a text string into a Dictionary

Parameters:
dictionary - items parsed from the text are put into this dictionary,
text - a comma separated list of items.
delimiter - the delimiter which separates the items.
Throws:
com.sas.util.transforms.TransformException - if the there is an error parsing the text

getInputClass

public java.lang.Class getInputClass()
Specified by:
getInputClass in interface com.sas.util.transforms.TransformInputOutputInterface

getOutputClass

public java.lang.Class getOutputClass()
Specified by:
getOutputClass in interface com.sas.util.transforms.TransformInputOutputInterface



Copyright © 2009 SAS Institute Inc. All Rights Reserved.