public final class RuntimeUtility extends Object
Modifier and Type | Method and Description |
---|---|
static Class<?> |
geCallerType()
Returns the type of the (
Class ) belonging to the direct caller of
this method. |
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(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 org.refcodes.collection.Properties |
loadProperties(String aPropertiesFileName)
Loads a properties file from the first folder containing such a file as
of the specification for the method
toAppConfigDirs() . |
static File |
toAppBaseDir()
Generates the base path relative to the given class location.
|
static List<File> |
toAppConfigDirs()
Returns a list of (existing) folders which are candidates for external
resources.
|
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 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 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.public static StackTraceElement getCallerStackTraceElement(String aCalleeClassName)
Object.getClass()
method, instead use
YourClass.class as as of inheritance, Object.getClass()
returns
the wrong type not being the actual callee!aCalleeClassName
- The callee class name 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.public static Class<?> geCallerType()
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.public 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"aObj
- 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
public static File toAppBaseDir() throws IOException
IOException
- thrown in case determining the path failed due to
I/O.public static Class getMainClass()
public static List<File> toAppConfigDirs() throws IOException
SystemProperty#CONFIG_DIR_NAMES
: The actual directories being
returned (in case them exist) are as follows, relative to your
applications base directory:
SystemProperty.CONFIG_DIR
IOException
- Thrown in case there were File
related
problems determining the folders.public static org.refcodes.collection.Properties loadProperties(String aPropertiesFileName) throws IOException
toAppConfigDirs()
.aPropertiesFileName
- The filename of the properties file to load.IOException
- thrown in case accessing or processing the properties
file failed.Copyright © 2017. All rights reserved.