Class Util


  • public class Util
    extends Object
    A few utility methods, mostly for private use.
    Author:
    Nathan Sweet
    • Field Detail

      • isAndroid

        public static final boolean isAndroid
      • unsafe

        public static final boolean unsafe
        True if Unsafe is available. Unsafe can be disabled by setting the system property "kryo.unsafe" to "false".
    • Constructor Detail

      • Util

        public Util()
    • Method Detail

      • isUnsafeAvailable

        public static boolean isUnsafeAvailable()
      • isClassAvailable

        public static boolean isClassAvailable​(String className)
      • getWrapperClass

        public static Class getWrapperClass​(Class type)
        Returns the primitive wrapper class for a primitive class, or the specified class if it is not primitive.
      • getPrimitiveClass

        public static Class getPrimitiveClass​(Class type)
        Returns the primitive class for a primitive wrapper class. Otherwise returns the type parameter.
        Parameters:
        type - Must be a wrapper class.
      • getArrayType

        public static Class getArrayType​(Class type)
        Returns the array type for a given class
      • isWrapperClass

        public static boolean isWrapperClass​(Class type)
      • isEnum

        public static boolean isEnum​(Class type)
      • log

        public static void log​(String message,
                               Object object,
                               int position)
        Logs a message about an object. The log level and the string format of the object depend on the object type.
      • pos

        public static String pos​(int position)
      • string

        public static String string​(Object object)
        Returns the object formatted as a string. The format depends on the object's type and whether Object.toString() has been overridden.
      • className

        public static String className​(Class type)
        Returns the class formatted as a string. The format varies depending on the type.
      • classNames

        public static String classNames​(Class[] types)
        Returns the classes formatted as a string. The format varies depending on the type.
      • canonicalName

        public static String canonicalName​(Class type)
        Returns the class formatted as a string. If the class has a canonical name, the canonical name is returned, otherwise it returns the result of className(Class)
      • simpleName

        public static String simpleName​(Type type)
      • getDimensionCount

        public static int getDimensionCount​(Class arrayClass)
        Returns the number of dimensions of an array.
      • getElementClass

        public static Class getElementClass​(Class arrayClass)
        Returns the base element type of an n-dimensional array class.
      • isAssignableTo

        public static boolean isAssignableTo​(Class<?> from,
                                             Class<?> to)
      • isAscii

        public static boolean isAscii​(String value)
      • newFactory

        public static <T extends SerializerFactory> T newFactory​(Class<T> factoryClass,
                                                                 Class<? extends Serializer> serializerClass)
        Parameters:
        factoryClass - Must have a constructor that takes a serializer class, or a zero argument constructor.
        serializerClass - May be null if the factory already knows the serializer class to create.