Class Conversions
- java.lang.Object
-
- org.apache.jackrabbit.oak.plugins.value.Conversions
-
public final class Conversions extends Object
Utility class defining the conversion that take place betweenPropertyState
s of different types. All conversions defined in this class are compatible with the conversions specified in JSR-283 $3.6.4. However, some conversion in this class might not be defined in JSR-283.Example:
double three = convert("3.0").toDouble();
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Conversions.Converter
A converter converts a value to its representation as a specific target type.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Conversions.Converter
convert(boolean value)
Create a converter for a boolean.static Conversions.Converter
convert(double value)
Create a converter for a double.static Conversions.Converter
convert(long value)
Create a converter for a long.static Conversions.Converter
convert(String value)
Create a converter for a string.static Conversions.Converter
convert(String value, Type<?> type)
Create a converter for a date.static Conversions.Converter
convert(BigDecimal value)
Create a converter for a decimal.static Conversions.Converter
convert(Blob value)
Create a converter for a binary.
-
-
-
Method Detail
-
convert
public static Conversions.Converter convert(String value)
Create a converter for a string.- Parameters:
value
- The string to convert- Returns:
- A converter for
value
- Throws:
NumberFormatException
-
convert
public static Conversions.Converter convert(Blob value)
Create a converter for a binary. For the conversion toString
the binary in interpreted as UTF-8 encoded string.- Parameters:
value
- The binary to convert- Returns:
- A converter for
value
- Throws:
IllegalArgumentException
- if the binary is inaccessible
-
convert
public static Conversions.Converter convert(long value)
Create a converter for a long.String.valueOf(long)
is used for the conversion toString
. The conversions todouble
andlong
return thevalue
itself. The conversion to decimal usesnew BigDecimal.valueOf(long)
. The conversion to date interprets the value as number of milliseconds since1970-01-01T00:00:00.000Z
.- Parameters:
value
- The long to convert- Returns:
- A converter for
value
-
convert
public static Conversions.Converter convert(double value)
Create a converter for a double.String.valueOf(double)
is used for the conversion toString
. The conversions todouble
andlong
return thevalue
itself where in the former case the value is casted tolong
. The conversion to decimal usesBigDecimal.valueOf(double)
. The conversion to date interpretstoLong()
as number of milliseconds since1970-01-01T00:00:00.000Z
.- Parameters:
value
- The double to convert- Returns:
- A converter for
value
-
convert
public static Conversions.Converter convert(String value, Type<?> type)
Create a converter for a date.ISO8601.format(Calendar)
is used for the conversion toString
. The conversions todouble
,long
andBigDecimal
return the number of milliseconds since1970-01-01T00:00:00.000Z
.- Parameters:
value
- The date to convert- Returns:
- A converter for
value
-
convert
public static Conversions.Converter convert(boolean value)
Create a converter for a boolean.Boolean.toString(boolean)
is used for the conversion toString
.- Parameters:
value
- The boolean to convert- Returns:
- A converter for
value
-
convert
public static Conversions.Converter convert(BigDecimal value)
Create a converter for a decimal.BigDecimal.toString()
is used for the conversion toString
.BigDecimal.longValue()
andBigDecimal.doubleValue()
is used for the conversions tolong
anddouble
, respectively. The conversion to date interpretstoLong()
as number of milliseconds since1970-01-01T00:00:00.000Z
.- Parameters:
value
- The decimal to convert- Returns:
- A converter for
value
-
-