com.sas.util.transforms
Class StringToCollectionInterfaceTransform

com.sas.util.transforms.StringToCollectionInterfaceTransform
All Implemented Interfaces:
com.sas.util.transforms.TransformInterface, java.io.Serializable
Direct Known Subclasses:
StringToOrderedCollectionInterfaceTransform

public class StringToCollectionInterfaceTransform
implements com.sas.util.transforms.TransformInterface

A transform for converting a String to a CollectionInterface. 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.

See Also:
StaticCollectionInterfaceToStringTransform, Serialized Form

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

Field Detail

defaultInstance

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


collectionClass

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

Constructor Detail

StringToCollectionInterfaceTransform

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


StringToCollectionInterfaceTransform

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

Parameters:
delimiter - the item delimiter.

StringToCollectionInterfaceTransform

public StringToCollectionInterfaceTransform(char delimiter,
                                            com.sas.collection.CollectionInterface collection)
Construct a transform which uses a specific delimiter.

Parameters:
delimiter - the item delimiter.
collection - an output collection to return from transform(Object)
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 CollectionInterface

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(collection, Object) method throws an exception
java.lang.ClassCastException - if object is not a String

newCollection

protected com.sas.collection.CollectionInterface newCollection()
Factory method to create a CollectionInterface instance when transforming an object. Creates an instance of the class referenced in collectionClass, or Collection if that is null.

Returns:
a new instance of com.sas.collection.Collection

transform

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

Parameters:
collection - items parsed from the text are appended to this string list
text - a comma separated list of items.
Throws:
com.sas.util.transforms.TransformException - if the transform(Object) method throws an exception



Copyright © 2009 SAS Institute Inc. All Rights Reserved.