org.scijava.convert
Class NullConverter
java.lang.Object
org.scijava.AbstractContextual
org.scijava.plugin.AbstractRichPlugin
org.scijava.plugin.AbstractTypedPlugin<D>
org.scijava.plugin.AbstractHandlerPlugin<ConversionRequest>
org.scijava.convert.AbstractConverter<Object,Object>
org.scijava.convert.NullConverter
- All Implemented Interfaces:
- Comparable<Prioritized>, Contextual, Converter<Object,Object>, HandlerPlugin<ConversionRequest>, HasPluginInfo, RichPlugin, SciJavaPlugin, SingletonPlugin, TypedPlugin<ConversionRequest>, Prioritized, Typed<ConversionRequest>
public class NullConverter
- extends AbstractConverter<Object,Object>
Converter
implementation for handling null
values. Performs
basic casting when given a null
source and returns
null
directly when given a
null destination.
By running at Priority.FIRST_PRIORITY
, other converters should
not need to worry about null
source or destination parameters.
NB: if a Class
source is queried for the canConvert(java.lang.Object, java.lang.Class>)
,
this converter will always return false (as there is no way of knowing
if the source object will be null or not).
- Author:
- Mark Hiner
NullConverter
public NullConverter()
canConvert
public boolean canConvert(Object src,
Class<?> dest)
- Description copied from interface:
Converter
- Checks whether the given object's type can be converted to the specified
type.
Note that this does not necessarily entail that
Converter.convert(Object, Class)
on that specific object will succeed. For
example: canConvert("5.1", int.class)
will return true
because a String
can in general be converted to an int
, but
calling convert("5.1", int.class)
will throw a
NumberFormatException
when the conversion is actually attempted via
the Integer.Integer(String)
constructor.
- Specified by:
canConvert
in interface Converter<Object,Object>
- Overrides:
canConvert
in class AbstractConverter<Object,Object>
- See Also:
Converter.convert(Object, Class)
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,
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.