Class TypeConverter


  • public final class TypeConverter
    extends java.lang.Object
    Helper to convert DBus types and java types.
    Since:
    v3.0.1 - 2018-12-22
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.Map<java.lang.String,​java.lang.String> CLASS_MAP  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private TypeConverter()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.String convertJavaBoxedTypeToPrimitive​(java.lang.String _clazzName)
      Converts certain boxed types to primitives.
      static java.lang.String convertJavaType​(java.lang.String _fqcn, boolean _usePrimitives)
      Transform certain java types to other java types (see CLASS_MAP).
      static java.lang.String getJavaTypeFromDBusType​(java.lang.String _dbusType, java.util.Set<java.lang.String> _javaIncludes)
      Converts a DBus data type string to java classname(s).
      static java.lang.String getProperJavaClass​(java.lang.String _argType, java.util.Set<java.lang.String> _includes)
      Converts a java class type to another type.
      private static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getTypeAdv​(java.lang.reflect.Type _type)
      Resolve java type recursively.
      private static java.lang.String getTypeAdv​(java.lang.String _dbusType, java.util.Set<java.lang.String> _javaIncludes)
      Special handling for DBusMapType and DBusListType.
      • Methods inherited from class java.lang.Object

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

      • CLASS_MAP

        private static final java.util.Map<java.lang.String,​java.lang.String> CLASS_MAP
    • Constructor Detail

      • TypeConverter

        private TypeConverter()
    • Method Detail

      • getProperJavaClass

        public static java.lang.String getProperJavaClass​(java.lang.String _argType,
                                                          java.util.Set<java.lang.String> _includes)
        Converts a java class type to another type. This is used for converting e.g. CharSequence to String etc. It will also remove unnecessary package names like java.lang.
        Parameters:
        _argType - Argument to convert
        _includes - Set where additional includes will be added (should never be null!)
        Returns:
        String with proper type, if no converation could be done, original input is returned
      • convertJavaType

        public static java.lang.String convertJavaType​(java.lang.String _fqcn,
                                                       boolean _usePrimitives)
        Transform certain java types to other java types (see CLASS_MAP).
        Parameters:
        _fqcn - fully qualified classname of the type to convert
        _usePrimitives - if true, boxed types will be converted to primitives
        Returns:
        converted type or original input
      • convertJavaBoxedTypeToPrimitive

        private static java.lang.String convertJavaBoxedTypeToPrimitive​(java.lang.String _clazzName)
        Converts certain boxed types to primitives.
        Parameters:
        _clazzName - class name of boxed type
        Returns:
        primitive or original input
      • getJavaTypeFromDBusType

        public static java.lang.String getJavaTypeFromDBusType​(java.lang.String _dbusType,
                                                               java.util.Set<java.lang.String> _javaIncludes)
                                                        throws DBusException
        Converts a DBus data type string to java classname(s).
        Parameters:
        _dbusType - DBus data type string
        _javaIncludes - List where additional imports will be added to (should not be null!)
        Returns:
        Java classname, maybe null if no suitable input was given
        Throws:
        DBusException - on DBus error
      • getTypeAdv

        private static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getTypeAdv​(java.lang.reflect.Type _type)
                                                                                                  throws DBusException
        Resolve java type recursively.
        Parameters:
        _type - Type object
        Returns:
        Map where key is parent classname (e.g. List) and value is a list of types used inside the generics
        Throws:
        DBusException - on error
      • getTypeAdv

        private static java.lang.String getTypeAdv​(java.lang.String _dbusType,
                                                   java.util.Set<java.lang.String> _javaIncludes)
                                            throws DBusException
        Special handling for DBusMapType and DBusListType.
        Parameters:
        _dbusType - DBus type string
        _javaIncludes - list where additional java imports are added to (if any)
        Returns:
        class name of the parent type, maybe null if no suitable input provided
        Throws:
        DBusException