net.sf.okapi.common

## Class ClassUtil

- java.lang.Object
- - net.sf.okapi.common.ClassUtil

-     public class ClassUtil
      extends java.lang.Object

  Collection of helper functions for working with classes.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ClassUtil()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.String` | `buildClassPath(java.lang.Class<?>... classes)`
    `static java.lang.String` | `buildClassPath(java.lang.String... paths)`
    `static java.lang.String` | `extractPackageName(java.lang.String className)` Extracts the package name part of a qualified class name.
    `static java.lang.String` | `extractShortClassName(java.lang.String className)` Extracts the class name part of a qualified class name.
    `static java.lang.Class<?>` | `getClass(java.lang.Object obj)` Gets the runtime class of a given object.
    `static java.lang.Class<?>` | `getClass(java.lang.String className)` Gets the class reference for a given qualified class name.
    `static java.lang.String` | `getClassFilePath(java.lang.Class<?> cls)`
    `static java.lang.String` | `getClassName(java.lang.Class<?> classRef)` Gets the non-qualified (w/o package name prefix) class name of a given class reference.
    `static java.lang.String` | `getClassName(java.lang.Object obj)` Gets the non-qualified (without package name prefix) class name for a given object.
    `static java.lang.String` | `getPackageName(java.lang.Class<?> classRef)` Gets the package name of a given class reference.
    `static java.lang.String` | `getPackageName(java.lang.Object obj)` Gets the name of the package containing a given object's class.
    `static java.lang.String` | `getPath(java.lang.Class<?> cls)`
    `static java.lang.String` | `getQualifiedClassName(java.lang.Class<?> classRef)` Gets the qualified class name of a given class reference.
    `static java.lang.String` | `getQualifiedClassName(java.lang.Object obj)` Gets the qualified class name of a given object.
    `static java.lang.String` | `getResourceParent(java.lang.Class<?> cls, java.lang.String resourceName)` Gets the pathname parent of a given resource.
    `static java.lang.String` | `getResourcePath(java.lang.Class<?> cls, java.lang.String resourceName)` Gets a full path of a given resource.
    `static java.lang.String` | `getShortClassName(java.lang.Class<?> classRef)` Gets the non-qualified class name (w/o package name prefix) of a given class reference.
    `static java.lang.String` | `getShortClassName(java.lang.Object obj)` Gets the non-qualified class name (w/o package name prefix) of a given object.
    `static java.lang.String` | `getTargetPath(java.lang.Class<?> cls)`
    `static <T> T` | `instantiateClass(java.lang.Class<T> classRef)` Creates a new instance of a given class.
    `static <T> T` | `instantiateClass(java.lang.Class<T> classRef, java.lang.Object... constructorParameters)` Creates a new instance of the class using a given class loader and initialization parameters.
    `static java.lang.Object` | `instantiateClass(java.lang.String className)` Creates a new instance of the class with a given class name.
    `static java.lang.Object` | `instantiateClass(java.lang.String className, java.lang.ClassLoader classLoader)` Creates a new instance of the class with a given class name using a given class loader.
    `static java.lang.Object` | `instantiateClass(java.lang.String className, java.lang.ClassLoader classLoader, java.lang.Object... constructorParameters)` Creates a new instance of the class with a given class name and initialization parameters using a given class loader.
    `static java.lang.Object` | `instantiateClass(java.lang.String className, java.lang.Object... constructorParameters)` Creates a new instance of the class with a given class name and initialization parameters.
    `static boolean` | `isInJar(java.lang.Class<?> cls, java.lang.String resPath)` Detect if a given class is located in a JAR.
    `static java.lang.String` | `qualifyName(java.lang.Class<?> siblingClassRef, java.lang.String shortClassName)` Builds a qualified class name for the given class name.
    `static java.lang.String` | `qualifyName(java.lang.Object sibling, java.lang.String shortClassName)` Builds a qualified class name for the given class name.
    `static java.lang.String` | `qualifyName(java.lang.String packageName, java.lang.String shortClassName)` Builds a qualified class name from given parts.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ClassUtil

          public ClassUtil()

  - ### Method Detail

    - #### getClass

          public static java.lang.Class<?> getClass(java.lang.Object obj)

      Gets the runtime class of a given object.
      Parameters:
        `obj` - The given object
      Returns:
        The object's runtime class

    - #### getClass

          public static java.lang.Class<?> getClass(java.lang.String className)

      Gets the class reference for a given qualified class name.
      Parameters:
        `className` - The given class name
      Returns:
        Class reference

    - #### getClassName

          public static java.lang.String getClassName(java.lang.Object obj)

      Gets the non-qualified (without package name prefix) class name for a given object.
      Parameters:
        `obj` - The given object
      Returns:
        The object's class name (w/o package name prefix)

    - #### getClassName

          public static java.lang.String getClassName(java.lang.Class<?> classRef)

      Gets the non-qualified (w/o package name prefix) class name of a given class reference.
      Parameters:
        `classRef` - The given class reference
      Returns:
        The name of the class (w/o package name prefix)

    - #### getQualifiedClassName

          public static java.lang.String getQualifiedClassName(java.lang.Object obj)

      Gets the qualified class name of a given object.
      Parameters:
        `obj` - The given object
      Returns:
        Qualified class name

    - #### getQualifiedClassName

          public static java.lang.String getQualifiedClassName(java.lang.Class<?> classRef)

      Gets the qualified class name of a given class reference.
      Parameters:
        `classRef` - The given class reference
      Returns:
        Qualified class name

    - #### getShortClassName

          public static java.lang.String getShortClassName(java.lang.Class<?> classRef)

      Gets the non-qualified class name (w/o package name prefix) of a given class reference.
      Parameters:
        `classRef` - The given class reference
      Returns:
        Non-qualified class name

    - #### getShortClassName

          public static java.lang.String getShortClassName(java.lang.Object obj)

      Gets the non-qualified class name (w/o package name prefix) of a given object.
      Parameters:
        `obj` - The given object
      Returns:
        Non-qualified class name

    - #### getPackageName

          public static java.lang.String getPackageName(java.lang.Object obj)

      Gets the name of the package containing a given object's class.
      Parameters:
        `obj` - The given object
      Returns:
        Package name of the given object's class (w/o the trailing dot), or an empty string

    - #### getPackageName

          public static java.lang.String getPackageName(java.lang.Class<?> classRef)

      Gets the package name of a given class reference.
      Parameters:
        `classRef` - The given class reference
      Returns:
        Package name of the given class reference (w/o the trailing dot), or an empty string

    - #### getTargetPath

          public static java.lang.String getTargetPath(java.lang.Class<?> cls)

    - #### extractPackageName

          public static java.lang.String extractPackageName(java.lang.String className)

      Extracts the package name part of a qualified class name.
      Parameters:
        `className` - Qualified class name
      Returns:
        Package name (w/o the trailing dot)

    - #### extractShortClassName

          public static java.lang.String extractShortClassName(java.lang.String className)

      Extracts the class name part of a qualified class name.
      Parameters:
        `className` - Qualified class name
      Returns:
        Class name

    - #### qualifyName

          public static java.lang.String qualifyName(java.lang.String packageName,
                                     java.lang.String shortClassName)

      Builds a qualified class name from given parts.
      Parameters:
        `packageName` - Package name
        `shortClassName` - Class name
      Returns:
        Qualified class name

    - #### qualifyName

          public static java.lang.String qualifyName(java.lang.Class<?> siblingClassRef,
                                     java.lang.String shortClassName)

      Builds a qualified class name for the given class name. Package name is determined from a reference to another class in the same package.
      Parameters:
        `siblingClassRef` - Reference to another class in the same package
        `shortClassName` - Non-qualified name of the class to get a qualified name for
      Returns:
        Qualified class name

    - #### qualifyName

          public static java.lang.String qualifyName(java.lang.Object sibling,
                                     java.lang.String shortClassName)

      Builds a qualified class name for the given class name. Package name is determined from an instance of another class in the same package.
      Parameters:
        `sibling` - Existing object, an instance of another class in the same package
        `shortClassName` - Non-qualified name of the class to get a qualified name for
      Returns:
        Qualified class name

    - #### instantiateClass

          public static <T> T instantiateClass(java.lang.Class<T> classRef)
                                    throws java.lang.InstantiationException,
                                           java.lang.IllegalAccessException

      Creates a new instance of a given class.
      Type Parameters:
        `T` - the type of the given class
      Parameters:
        `classRef` - The given class
      Returns:
        a newly created instance of the given class
      Throws:
        `java.lang.InstantiationException` - when we fail to create an instance.
        `java.lang.IllegalAccessException` - when trying to create an instance but don't have the right.

    - #### instantiateClass

          public static java.lang.Object instantiateClass(java.lang.String className)
                                                   throws java.lang.InstantiationException,
                                                          java.lang.IllegalAccessException,
                                                          java.lang.ClassNotFoundException

      Creates a new instance of the class with a given class name.
      Parameters:
        `className` - The given class name
      Returns:
        a newly created instance of the class with the given class name
      Throws:
        `java.lang.InstantiationException` - when we fail to create an instance.
        `java.lang.IllegalAccessException` - when trying to create an instance but don't have the right.
        `java.lang.ClassNotFoundException` - when no definition for the class was found

    - #### instantiateClass

          public static java.lang.Object instantiateClass(java.lang.String className,
                                          java.lang.ClassLoader classLoader)
                                                   throws java.lang.InstantiationException,
                                                          java.lang.IllegalAccessException,
                                                          java.lang.ClassNotFoundException

      Creates a new instance of the class with a given class name using a given class loader.
      Parameters:
        `className` - The given class name
        `classLoader` - The class loader from which the class must be loaded
      Returns:
        A newly created instance of the desired class.
      Throws:
        `java.lang.InstantiationException` - when we fail to create an instance.
        `java.lang.IllegalAccessException` - when trying to create an instance but don't have the right.
        `java.lang.ClassNotFoundException` - when no definition for the class was found

    - #### instantiateClass

          public static <T> T instantiateClass(java.lang.Class<T> classRef,
                               java.lang.Object... constructorParameters)
                                    throws java.lang.SecurityException,
                                           java.lang.NoSuchMethodException,
                                           java.lang.IllegalArgumentException,
                                           java.lang.InstantiationException,
                                           java.lang.IllegalAccessException,
                                           java.lang.reflect.InvocationTargetException

      Creates a new instance of the class using a given class loader and initialization parameters.
      Type Parameters:
        `T` - the type of the class to create
      Parameters:
        `classRef` - The given class
        `constructorParameters` - The initialization parameters for the class constructor
      Returns:
        A newly created instance of the desired class
      Throws:
        `java.lang.SecurityException` - if we don't have the right to create the class
        `java.lang.NoSuchMethodException` - when a constructor cannot be found
        `java.lang.IllegalArgumentException` - if the classRef was null.
        `java.lang.InstantiationException` - when we fail to create an instance.
        `java.lang.IllegalAccessException` - when trying to create an instance but don't have the right.
        `java.lang.reflect.InvocationTargetException` - when the constructor throws an exception.

    - #### instantiateClass

          public static java.lang.Object instantiateClass(java.lang.String className,
                                          java.lang.Object... constructorParameters)
                                                   throws java.lang.SecurityException,
                                                          java.lang.NoSuchMethodException,
                                                          java.lang.IllegalArgumentException,
                                                          java.lang.InstantiationException,
                                                          java.lang.IllegalAccessException,
                                                          java.lang.reflect.InvocationTargetException,
                                                          java.lang.ClassNotFoundException

      Creates a new instance of the class with a given class name and initialization parameters.
      Parameters:
        `className` - The given class name
        `constructorParameters` - The initialization parameters for the class constructor
      Returns:
        A newly created instance of the desired class
      Throws:
        `java.lang.SecurityException` - if we don't have the right to create the class
        `java.lang.NoSuchMethodException` - when a constructor cannot be found
        `java.lang.IllegalArgumentException` - if the class name is null or empty
        `java.lang.InstantiationException` - when we fail to create an instance.
        `java.lang.IllegalAccessException` - when trying to create an instance but don't have the right.
        `java.lang.reflect.InvocationTargetException` - when the constructor throws an exception.
        `java.lang.ClassNotFoundException` - when no definition for the class was found

    - #### instantiateClass

          public static java.lang.Object instantiateClass(java.lang.String className,
                                          java.lang.ClassLoader classLoader,
                                          java.lang.Object... constructorParameters)
                                                   throws java.lang.SecurityException,
                                                          java.lang.NoSuchMethodException,
                                                          java.lang.IllegalArgumentException,
                                                          java.lang.InstantiationException,
                                                          java.lang.IllegalAccessException,
                                                          java.lang.reflect.InvocationTargetException,
                                                          java.lang.ClassNotFoundException

      Creates a new instance of the class with a given class name and initialization parameters using a given class loader.
      Parameters:
        `className` - The given class name
        `classLoader` - The given class loader
        `constructorParameters` - The initialization parameters for the class constructor
      Returns:
        A newly created instance of the desired class
      Throws:
        `java.lang.SecurityException` - if we don't have the right to create the class
        `java.lang.NoSuchMethodException` - when a constructor cannot be found
        `java.lang.IllegalArgumentException` - if the class name is null or empty, or if the classLoader is null.
        `java.lang.InstantiationException` - when we fail to create an instance.
        `java.lang.IllegalAccessException` - when trying to create an instance but don't have the right.
        `java.lang.reflect.InvocationTargetException` - when the constructor throws an exception.
        `java.lang.ClassNotFoundException` - when no definition for the class was found

    - #### getResourcePath

          public static java.lang.String getResourcePath(java.lang.Class<?> cls,
                                         java.lang.String resourceName)

      Gets a full path of a given resource.
      Parameters:
        `cls` - Class containing the given resource.
        `resourceName` - Name of the given resource. Should be prefixed with a leading slash ("/name.ext") if the resource is located in the class root. If the resource is located in the same package as the class, then no leading slash is needed ("name.ext").
      Returns:
        Full path of the given resource.

    - #### getResourceParent

          public static java.lang.String getResourceParent(java.lang.Class<?> cls,
                                           java.lang.String resourceName)

      Gets the pathname parent of a given resource.
      Parameters:
        `cls` - Class containing the given resource.
        `resourceName` - Name of the given resource. Should be prefixed with a leading slash ("/name.ext") if the resource is located in the class root. If the resource is located in the same package as the class, then no leading slash is needed ("name.ext").
      Returns:
        The given resource's pathname parent.

    - #### isInJar

          public static boolean isInJar(java.lang.Class<?> cls,
                        java.lang.String resPath)

      Detect if a given class is located in a JAR.
      Parameters:
        `cls` - the given class.
        `resPath` - resource path inside the jar
      Returns:
        true if the class is located in a JAR.

    - #### buildClassPath

          public static java.lang.String buildClassPath(java.lang.String... paths)

    - #### getPath

          public static java.lang.String getPath(java.lang.Class<?> cls)

    - #### getClassFilePath

          public static java.lang.String getClassFilePath(java.lang.Class<?> cls)

    - #### buildClassPath

          public static java.lang.String buildClassPath(java.lang.Class<?>... classes)