Class GenericsUtil

java.lang.Object
org.apache.hadoop.util.GenericsUtil

@Private @Unstable public class GenericsUtil extends Object
Contains utility methods for dealing with Java Generics.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> Class<T>
    getClass(T t)
    Returns the Class object (of type Class<T>) of the argument of type T.
    static boolean
    isLog4jLogger(Class<?> clazz)
    Determine whether the log of clazz is Log4j implementation.
    static boolean
    Determine whether the log of the given logger is of Log4J implementation.
    static <T> T[]
    toArray(Class<T> c, List<T> list)
    Converts the given List<T> to a an array of T[].
    static <T> T[]
    toArray(List<T> list)
    Converts the given List<T> to a an array of T[].

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GenericsUtil

      public GenericsUtil()
  • Method Details

    • getClass

      public static <T> Class<T> getClass(T t)
      Returns the Class object (of type Class<T>) of the argument of type T.
      Type Parameters:
      T - The type of the argument
      Parameters:
      t - the object to get it class
      Returns:
      Class<T>
    • toArray

      public static <T> T[] toArray(Class<T> c, List<T> list)
      Converts the given List<T> to a an array of T[].
      Type Parameters:
      T - Generics Type T.
      Parameters:
      c - the Class object of the items in the list
      list - the list to convert
      Returns:
      T Array.
    • toArray

      public static <T> T[] toArray(List<T> list)
      Converts the given List<T> to a an array of T[].
      Type Parameters:
      T - Generics Type T.
      Parameters:
      list - the list to convert
      Returns:
      T Array.
      Throws:
      ArrayIndexOutOfBoundsException - if the list is empty. Use toArray(Class, List) if the list may be empty.
    • isLog4jLogger

      public static boolean isLog4jLogger(Class<?> clazz)
      Determine whether the log of clazz is Log4j implementation.
      Parameters:
      clazz - a class to be determined
      Returns:
      true if the log of clazz is Log4j implementation.
    • isLog4jLogger

      public static boolean isLog4jLogger(String logger)
      Determine whether the log of the given logger is of Log4J implementation.
      Parameters:
      logger - the logger name, usually class name as string.
      Returns:
      true if the logger uses Log4J implementation.