Search this API

y.util
Class AbstractStringConverter

java.lang.Object
  extended by y.util.AbstractStringConverter
All Implemented Interfaces:
ObjectStringConverter
Direct Known Subclasses:
ReflectionStringConverter

public abstract class AbstractStringConverter
extends java.lang.Object
implements ObjectStringConverter

This class is an abstract base class for classes implementing the ObjectStringConverter interface. Subclasses have to implement the two abstract methods only.

 

Field Summary
protected  java.lang.Class forClass
          the class type which can be converted by this instance
 
Constructor Summary
protected AbstractStringConverter(java.lang.Class forClass)
          Creates a new instance
 
Method Summary
protected abstract  java.lang.Object convertToObject(java.lang.String o)
          This method must be implemented by subclasses. o will never be the null String
 java.lang.Object convertToObject(java.lang.String o, java.lang.Class asClass)
          This method does some checks and then delegates the call to convertToObject(String)
protected abstract  java.lang.String convertToString(java.lang.Object o)
          This method must be implemented by subclasses. o will never be the null object.
 java.lang.String convertToString(java.lang.Object o, java.lang.Class asClass)
          This method does some checks and then delegates the call to convertToString(Object)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

forClass

protected java.lang.Class forClass
the class type which can be converted by this instance

Constructor Detail

AbstractStringConverter

protected AbstractStringConverter(java.lang.Class forClass)
Creates a new instance

Parameters:
forClass - the class type
Method Detail

convertToObject

public java.lang.Object convertToObject(java.lang.String o,
                                        java.lang.Class asClass)
                                 throws java.lang.IllegalArgumentException
This method does some checks and then delegates the call to convertToObject(String)

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
This method does some checks and then delegates the call to convertToString(Object)

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

convertToObject

protected abstract java.lang.Object convertToObject(java.lang.String o)
                                             throws java.lang.IllegalArgumentException
This method must be implemented by subclasses. o will never be the null String

Parameters:
o - the string representation
Returns:
the created object
Throws:
java.lang.IllegalArgumentException - if the method was unable to do the transformation

convertToString

protected abstract java.lang.String convertToString(java.lang.Object o)
                                             throws java.lang.IllegalArgumentException
This method must be implemented by subclasses. o will never be the null object.

Parameters:
o - the object
Returns:
the String representation
Throws:
java.lang.IllegalArgumentException - if the method was unable to do the transformation

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