All Downloads are FREE. Search and download functionalities are using the official Maven repository.

public.javadoc.org.spincast.core.utils.ObjectConverter.html Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version






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 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.
      • convertToString

        String convertToString(Object element)
        Converts the element to a JsonObject.
      • 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.
      • 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.
      • 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.





© 2015 - 2024 Weber Informatics LLC | Privacy Policy