bpiwowar.argparser
Class GenericHelper

java.lang.Object
  extended by bpiwowar.argparser.GenericHelper

public class GenericHelper
extends Object

Helper methods for generics

Author:
bpiwowar

Constructor Summary
GenericHelper()
           
 
Method Summary
static boolean checkGenerics(Class<?> candidate, Type gtype, Class... classes)
          Check if the generic types of an implemented superclass/interface match
static Type[] getActualTypeArguments(Class<?> candidate, Class<?> implemented)
          Reflection helper - give the generic parameters of a class.
static
<T,U extends T>
U[]
newArray(Class<T> theClass, int length)
           
static
<T> ArrayList<T>
newArrayList()
           
static
<T> ArrayList<T>
newArrayList(int length)
           
static
<K,V> HashMap<K,V>
newHashMap()
           
static
<T> HashSet<T>
newHashSet()
           
static
<K,V> TreeMap<K,V>
newTreeMap()
           
static
<T> TreeSet<T>
newTreeSet()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericHelper

public GenericHelper()
Method Detail

newArrayList

public static final <T> ArrayList<T> newArrayList()

newTreeMap

public static final <K,V> TreeMap<K,V> newTreeMap()

newHashMap

public static final <K,V> HashMap<K,V> newHashMap()

newHashSet

public static final <T> HashSet<T> newHashSet()

checkGenerics

public static boolean checkGenerics(Class<?> candidate,
                                    Type gtype,
                                    Class... classes)
Check if the generic types of an implemented superclass/interface match

 GenericHelper.checkGenerics(Collection.class, gtype, String.class);
 

Parameters:
candidate -
gtype -
classes -
Returns:

getActualTypeArguments

public static Type[] getActualTypeArguments(Class<?> candidate,
                                            Class<?> implemented)
Reflection helper - give the generic parameters of a class.

Parameters:
candidate - The class implementing the superclass or superinterface
implemented -
Returns:
a type array of the type arguments of a superclass or a superinterface

newTreeSet

public static <T> TreeSet<T> newTreeSet()

newArrayList

public static <T> ArrayList<T> newArrayList(int length)

newArray

public static final <T,U extends T> U[] newArray(Class<T> theClass,
                                                 int length)


Copyright © 2013. All Rights Reserved.