public class IlvValueConverter extends Object implements Serializable
IlvValueConverter
is used to convert a value from one
type to another. It is used by the classes in the
ilog.views.prototypes
package to automatically convert to the
appropriate types the values given as arguments or returned by the
set
and get
methods of the class
IlvGroupElement
and its subclasses.
Conversions are handled by a table of IlvValueFilter
objects.
Each filter handles one or several "from" types and one or several "to"
types. The conversion is actually performed by the convert
method of the filter.
A number of predefined filters are provided:
String
String
to number
float
to int
)
String
to/from Color
String
to/from Font
More filters supplied by other packages or by the application can be added.
IlvValueFilter
,
IlvGroupElement
,
Serialized FormModifier and Type | Method and Description |
---|---|
static Object |
convert(Object value,
Class<?> toType)
Converts the type of a value to a new type.
|
static boolean |
convertToBoolean(Object value)
Converts a value from its current type to a boolean value.
|
static double |
convertToDouble(Object value)
Converts a value from its current type to a double.
|
static float |
convertToFloat(Object value)
Converts a value from its current type to a float.
|
static int |
convertToInt(Object value)
Converts a value from its current type to an integer.
|
static long |
convertToLong(Object value)
Converts a value from its current type to a long integer.
|
static String |
convertToString(Object value)
Converts a value from its current type to a string.
|
static void |
registerFilter(IlvValueFilter filter)
Adds a filter to the global list of filters used to convert values.
|
public static final void registerFilter(IlvValueFilter filter)
filter
- the new value filter. The source and target types handled by the
filter are determined by the result of the methods
fromTypes
and toTypes
of the filter.public static final Object convert(Object value, Class<?> toType) throws IlvValueException
value
- the value to be converted.toType
- the type to which the value must be converted.toType
.IlvValueException
- if no filter was registered for the requested conversion or if
the value could not be converted to the requested type.IlvGroupElement
public static final String convertToString(Object value) throws IlvValueException
(String) convert(value, String.class)
value
- the value to be converted.IlvValueException
- if no filter was registered for the requested conversion or if
the value could not be converted to the requested type.convert(java.lang.Object, java.lang.Class<?>)
public static final int convertToInt(Object value) throws IlvValueException
((Integer) convert(value, Integer.class)).intValue()
value
- the value to be converted.IlvValueException
- if no filter was registered for the requested conversion or if
the value could not be converted to the requested type.convert(java.lang.Object, java.lang.Class<?>)
public static final long convertToLong(Object value) throws IlvValueException
((Long) convert(value, Long.class)).longValue()
value
- the value to be converted.IlvValueException
- if no filter was registered for the requested conversion or if
the value could not be converted to the requested type.convert(java.lang.Object, java.lang.Class<?>)
public static final boolean convertToBoolean(Object value) throws IlvValueException
((Boolean) convert(value, Boolean.class)).booleanValue()
value
- the value to convertIlvValueException
- if not filter was registered for the requested conversion or
if the value could not be converted to the requested type.convert(java.lang.Object, java.lang.Class<?>)
public static final float convertToFloat(Object value) throws IlvValueException
((Float) convert(value, Float.class)).floatValue()
value
- the value to be converted.IlvValueException
- if no filter was registered for the requested conversion or if
the value could not be converted to the requested type.convert(java.lang.Object, java.lang.Class<?>)
public static final double convertToDouble(Object value) throws IlvValueException
((Double) convert(value, Double.class)).doubleValue()
value
- the value to be converted.IlvValueException
- if no filter was registered for the requested conversion or if
the value could not be converted to the requested type.convert(java.lang.Object, java.lang.Class<?>)
© Copyright 2024 Rogue Wave Software, Inc., a Perforce company.. All Rights Reserved.