Class Convert


  • public final class Convert
    extends java.lang.Object
    Provides utility methods to handle type conversions
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Convert.Lazy
      Lazy holder for creating a single instance of Gson on demand.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean toBoolean​(java.lang.Object source)
      Find the boolean value of the source
      static java.lang.String toHexString​(byte[] source)
      Converts the given array of bytes into hexadecimal string.
      static int toInt​(java.lang.Object source)
      Converts the given object into a primitive integer value.
      static int toInt​(java.lang.Object source, int defaultValue)
      Converts the given object into a primitive integer value.
      static java.lang.String toJsonString​(java.lang.Object source)
      Converts the given object into a JSON formatted string.
      static <T> java.util.List<T> toList​(java.util.Set<T> source)
      Converts a set of objects into a list of objects.
      static long toLong​(java.lang.Object source)
      Converts the given object into a primitive long value.
      static long toLong​(java.lang.Object source, long defaultValue)
      Converts the given object into a primitive long value.
      static java.lang.Long[] toLongArray​(long[] source)
      Converts the give array of primitive long values into an array of Long values.
      static java.lang.Long[] toLongArray​(java.util.Collection<? extends java.lang.Number> source)
      Converts the give collection of Number objects into an array of Long objects.
      static long[] toPrimitiveLongArray​(java.util.Collection<? extends java.lang.Number> collection)
      Converts the give collection of Number objects into an array of primitive long values.
      static <T> java.util.Set<T> toSet​(java.util.Collection<T> source)
      Converts the given Collection of objects into a Set of objects.
      static <T> java.util.Set<T> toSet​(T[] source)
      Converts the given primitive array of objects into a Set of objects.
      static java.lang.String toString​(java.lang.Object source)
      Converts the given object into a String object.
      static java.lang.String toString​(java.lang.Object source, java.lang.String defaultValue)
      Converts the given object into a String object.
      static java.net.URI toURI​(java.lang.Object source)
      Converts the give object to an URI object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • toString

        @Nullable
        public static java.lang.String toString​(@Nullable
                                                java.lang.Object source,
                                                @Nullable
                                                java.lang.String defaultValue)
        Converts the given object into a String object.
        Parameters:
        source - the object to be converted.
        defaultValue - the value that should be returned if the object cannot be converted.
        Returns:
        the converted string.
      • toString

        @NonNull
        public static java.lang.String toString​(@Nullable
                                                java.lang.Object source)
        Converts the given object into a String object.
        Parameters:
        source - the object to be converted.
        Returns:
        the converted string.
      • toBoolean

        public static boolean toBoolean​(@Nullable
                                        java.lang.Object source)
        Find the boolean value of the source
        Parameters:
        source - the object to be compared.
        Returns:
        true or false
      • toLong

        public static long toLong​(@Nullable
                                  java.lang.Object source,
                                  long defaultValue)
        Converts the given object into a primitive long value.
        Parameters:
        source - the object to be converted.
        defaultValue - the value that should be returned if the object cannot be converted.
        Returns:
        the converted value.
      • toLong

        public static long toLong​(@Nullable
                                  java.lang.Object source)
        Converts the given object into a primitive long value.
        Parameters:
        source - the object to be converted.
        Returns:
        the converted value.
      • toInt

        public static int toInt​(@Nullable
                                java.lang.Object source,
                                int defaultValue)
        Converts the given object into a primitive integer value.
        Parameters:
        source - the object to be converted.
        defaultValue - the value that should be returned if the object cannot be converted.
        Returns:
        the converted value.
      • toInt

        public static int toInt​(@Nullable
                                java.lang.Object source)
        Converts the given object into a primitive integer value.
        Parameters:
        source - the object to be converted.
        Returns:
        the converted value.
      • toSet

        @NonNull
        public static <T> java.util.Set<T> toSet​(@Nullable
                                                 T[] source)
        Converts the given primitive array of objects into a Set of objects.
        Type Parameters:
        T - the type of the object.
        Parameters:
        source - the array of objects to be converted.
        Returns:
        reference to a Set containing the objects.
      • toList

        @NonNull
        public static <T> java.util.List<T> toList​(@Nullable
                                                   java.util.Set<T> source)
        Converts a set of objects into a list of objects.
        Type Parameters:
        T -
        Parameters:
        source - the set of objects to be converted.
        Returns:
        the list of objects.
      • toSet

        @NonNull
        public static <T> java.util.Set<T> toSet​(@Nullable
                                                 java.util.Collection<T> source)
        Converts the given Collection of objects into a Set of objects.
        Type Parameters:
        T - the type of the object.
        Parameters:
        source - the list of objects to be converted.
        Returns:
        reference to a Set containing the objects.
      • toPrimitiveLongArray

        @NonNull
        public static long[] toPrimitiveLongArray​(@Nullable
                                                  java.util.Collection<? extends java.lang.Number> collection)
        Converts the give collection of Number objects into an array of primitive long values.
        Parameters:
        collection - a collection of Number objects
        Returns:
        an array of primitive long values.
      • toLongArray

        @NonNull
        public static java.lang.Long[] toLongArray​(@Nullable
                                                   java.util.Collection<? extends java.lang.Number> source)
        Converts the give collection of Number objects into an array of Long objects.
        Parameters:
        source - a collection of Number objects
        Returns:
        an array of Long objects.
      • toLongArray

        @NonNull
        public static java.lang.Long[] toLongArray​(@Nullable
                                                   long[] source)
        Converts the give array of primitive long values into an array of Long values.
        Parameters:
        source - an array of primitive long values.
        Returns:
        an array of Long objects.
      • toURI

        @Nullable
        public static java.net.URI toURI​(@Nullable
                                         java.lang.Object source)
        Converts the give object to an URI object.
        Parameters:
        source - the object to be converted.
        Returns:
        null if the source is null, otherwise the URI.
      • toHexString

        @NonNull
        public static java.lang.String toHexString​(@Nullable
                                                   byte[] source)
        Converts the given array of bytes into hexadecimal string.
        Parameters:
        source - an array of bytes.
        Returns:
        the converted hexadecimal string.
      • toJsonString

        @NonNull
        public static java.lang.String toJsonString​(@Nullable
                                                    java.lang.Object source)
        Converts the given object into a JSON formatted string.
        Parameters:
        source - the object to be converted.
        Returns:
        the converted value.