Package org.geotoolkit.util.converter

Performs conversions between instances of different classes.

See:
          Description

Interface Summary
ClassFilter A filter to be given as parameter to methods that apply filtering on Class instances.
ObjectConverter<S,T> Performs conversions from instances of a source class to instances of a target class.
 

Class Summary
AnyConverter An utility for converting arbitrary objects to arbitrary target types without the need to handle ObjectConverter and ConverterRegistry explicitly.
BaseClassFilter A Class Filter implementation accepting only classes that are assignable to a given base class.
Classes Miscellaneous static methods working on Class objects.
ConverterRegistry A collection of Object Converters.
Numbers Miscellaneous static methods working on Number objects, and a few primitive types by extension.
SimpleConverter<S,T> An abstract class for simple Object Converters.
 

Exception Summary
NonconvertibleObjectException Thrown when an object can not be converted from the source type the target type.
 

Package org.geotoolkit.util.converter Description

Performs conversions between instances of different classes. For example it is sometime convenient to consider Date objects as if they were Long objects for computational purpose in generic algorithms. This particular conversion is straightforward when the type are known at compile-time, but more tedious when they must be determined dynamically at run-time. This package allow that in a two-steps process:

A system-wide set of conversions is pre-defined and available by the ConverterRegistry.system() method.


Example
The following code convert instances in a collection from type S to type T, where the types are unknown at compile-time. Note that the converter is obtained only once before to be applied to every elements in the loop.

Class<S> sourceType = ...
Class<T> targetType = ...
Collection<S> sources = ...;
Collection<T> targets = ...;
ObjectConverter<S,T> converter = ConverterRegistry.system().converter(sourceType, targetType);
for (S source : sources) {
    targets.add(converter.convert(source));
}

Since:
2.5
Version:
3.17
Author:
Martin Desruisseaux (Geomatys), Justin Deoliveira (TOPP)
Module:
utility/geotk-utility (download)


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.