Search this API

y.util
Class ObjectStringConversion

java.lang.Object
  extended by y.util.ObjectStringConversion
All Implemented Interfaces:
ObjectStringConverter

public class ObjectStringConversion
extends java.lang.Object
implements ObjectStringConverter

This class serves as a basic implementation of the ObjectStringConverter interface. It is capable of converting objects of different types to Strings and vice versa.
It provides a default singleton instance that contains a great number of different implementations for a variety of types.

See Also:
getInstance()
 

Constructor Summary
protected ObjectStringConversion()
          Creates a new instance of ObjectStringConversion with no converters installed initially.
 
Method Summary
 java.lang.Object convertToObject(java.lang.String o, java.lang.Class asClass)
          This method takes a String, and tries to interpret it as a String representation of the given class type, which it will then create.
 java.lang.String convertToString(java.lang.Object o, java.lang.Class asClass)
          This method takes an object, treats it as an object of the given class type and produces a String representation.
 ObjectStringConverter findObjectStringConverter(java.lang.Class forClass)
           
static ObjectStringConversion getInstance()
          Provides access to the singleton instance
 void registerAsSingleton()
          Registers this instance as the singleton instance returned by getInstance().
protected  void registerDefaultConverters()
          Registers default implementations for this instance for a number of different classes and types including: Integer Float Double Byte Short Boolean Long int float double byte boolean short long String Color File Date Font URL Rectangle2D Point2D Class Locale
 void registerObjectStringConverter(java.lang.Class clazz, ObjectStringConverter s)
          Registers another handler for the given class type
 ObjectStringConverter removeObjectStringConverter(java.lang.Class forClass)
          Removes a handler which was previously registered for the given class type
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectStringConversion

protected ObjectStringConversion()
Creates a new instance of ObjectStringConversion with no converters installed initially.

See Also:
registerDefaultConverters()
Method Detail

registerAsSingleton

public void registerAsSingleton()
Registers this instance as the singleton instance returned by getInstance().


registerDefaultConverters

protected void registerDefaultConverters()
Registers default implementations for this instance for a number of different classes and types including:


registerObjectStringConverter

public void registerObjectStringConverter(java.lang.Class clazz,
                                          ObjectStringConverter s)
Registers another handler for the given class type

Parameters:
clazz - the type of class
s - the converter

removeObjectStringConverter

public ObjectStringConverter removeObjectStringConverter(java.lang.Class forClass)
Removes a handler which was previously registered for the given class type

Parameters:
forClass - the type of class
Returns:
the instance that was registered previously for the given class or null if there was no such handler registered

getInstance

public static ObjectStringConversion getInstance()
Provides access to the singleton instance

Returns:
an instance of ObjectStringConversion

convertToObject

public java.lang.Object convertToObject(java.lang.String o,
                                        java.lang.Class asClass)
                                 throws java.lang.IllegalArgumentException
Description copied from interface: ObjectStringConverter
This method takes a String, and tries to interpret it as a String representation of the given class type, which it will then create.

Specified by:
convertToObject in interface ObjectStringConverter
Parameters:
o - the String to convert
asClass - the type which should be generated by this method. the method is free to create a more specific type, but that type must be assignment compatible
Returns:
an object which can safely be cast to the given type
Throws:
java.lang.IllegalArgumentException - if this method is not capable of doing the transformation because of illegal arguments

convertToString

public java.lang.String convertToString(java.lang.Object o,
                                        java.lang.Class asClass)
                                 throws java.lang.IllegalArgumentException
Description copied from interface: ObjectStringConverter
This method takes an object, treats it as an object of the given class type and produces a String representation.

Specified by:
convertToString in interface ObjectStringConverter
Parameters:
o - the object to convert
asClass - the type which should be used to interpret the object, may be less specific than the actual object's type
Returns:
a string representation of the object
Throws:
java.lang.IllegalArgumentException - if this method is not capable of doing the transformation because of illegal arguments

findObjectStringConverter

public ObjectStringConverter findObjectStringConverter(java.lang.Class forClass)

© Copyright 2000-2017,
yWorks GmbH.
All rights reserved.