public final class RuntimeUtility extends Object
Modifier and Type | Method and Description |
---|---|
protected static boolean |
containsDir(File aDir,
List<File>... aDirs) |
static StackTraceElement |
getCallerStackTraceElement()
Returns the stack trace element belonging to the direct caller of this
method.
|
static StackTraceElement |
getCallerStackTraceElement(Class<?>... aCallees)
Same as
getCallerStackTraceElement(Class) with the difference
that the passed callees are tried out one after the other until the first
caller determined for a callee is returned. |
static StackTraceElement |
getCallerStackTraceElement(Class<?> aCallee)
Returns the stack trace element belonging to the caller of the callee.
|
static StackTraceElement |
getCallerStackTraceElement(String... aCalleeClassNames)
Same as
getCallerStackTraceElement(String) with the difference
that the passed callees are tried out one after the other until the first
caller determined for a callee is returned. |
static StackTraceElement |
getCallerStackTraceElement(String aCalleeClassName)
Returns the stack trace element belonging to the caller of the callee.
|
static Class<?> |
getCallerType()
Returns the type of the (
Class ) belonging to the direct caller of
this method. |
static Class<?> |
getCallerType(Class<?>... aCallees)
Same as
getCallerType(Class) with the difference that the passed
callees are tried out one after the other until the first caller
determined for a callee is returned. |
static Class<?> |
getCallerType(Class<?> aCallee)
Returns the type of the (
Class ) belonging to the caller of the
callee. |
static Class |
getMainClass()
Returns the main class launching the application.
|
static Long |
getPid()
Bad hack to get the JVM's (process ID) PID of the process running your
JVM instance.
|
static boolean |
kill(Long aPid)
Bad hack to kill an OS thread by PID.
|
static Process |
killProcess(Long aPid)
Bad hack to kill an OS thread by PID.
|
static Class<?> |
toClass(StackTraceElement aStackTraceElement)
Retrieves the
Class type to which the StackTraceElement
belongs. |
static String |
toClassName()
Retrieves the class name of the caller of this method without the fully
qualified package name part.
|
static String |
toClassName(StackTraceElement aStackTraceElement)
Returns the class name part from a stack trace element.
|
static String |
toClassName(String aFullyQualifiedClassName)
Returns the class name part from a fully qualified class name (which has
the fully qualified package name as part of its name).
|
static <T> T |
toClone(T aObj)
|
static List<File> |
toConfigDirs()
The application's base directory (where your JAR or your classes reside)
is taken using the folder as retrieved by
toLauncherDir() and
passed to toConfigDirs(File...) . |
static List<File> |
toConfigDirs(File... aBaseDirectories)
Returns a list of (existing) folders which are candidates for external
resources.
|
static List<File> |
toConfigDirs(File aBaseDirectory)
The
File representing the potential base directory together with
the application's base directory where your JAR or your classes reside)
is taken (using the folder as retrieved by toLauncherDir() ) and
passed to toConfigDirs(File...) and tested for application
configuration folders. |
static String |
toFullyQualifiedClassName()
Retrieves the fully qualified method name of the caller of this method.
|
static String |
toFullyQualifiedClassName(StackTraceElement aStackTraceElement)
Retrieves the fully qualified class name from a stack trace element.
|
static String |
toFullyQualifiedMethodName()
Retrieves the fully qualified method name of the caller of this method.
|
static String |
toFullyQualifiedMethodName(StackTraceElement aStackTraceElement)
Retrieves the fully qualified method name from a stack trace element.
|
static String |
toFullyQualifiedPackageName()
Retrieves the fully qualified package name of the caller of this method
without the class name part.
|
static String |
toFullyQualifiedPackageName(StackTraceElement aStackTraceElement)
Retrieves the fully qualified package name from a stack trace element.
|
static String |
toFullyQualifiedPackageName(String aFullyQualifiedClassName)
Returns the fully qualified package name part from a fully qualified
class name (which has the fully qualified package name as part of its
name).
|
static File |
toLauncherDir()
Generates the base path relative to the given class location.
|
static String |
toMethodName()
Retrieves the fully qualified method name of the caller of this method.
|
static String |
toMethodName(StackTraceElement aStackTraceElement)
Retrieves the method name from a stack trace element.
|
static String |
toStackTrace()
Gets the stack trace for the current thread.
|
static String |
toString(String aToString,
String aSuperToString)
Creates a string of a super class's
Object.toString() method and
the provided "toString" text. |
public static String toStackTrace()
public static StackTraceElement getCallerStackTraceElement()
public static StackTraceElement getCallerStackTraceElement(Class<?> aCallee)
Object.getClass()
method, instead use
YourClass.class as as of inheritance, Object.getClass()
returns
the wrong type not being the actual callee!aCallee
- The callee class which wants to find out who called it.public static StackTraceElement getCallerStackTraceElement(Class<?>... aCallees)
getCallerStackTraceElement(Class)
with the difference
that the passed callees are tried out one after the other until the first
caller determined for a callee is returned.aCallees
- the a calleespublic static StackTraceElement getCallerStackTraceElement(String aCalleeClassName)
aCalleeClassName
- The callee class name or package namespace which
wants to find out who called it.public static StackTraceElement getCallerStackTraceElement(String... aCalleeClassNames)
getCallerStackTraceElement(String)
with the difference
that the passed callees are tried out one after the other until the first
caller determined for a callee is returned.aCalleeClassNames
- the a callee class namespublic static Class<?> getCallerType()
Class
) belonging to the direct caller of
this method. When you use this method in your code, you get the
Class
of your method (invoking this method).Class
) of the direct caller of this method.public static Class<?> getCallerType(Class<?> aCallee)
Class
) belonging to the caller of the
callee.aCallee
- The callee class which wants to find out who called it.Class
) of the caller of the caller of this
method.public static Class<?> getCallerType(Class<?>... aCallees)
getCallerType(Class)
with the difference that the passed
callees are tried out one after the other until the first caller
determined for a callee is returned.aCallees
- the a calleespublic static Class<?> toClass(StackTraceElement aStackTraceElement)
Class
type to which the StackTraceElement
belongs.aStackTraceElement
- The StackTraceElement
for which to get
the according Class
.Class
) of the according
StackTraceElement
.public static String toMethodName(StackTraceElement aStackTraceElement)
aStackTraceElement
- The stack trace element from which to retrieve
the method name.public static String toClassName(StackTraceElement aStackTraceElement)
aStackTraceElement
- The stack trace element from which to retrieve
the class name.public static String toFullyQualifiedClassName(StackTraceElement aStackTraceElement)
aStackTraceElement
- The stack trace element from which to retrieve
the fully qualified class name.public static String toFullyQualifiedMethodName(StackTraceElement aStackTraceElement)
aStackTraceElement
- The stack trace element from which to retrieve
the fully qualified method name.public static String toFullyQualifiedClassName()
public static String toFullyQualifiedMethodName()
public static String toMethodName()
public static String toClassName()
public static String toFullyQualifiedPackageName()
public static String toFullyQualifiedPackageName(StackTraceElement aStackTraceElement)
aStackTraceElement
- The stack trace element from which to retrieve
the fully qualified package name.public static String toClassName(String aFullyQualifiedClassName)
aFullyQualifiedClassName
- The fully qualified class name.public static String toFullyQualifiedPackageName(String aFullyQualifiedClassName)
aFullyQualifiedClassName
- The fully qualified class name.public static <T> T toClone(T aObj) throws CloneNotSupportedException
Cloneable
object cannot directly be cloned by casting it to be
Cloneable
:-( Thereforee this method does the job.
Citation From Josh Bloch's Effective Java: "The Cloneable
interface was intended as a mixin interface for objects to advertise that
they permit cloning. Unfortunately it fails to serve this purpose ...
This is a highly atypical use of interfaces and not one to be emulated
... In order for implementing the interface to have any effect on a
class, it and all of its superclasses must obey a fairly complex,
unenforceable and largely undocumented protocol"T
- the generic typeaObj
- The object to be cloned.CloneNotSupportedException
- in case the object cannot be cloned.public static String toString(String aToString, String aSuperToString)
Object.toString()
method and
the provided "toString" text.aToString
- The provided "toString" text.aSuperToString
- A super class's Object.toString()
method's
String
.String
to be
returned by an implementing class's Object.toString()
method.public static Long getPid()
public static Process killProcess(Long aPid) throws IOException
aPid
- The process ID (PID) of the process to kill.Process
object representing the kill operation. This
instance will let you wait till the operation finished
Process.waitFor()
and provides access to the
Process.exitValue()
IOException
- Thrown in case of failing to successfully execute the
kill operation.public static boolean kill(Long aPid) throws IOException, InterruptedException
aPid
- The process ID (PID) of the process to kill.IOException
- Thrown in case of failing to successfully execute the
kill operation.InterruptedException
- the interrupted exceptionpublic static File toLauncherDir()
public static Class getMainClass()
public static List<File> toConfigDirs(File... aBaseDirectories) throws IOException
Folders.CONFIG_DIRS
: The actual directories being returned
(in case them exist) are as follows, relative to each of your
application's base directories:
SystemProperty.CONFIG_DIR
aBaseDirectories
- The application's base directories, in case a
File
instance represent a file (not a directory), then the
according file's parent directory is used.IOException
- Thrown in case there were File
related
problems determining the folders.public static List<File> toConfigDirs() throws IOException
toLauncherDir()
and
passed to toConfigDirs(File...)
.IOException
- Thrown in case there were File
related
problems determining the folders.public static List<File> toConfigDirs(File aBaseDirectory) throws IOException
File
representing the potential base directory together with
the application's base directory where your JAR or your classes reside)
is taken (using the folder as retrieved by toLauncherDir()
) and
passed to toConfigDirs(File...)
and tested for application
configuration folders.aBaseDirectory
- The File
representing the potential base
directory.File
representing a potential application configuration
folder.IOException
- Thrown in case there were File
related
problems determining the folders.@SafeVarargs protected static boolean containsDir(File aDir, List<File>... aDirs)
Copyright © 2017. All rights reserved.