org.scijava.convert
Class DefaultConverter

java.lang.Object
  extended by org.scijava.AbstractContextual
      extended by org.scijava.plugin.AbstractRichPlugin
          extended by org.scijava.plugin.AbstractTypedPlugin<D>
              extended by org.scijava.plugin.AbstractHandlerPlugin<ConversionRequest>
                  extended by org.scijava.convert.AbstractConverter<Object,Object>
                      extended by org.scijava.convert.DefaultConverter
All Implemented Interfaces:
Comparable<Prioritized>, Contextual, Converter<Object,Object>, HandlerPlugin<ConversionRequest>, HasPluginInfo, RichPlugin, SciJavaPlugin, SingletonPlugin, TypedPlugin<ConversionRequest>, Prioritized, Typed<ConversionRequest>

public class DefaultConverter
extends AbstractConverter<Object,Object>

Default Converter implementation. Provides useful conversion functionality for many common conversion cases.

Author:
Mark Hiner

Constructor Summary
DefaultConverter()
           
 
Method Summary
 boolean canConvert(Class<?> src, Class<?> dest)
          Deprecated. 
 boolean canConvert(Class<?> src, Type dest)
          Deprecated. 
<T> T
convert(Object src, Class<T> dest)
          Converts the given object to an object of the specified type.
 Object convert(Object src, Type dest)
          As Converter.convert(Object, Class) but capable of creating and populating multi-element objects (Collections and array types).
 Class<Object> getInputType()
           
 Class<Object> getOutputType()
           
 
Methods inherited from class org.scijava.convert.AbstractConverter
canConvert, canConvert, canConvert, convert, getType, populateInputCandidates, supports
 
Methods inherited from class org.scijava.plugin.AbstractRichPlugin
compareTo, getInfo, getPriority, setInfo, setPriority, toString
 
Methods inherited from class org.scijava.AbstractContextual
context, getContext, setContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.scijava.Contextual
context, getContext, setContext
 
Methods inherited from interface org.scijava.Prioritized
getPriority, setPriority
 
Methods inherited from interface java.lang.Comparable
compareTo
 
Methods inherited from interface org.scijava.plugin.HasPluginInfo
getInfo, setInfo
 

Constructor Detail

DefaultConverter

public DefaultConverter()
Method Detail

convert

public Object convert(Object src,
                      Type dest)
Description copied from interface: Converter
As Converter.convert(Object, Class) but capable of creating and populating multi-element objects (Collections and array types). If a single element type is provided, it will be converted the same as Converter.convert(Object, Class). If a multi-element type is detected, then the value parameter will be interpreted as potential collection of values. An appropriate container will be created, and the full set of values will be type converted and added.

NB: This method should be capable of creating any array type, but if a Collection interface or abstract class is provided we can only make a best guess as to what container type to instantiate. Defaults are provided for Set and List subclasses.

Specified by:
convert in interface Converter<Object,Object>
Overrides:
convert in class AbstractConverter<Object,Object>
Parameters:
src - The object to convert.
dest - Type to which the object should be converted.

convert

public <T> T convert(Object src,
                     Class<T> dest)
Description copied from interface: Converter
Converts the given object to an object of the specified type. The object is casted directly if possible, or else a new object is created using the destination type's public constructor that takes the original object as input (except when converting to String, which uses the Object.toString() method instead). In the case of primitive types, returns an object of the corresponding wrapped type. If the destination type does not have an appropriate constructor, returns null.

Type Parameters:
T - Type to which the object should be converted.
Parameters:
src - The object to convert.
dest - Type to which the object should be converted.

getOutputType

public Class<Object> getOutputType()
Returns:
The base Class this Converter produces as output.

getInputType

public Class<Object> getInputType()
Returns:
The base Class this Converter accepts as input.

canConvert

@Deprecated
public boolean canConvert(Class<?> src,
                                     Type dest)
Deprecated. 

Description copied from interface: Converter
Checks whether objects of the given class can be converted to the specified type.

Specified by:
canConvert in interface Converter<Object,Object>
Overrides:
canConvert in class AbstractConverter<Object,Object>
See Also:
Converter.convert(Object, Type)

canConvert

@Deprecated
public boolean canConvert(Class<?> src,
                                     Class<?> dest)
Deprecated. 

Description copied from interface: Converter
Checks whether objects of the given class can be converted to the specified type.

See Also:
Converter.convert(Object, Class)


Copyright © 2009–2014 SciJava. All rights reserved.