org.geotools.util
Class Converters

Object
  extended by Converters

public final class Converters
extends Object

Convenience class for converting an object from one type to an object of another.

Since:
2.4
Author:
Justin Deoliveira, The Open Planning Project
Module:
modules/library/main (gt-main.jar)

Constructor Summary
Converters()
           
 
Method Summary
static
<T> T
convert(Object source, Class<T> target)
          Convenience for convert(Object, Class, Hints)
static
<T> T
convert(Object source, Class<T> target, Hints hints)
          Converts an object of a particular type into an object of a differnt type.
static Set<ConverterFactory> getConverterFactories(Class source, Class target)
          Returns a set of all available ConverterFactory's which can handle convert from the source to destination class.
static Set getConverterFactories(Hints hints)
          Returns a set of all available implementations for the ConverterFactory interface.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Converters

public Converters()
Method Detail

getConverterFactories

public static Set getConverterFactories(Hints hints)
Returns a set of all available implementations for the ConverterFactory interface.

Parameters:
hints - An optional map of hints, or null if none.
Returns:
Set of available ConverterFactory implementations.

getConverterFactories

public static Set<ConverterFactory> getConverterFactories(Class source,
                                                          Class target)
Returns a set of all available ConverterFactory's which can handle convert from the source to destination class.

This method essentially returns all factories in which the following returns non null.

 factory.createConverter( source, target );
 

Since:
2.5

convert

public static <T> T convert(Object source,
                            Class<T> target)
Convenience for convert(Object, Class, Hints)

Parameters:
source - The object to convert.
target - The type of the converted value.
Returns:
The converted value as an instance of target, or null if a converter could not be found
Since:
2.4

convert

public static <T> T convert(Object source,
                            Class<T> target,
                            Hints hints)
Converts an object of a particular type into an object of a differnt type.

This method uses the ConverterFactory extension point to find a converter capable of performing the conversion. The first converter found is the one used. Using this class there is no way to guarantee which converter will be used.

Parameters:
source - The object to convert.
target - The type of the converted value.
hints - Any hints for the converter factory.
Returns:
The converted value as an instance of target, or null if a converter could not be found.
Since:
2.4


Copyright © 1996-2009 Geotools. All Rights Reserved.