gate.util
Class Tools

java.lang.Object
  extended by gate.util.Tools

public class Tools
extends Object


Field Summary
private static boolean DEBUG
          Debug flag
(package private) static long sym
           
private static boolean unicodeEnabled
          Does Gate know about Unicode?
 
Constructor Summary
Tools()
           
 
Method Summary
static List findSubclasses(Class parentClass)
          Finds all subclasses of a given class or interface.
static Long gensym()
          Returns a Long wich is unique during the current run.
static Long genTime()
           
static Constructor getMostSpecificConstructor(Class targetClass, Class paramClass)
          Find the constructor to use to create an instance of targetClass from one of paramClass.
static boolean isUnicodeEnabled()
          Checks wheter Gate is Unicode enabled
static void printStackTrace(PrintStream pStream)
          Prints the stack trace of the current thread to the specified print stream.
static void setUnicodeEnabled(boolean value)
          Specifies whether Gate should or shouldn't know about Unicode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
Debug flag

See Also:
Constant Field Values

sym

static long sym

unicodeEnabled

private static boolean unicodeEnabled
Does Gate know about Unicode?

Constructor Detail

Tools

public Tools()
Method Detail

gensym

public static Long gensym()
Returns a Long wich is unique during the current run. Maybe we should use serializaton in order to save the state on System.exit...


genTime

public static Long genTime()

setUnicodeEnabled

public static void setUnicodeEnabled(boolean value)
Specifies whether Gate should or shouldn't know about Unicode


isUnicodeEnabled

public static boolean isUnicodeEnabled()
Checks wheter Gate is Unicode enabled


findSubclasses

public static List findSubclasses(Class parentClass)
Finds all subclasses of a given class or interface. It will only search within the loaded packages and not the entire classpath.

Parameters:
parentClass - the class for which subclasses are sought
Returns:
a list of Class objects.

getMostSpecificConstructor

public static Constructor getMostSpecificConstructor(Class targetClass,
                                                     Class paramClass)
                                              throws NoSuchMethodException

Find the constructor to use to create an instance of targetClass from one of paramClass. We use the same rules as Java in finding the constructor to call, i.e. we find the constructor that javac would call for the expression parameterValue = new PropertyType(parameterValue):

  1. find all the single-argument constructors for propertyType whose argument type T1 is assignable from paramType
  2. from these, choose the one whose argument type T2 is more specific than the argument type S of every other one i.e. for all S, S.isAssignableFrom(T2)

If there is no applicable single argument constructor that is more specific than all the others, then the above expression would be a compile error (constructor ParamType(X) is ambiguous).

(The "most specific" check is to catch situations such as paramClass implements SortedSet, targetClass = TreeSet. Here both TreeSet(SortedSet) and TreeSet(Collection) are applicable but the former is more specific. However, if paramType also implements Comparator then there are three applicable constructors, taking SortedSet, Collection and Comparator respectively and none of these types is assignable to both the others. This is ambiguous according to the Java Language Specification, 2nd edition, section 15.12.2)

Parameters:
targetClass - the class we wish to construct
paramClass - the type of the object to pass as a parameter to the constructor.
Returns:
the most specific constructor of targetClass that is applicable to an argument of paramClass
Throws:
NoSuchMethodException - if there are no applicable constructors, or if there is no single most-specific one.

printStackTrace

public static final void printStackTrace(PrintStream pStream)
Prints the stack trace of the current thread to the specified print stream.

Parameters:
pStream -