| java.lang.Object org.geotools.resources.ClassChanger
ClassChanger | abstract public class ClassChanger (Code) | | A central place to register transformations between an arbitrary class and a
Number . For example, it is sometime convenient to consider
Date objects as if they were
Long objects for computation purpose in generic
algorithms. Client can call the following method to convert an arbitrary object
to a
Number :
Object someArbitraryObject = new Date();
Number myObjectAsANumber =
ClassChanger.toNumber ClassChanger.toNumber (someArbitraryObject);
since: 2.0 version: $Id: ClassChanger.java 26581 2007-08-17 18:04:30Z desruisseaux $ author: Martin Desruisseaux |
getFinestClass | public static Class getFinestClass(double value)(Code) | | Returns the smallest class capable to hold the specified value.
|
getTransformedClass | public static synchronized Class getTransformedClass(Class source)(Code) | | Returns the target class for the specified source class, if a suitable
transformation is known. The source class is a
Comparable subclass
that will be specified as input to
ClassChanger.convert . The target class is a
Number subclass that will be returned as output by
ClassChanger.convert .
If no suitable mapping is found, then
source is returned.
|
inverseConvert | abstract protected Comparable inverseConvert(Number value)(Code) | | Returns an instance of the converted classe from a numerical value.
Parameters: value - The value to wrap. An instance of the source classe. |
register | public static synchronized void register(ClassChanger converter) throws IllegalStateException(Code) | | Registers a new transformation. All registered
ClassChanger will
be taken in account by the
ClassChanger.toNumber method. The example below
register a transformation for the
Date class:
ClassChanger.register(new ClassChanger(Date.class, Long.class) {
protected Number convert(final Comparable o) {
return new Long(((Date) o).getTime());
}
protected Comparable inverseConvert(final Number number) {
return new Date(number.longValue());
}
});
Parameters: converter - The ClassChanger to add. throws: IllegalStateException - if an other ClassChanger was alreadyregistered for the same source class. This is usuallynot a concern since the registration usually take place during theclass initialization ("static" constructor). |
toComparable | public static Comparable toComparable(Number value, Class classe) throws ClassNotFoundException(Code) | | Wraps the specified number as an instance of the specified classe.
For example toComparable(Date.class, new Long(time))
is equivalent to new Date(time) . There is of course no
point to use this method if the destination class is know at compile time.
This method is useful for creating instance of classes choosen dynamically
at run time.
Parameters: value - The numerical value (may be null). Parameters: classe - The desired classe for return value. throws: ClassNotFoundException - if classe is not a registered class. |
toNumber | public static Number toNumber(Comparable object) throws ClassNotFoundException(Code) | | Returns the numeric value for the specified object. For example the code
toNumber(new Date()) returns the
Date.getTime value of the specified date object as a
Long .
Parameters: object - Object to convert (may be null). null if object was null; otherwise object if the supplied object is already an instanceof Number; otherwise a new number with the numerical value. throws: ClassNotFoundException - if object is not an instanceof a registered class. |
toPrimitive | public static Class toPrimitive(Class c) throws IllegalArgumentException(Code) | | Converts a wrapper class to a primitive class. For example this method converts
.class to Double.
.
Parameters: c - The wrapper class. The primitive class. throws: IllegalArgumentException - if the specified class is not a wrapper for a primitive. |
toString | public String toString()(Code) | | Returns a string representation for this class changer.
|
|
|