public.javadoc.org.spincast.core.utils.ObjectConverter.html Maven / Gradle / Ivy
Show all versions of spincast-website Show documentation
ObjectConverter (org.spincast:spincast-framework 1.0.0 API)
org.spincast.core.utils
Interface ObjectConverter
-
- All Known Implementing Classes:
- ObjectConverterDefault
public interface ObjectConverter
Methods to convert an object from a type to another, when
possible. Some methods also allow to compare two
elements.
-
-
Method Summary
All Methods Instance Methods Abstract Methods
Modifier and Type
Method and Description
int
compareTo(Object elementToCompare,
Object compareTo)
Compare two elements.
byte[]
convertBase64StringToByteArray(Object element)
Converts the element to a BigDecimal
.
String
convertByteArrayToBase64String(byte[] byteArray)
Converts the element to a Base64 String
.
<T> T
convertTo(Object element,
Class<T> targetType)
Tries to convert the element to the specified targetType
.
BigDecimal
convertToBigDecimal(Object element)
Converts the element to a BigDecimal
.
Boolean
convertToBoolean(Object element)
Converts the element to a JsonArray
.
Date
convertToDateFromJsonDateFormat(Object element)
Converts the element to a Date
.
Double
convertToDouble(Object element)
Converts the element to a Double
.
Float
convertToFloat(Object element)
Converts the element to a Float
.
Instant
convertToInstantFromJsonDateFormat(Object element)
Converts the element to a Instant
.
Integer
convertToInteger(Object element)
Converts the element to a Integer
.
JsonArray
convertToJsonArray(Object element)
Converts the element to a JsonArray
.
String
convertToJsonDateFormat(Date date)
Converts the date to a String representaiton compatible with
the Json specification.
JsonObject
convertToJsonObject(Object element)
Converts the element to a JsonObject
.
Long
convertToLong(Object element)
Converts the element to a Long
.
String
convertToString(Object element)
Converts the element to a JsonObject
.
boolean
isAtLeastOneEquivalentElementInCommon(Collection<?> col1,
Collection<?> col2)
Do the two Collections have at least one equivalent element
in common?
boolean
isBase64StringOrNull(Object element)
Returns true
if the element is a valid base 64 String,
or is null
.
boolean
isCanBeConvertedTo(Class<?> referenceType,
Object element)
Can the element be converted to the specified
referenceType
?
boolean
isCanBeConvertedToBigDecimal(Object element)
Can the element be converted to a
BigDecimal
?
boolean
isCanBeConvertedToBoolean(Object element)
Can the element be converted to a
Boolean
?
boolean
isCanBeConvertedToByteArray(Object element)
Can the element be converted to a
byte[]
?
boolean
isCanBeConvertedToDateFromJsonDateFormat(Object element)
Can the element be converted to a
Date
? The source element must follow
the Json date format.
boolean
isCanBeConvertedToDouble(Object element)
Can the element be converted to a
Double
?
boolean
isCanBeConvertedToFloat(Object element)
Can the element be converted to a
Float
?
boolean
isCanBeConvertedToInteger(Object element)
Can the element be converted to a
Integer
?
boolean
isCanBeConvertedToJsonArray(Object element)
Can the element be converted to a
JsonArray
?
boolean
isCanBeConvertedToJsonObject(Object element)
Can the element be converted to a
JsonObject
?
boolean
isCanBeConvertedToLong(Object element)
Can the element be converted to a
Long
?
boolean
isCanBeConvertedToString(Object element)
Can the element be converted to a
String
?
boolean
isEquivalent(Object elementToCompare,
Object compareTo)
Are the two elements equivalent?
-
-
Method Detail
-
isCanBeConvertedTo
boolean isCanBeConvertedTo(Class<?> referenceType,
Object element)
Can the element be converted to the specified
referenceType
?
-
isCanBeConvertedToString
boolean isCanBeConvertedToString(Object element)
Can the element be converted to a
String
?
-
isCanBeConvertedToInteger
boolean isCanBeConvertedToInteger(Object element)
Can the element be converted to a
Integer
?
-
isCanBeConvertedToLong
boolean isCanBeConvertedToLong(Object element)
Can the element be converted to a
Long
?
-
isCanBeConvertedToFloat
boolean isCanBeConvertedToFloat(Object element)
Can the element be converted to a
Float
?
-
isCanBeConvertedToDouble
boolean isCanBeConvertedToDouble(Object element)
Can the element be converted to a
Double
?
-
isCanBeConvertedToBoolean
boolean isCanBeConvertedToBoolean(Object element)
Can the element be converted to a
Boolean
?
-
isCanBeConvertedToBigDecimal
boolean isCanBeConvertedToBigDecimal(Object element)
Can the element be converted to a
BigDecimal
?
-
isCanBeConvertedToByteArray
boolean isCanBeConvertedToByteArray(Object element)
Can the element be converted to a
byte[]
?
-
isCanBeConvertedToDateFromJsonDateFormat
boolean isCanBeConvertedToDateFromJsonDateFormat(Object element)
Can the element be converted to a
Date
? The source element must follow
the Json date format.
-
isCanBeConvertedToJsonObject
boolean isCanBeConvertedToJsonObject(Object element)
Can the element be converted to a
JsonObject
?
-
isCanBeConvertedToJsonArray
boolean isCanBeConvertedToJsonArray(Object element)
Can the element be converted to a
JsonArray
?
-
isBase64StringOrNull
boolean isBase64StringOrNull(Object element)
Returns true
if the element is a valid base 64 String,
or is null
.
-
convertToJsonObject
JsonObject convertToJsonObject(Object element)
throws CantConvertException
Converts the element to a JsonObject
.
- Throws:
CantConvertException
- if the element can't be converted to
the required type.
-
convertToJsonArray
JsonArray convertToJsonArray(Object element)
throws CantConvertException
Converts the element to a JsonArray
.
- Throws:
CantConvertException
- if the element can't be converted to
the required type.
-
convertToInteger
Integer convertToInteger(Object element)
throws CantConvertException
Converts the element to a Integer
.
The toString()
method will be called on the object
before trying to convert it to an Integer. If the resulting
String contains zeros only decimals, those will be
removed and the conversion will work.
For example : "123.0" will work.
- Throws:
CantConvertException
- if the element can't be converted to
the required type.
-
convertToLong
Long convertToLong(Object element)
throws CantConvertException
Converts the element to a Long
.
The toString()
method will be called on the object
before trying to convert it to a Long. If the resulting
String contains zeros only decimals, those will be
removed and the conversion will work.
For example : "123.0" will work.
- Throws:
CantConvertException
- if the element can't be converted to
the required type.
-
convertToFloat
Float convertToFloat(Object element)
throws CantConvertException
Converts the element to a Float
.
- Throws:
CantConvertException
- if the element can't be converted to
the required type.
-
convertToDouble
Double convertToDouble(Object element)
throws CantConvertException
Converts the element to a Double
.
- Throws:
CantConvertException
- if the element can't be converted to
the required type.
-
convertToBoolean
Boolean convertToBoolean(Object element)
throws CantConvertException
Converts the element to a JsonArray
.
Il can be converted to a Boolean
if its already a Boolean,
if it's null
or if it's the String "true" or the String
"false".
- Throws:
CantConvertException
- if the element can't be converted to
the required type.
-
convertToBigDecimal
BigDecimal convertToBigDecimal(Object element)
throws CantConvertException
Converts the element to a BigDecimal
.
- Throws:
CantConvertException
- if the element can't be converted to
the required type.
-
convertBase64StringToByteArray
byte[] convertBase64StringToByteArray(Object element)
throws CantConvertException
Converts the element to a BigDecimal
.
Can be converted to a byte[]
if its already a byte[]
,
if it's null
or if it's a valid base 64 String
.
- Throws:
CantConvertException
- if the element can't be converted to
the required type.
-
convertByteArrayToBase64String
String convertByteArrayToBase64String(byte[] byteArray)
Converts the element to a Base64 String
.
-
convertToDateFromJsonDateFormat
Date convertToDateFromJsonDateFormat(Object element)
throws CantConvertException
Converts the element to a Date
.
The source element must follow the Json date format (ISO 8601).
- Throws:
CantConvertException
- if the element can't be converted to
the required type.
-
convertToInstantFromJsonDateFormat
Instant convertToInstantFromJsonDateFormat(Object element)
throws CantConvertException
Converts the element to a Instant
.
The source element must follow the Json date format (ISO 8601).
- Throws:
CantConvertException
- if the element can't be converted to
the required type.
-
convertTo
<T> T convertTo(Object element,
Class<T> targetType)
throws CantConvertException
Tries to convert the element to the specified targetType
.
By default, only the types native to JsonObject are supported as
the target types.
- Throws:
CantConvertException
- if the element can't be converted to
the required type.
-
convertToJsonDateFormat
String convertToJsonDateFormat(Date date)
Converts the date to a String representaiton compatible with
the Json specification.
-
compareTo
int compareTo(Object elementToCompare,
Object compareTo)
throws CantCompareException
Compare two elements.
If required, try to convert the elementToCompare
so it
can be compared with compareTo
. It is also possible
that we have to convert compareTo
, for the comparison
to be possible. For example, if compareTo
is Long(10) and
elementToCompare
is BigDecimal(12.34), we have to convert
both elements to BigDecimal so they can be compared.
For a comparison to work, the two elements must be (after conversion
or not) of the same type and this type must implement
Comparable
.
- Throws:
CantCompareException
- if the elements can't be compared together.
-
isEquivalent
boolean isEquivalent(Object elementToCompare,
Object compareTo)
Are the two elements equivalent?
If required, try to convert the elementToCompare
so it
can be compared with compareTo
. It is also possible
that we have to convert compareTo
, for the comparison
to be possible. For example, if compareTo
is Long(10) and
elementToCompare
is BigDecimal(12.34), we have to convert
both elements to BigDecimal so they can be compared.
For the two elements to be equivalent, they must be (after conversion
or not) of the same type and then the Object.equals(Object)
method must return true
.
-
isAtLeastOneEquivalentElementInCommon
boolean isAtLeastOneEquivalentElementInCommon(Collection<?> col1,
Collection<?> col2)
Do the two Collections have at least one equivalent element
in common?
- See Also:
#isEquivalent(Object, Object)}
Copyright © 2019. All rights reserved.