|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.util.Misc
public final class Misc
just some miscellaneous stuff for convenience that doesn't fit anywhere else
| Method Summary | ||
|---|---|---|
static void |
addToSystemClassLoader(URL url)
'hacks' the given URL into the system class loader |
|
static
|
asListRetriever(ValueRetriever<T> vr,
String desc)
|
|
static Properties |
asProperties(ResourceBundle bundle)
|
|
static Runnable |
asRunnable(Task<?> task)
|
|
static Task<RuntimeException> |
asTask(Runnable r)
|
|
static int |
calculateEANChecksum(String codeWithoutCheckDigit)
takes both: UPC and EAN codes; must be numeric only |
|
static boolean |
checkEAN(String code)
takes both: UPC and EAN codes; must be numeric only |
|
static void |
clearClipboard()
|
|
static int |
compare(Object o1,
Object o2)
|
|
static void |
copyToClipboard(Object obj)
|
|
static void |
copyToClipboard(Transferable tf)
|
|
static
|
create(boolean enforceAccessability,
Class<T> type,
Object... params)
|
|
static
|
create(Class<T> type,
Object... params)
calls create(boolean, Class, Object...) w/ true as the first parameter |
|
static KeyPair |
generateKeyPair()
|
|
static KeyPair |
generateKeyPair(int keySize)
|
|
static KeyPair |
generateKeyPair(String algorithm,
int keySize)
|
|
static String |
getConsoleInput()
reads a line from the console and returns the keyboard input as a string after 'Enter' was pressed |
|
static String |
getConsoleInput(String question)
prints the given question and returns getConsoleInput() |
|
static
|
getConstants(Class<?> declaringType,
Class<T> constantType)
|
|
static
|
getEnumExtractor(Class<T> type)
|
|
static String |
getMacAddress()
returns the first MAC address found in a non-virtual network interface. |
|
static String |
getMacAddress(InetAddress adr)
returns the MAC address supported since java version 1.6 |
|
static Method |
getMainMethod(Class<?> c)
|
|
static
|
getMethodComparator(Class<T> type,
String methodName)
|
|
static
|
getMethodComparator(Method method)
|
|
static PatternExtractor<Object,Object> |
getMethodExtractor(String methodName)
|
|
static
|
getMethodExtractor(String methodName,
Class<T> returnType)
|
|
static HashMap<String,Object> |
getMethodValues(Object obj)
maps public non-static method names with no parameters and a non-void return value to their respective return values |
|
static String |
getOption(String optionKey,
String[] args)
looks for the given option from a list of command line arguments. |
|
static String |
getSimpleTypeName(Class<?> type)
|
|
static Object |
invoke(Object obj,
boolean enforceAccessibility,
String methodName,
Object... params)
attempts to invoke the given method with the given parameters on the given object via reflection. |
|
static Object |
invoke(Object obj,
String methodName,
Object... params)
calls invoke(obj, false, methodName, params) |
|
static void |
invokeMain(Class<?> c,
String... args)
|
|
static boolean |
isClassAvailable(String className)
allows to test for the availability of the given class name w/o throwing an exception |
|
static boolean |
isObjectIn(Object obj,
Object... listOfObjects)
uses same(Object, Object) to see whether the first parameter is equal to any of the other given |
|
static URLClassLoader |
loadClasses(File... dirOrJar)
preloads all classes found in the given directories and/or Jar files |
|
static URLClassLoader |
loadClasses(Monitor monitor,
File... dirOrJar)
preloads all classes found in the given directories and/or Jar files |
|
static URLClassLoader |
loadFromClassPath(Monitor mon,
String path)
preloads all classes found in the given path |
|
static URLClassLoader |
loadFromClassPath(String path)
preloads all classes found in the given path |
|
static String |
macString(byte... bytes)
|
|
static String |
makeURLString(File file)
generates a URL-like String of the form " |
|
static void |
open(File file)
|
|
static void |
open(URL url)
|
|
static Object |
pasteFromClipboard()
|
|
static Object |
pasteFromClipboard(DataFlavor flavor)
|
|
static String |
pasteStringFromClipboard()
|
|
static void |
pause(long millisec)
just simplifies a call to Thread.sleep() |
|
static
|
reverseFilter(Filter<T> filter)
returns an inversed filter to the given one |
|
static void |
run(Task<?> task,
boolean asynchronously)
runs the given task (either within this or a new thread) while converting Exceptions to RuntimeExceptions if they happen |
|
static boolean |
same(Object s1,
Object s2)
returns true only if the the both objects are equal or both null, false otherwise. |
|
static Object |
setValue(Object obj,
String fieldName,
Object value)
|
|
static Process |
start(File workingDir,
String... params)
starts a given file and other parameters with the platform specific application.startCommand in the settings. |
|
static Process |
start(String... params)
|
|
static boolean |
start(URL url)
Deprecated. as of JDK 1.6, java.awt.Desktop can be used instead. |
|
static
|
synchronizeAccess(I instance,
Class<I> type,
Object semaphore)
allows to synchronize all access to the given instance based on the given semaphore object. |
|
static
|
unsaveCast(Object t)
allows to delegate an 'unsave' cast to this method so that the remainder of a calling method remains 'save' - provided that you know what your're doing here |
|
static
|
unwrap(Object obj,
Class<T> targetType)
employs the Wrapped interface to extract the given type from the given object if applicable |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static <T> T[] getConstants(Class<?> declaringType,
Class<T> constantType)
public static <T extends Enum<T>> PatternExtractor<Object,T> getEnumExtractor(Class<T> type)
public static Task<RuntimeException> asTask(Runnable r)
public static Runnable asRunnable(Task<?> task)
public static void run(Task<?> task,
boolean asynchronously)
task - the task to be run; may be nullasynchronously - if true, the method returns immediately, while the task is performed on a new thread;
if false, the task is performed directly before the method returns
public static <T> ListRetriever<T> asListRetriever(ValueRetriever<T> vr,
String desc)
public static <T> T unwrap(Object obj,
Class<T> targetType)
Wrapped,
InterfaceWrapper.wrap(ClassLoader, Object, Object, Class)
@Warning(value="you\'d better have a darn good reason to use this method")
public static <T> T unsaveCast(Object t)
throws ClassCastException
ClassCastExceptionpublic static String getConsoleInput()
public static String getConsoleInput(String question)
public static URLClassLoader loadFromClassPath(String path)
throws IOException
IOException
public static URLClassLoader loadFromClassPath(Monitor mon,
String path)
throws IOException
mon - allows to individually monitor the loading processpath - the path to load the classes from
IOException
public static URLClassLoader loadClasses(File... dirOrJar)
throws IOException
dirOrJar - Jar files or directories that are to be loaded
IOException
public static URLClassLoader loadClasses(Monitor monitor,
File... dirOrJar)
throws IOException
monitor - allows to individually monitor the loading processdirOrJar - Jar files or directories that are to be loaded
IOException
public static String makeURLString(File file)
throws IOException
IOExceptionpublic static <T> Filter<T> reverseFilter(Filter<T> filter)
ComboFilter.negate(Filter)
public static <T> Comparator<T> getMethodComparator(Class<T> type,
String methodName)
throws IllegalArgumentException
IllegalArgumentExceptionpublic static <T> Comparator<T> getMethodComparator(Method method)
public static int compare(Object o1,
Object o2)
UniversalComparator.getDefaultInstance()@Deprecated public static boolean start(URL url)
Settings.getProperties()
to start the url. Note that a successful call to this method is platform
dependent; you may have to adjust the application.startCommand
parameter to make this work for your platform.
The different command parts of the application.startCommand
are separated by a tab (\t).
The default value for this parameter shipped with the antelmann.jar file
works for Windows NT/2000/XP.
Settings.getProperties()
public static void open(File file)
throws IOException
IOException
public static void open(URL url)
throws IOException
IOException
public static Process start(String... params)
throws IOException
IOException
public static Process start(File workingDir,
String... params)
throws IOException
IOExceptionSettings.getProperties()public static void pause(long millisec)
Thread.sleep()
public static Properties asProperties(ResourceBundle bundle)
public static KeyPair generateKeyPair()
public static KeyPair generateKeyPair(int keySize)
public static KeyPair generateKeyPair(String algorithm,
int keySize)
throws NoSuchAlgorithmException
NoSuchAlgorithmException
public static boolean isObjectIn(Object obj,
Object... listOfObjects)
public static boolean same(Object s1,
Object s2)
public static void clearClipboard()
public static String pasteStringFromClipboard()
public static Object pasteFromClipboard()
public static Object pasteFromClipboard(DataFlavor flavor)
public static void copyToClipboard(Object obj)
public static void copyToClipboard(Transferable tf)
public static PatternExtractor<Object,Object> getMethodExtractor(String methodName)
public static <T> PatternExtractor<Object,T> getMethodExtractor(String methodName,
Class<T> returnType)
public static String getMacAddress()
throws UnknownHostException,
SocketException
UnknownHostException
SocketExceptionNetworkInterface.getHardwareAddress()
public static String getMacAddress(InetAddress adr)
throws UnknownHostException,
SocketException
UnknownHostException
SocketExceptionInetAddress.getLocalHost(),
NetworkInterface.getHardwareAddress()public static String macString(byte... bytes)
public static <T> T create(Class<T> type,
Object... params)
throws InstantiationException,
IllegalAccessException,
InvocationTargetException,
NoSuchMethodException
create(boolean, Class, Object...) w/ true as the first parameter
InstantiationException
IllegalAccessException
InvocationTargetException
NoSuchMethodException
@Warning(value="takes the first available constructor, which may not be the best due to overloading if no exact match was found at first")
public static <T> T create(boolean enforceAccessability,
Class<T> type,
Object... params)
throws InstantiationException,
IllegalAccessException,
InvocationTargetException,
NoSuchMethodException
InstantiationException
IllegalAccessException
InvocationTargetException
NoSuchMethodException
public static Object invoke(Object obj,
String methodName,
Object... params)
throws IllegalAccessException,
InvocationTargetException,
NoSuchMethodException
IllegalAccessException
InvocationTargetException
NoSuchMethodException
@Warning(value="takes the first available method, which may not be the best due to overloading if no exact match was found at first")
public static Object invoke(Object obj,
boolean enforceAccessibility,
String methodName,
Object... params)
throws IllegalAccessException,
InvocationTargetException,
NoSuchMethodException
IllegalAccessException
InvocationTargetException
NoSuchMethodException
public static void invokeMain(Class<?> c,
String... args)
throws NoSuchMethodException,
InvocationTargetException,
IllegalAccessException
NoSuchMethodException
InvocationTargetException
IllegalAccessException
public static Method getMainMethod(Class<?> c)
throws NoSuchMethodException
NoSuchMethodException
public static HashMap<String,Object> getMethodValues(Object obj)
throws IllegalAccessException,
InvocationTargetException
IllegalAccessException
InvocationTargetException
public static Object setValue(Object obj,
String fieldName,
Object value)
throws SecurityException,
NoSuchFieldException,
IllegalArgumentException,
IllegalAccessException
SecurityException
NoSuchFieldException
IllegalArgumentException
IllegalAccessExceptionpublic static String getSimpleTypeName(Class<?> type)
public static <I> I synchronizeAccess(I instance,
Class<I> type,
Object semaphore)
I - the interface to be synchronizedinstance - the object instance who's methods are to be synchronizedtype - the interface type that is to be usedsemaphore - the object used for synchronization
public static void addToSystemClassLoader(URL url)
throws Exception
Exception
public static boolean checkEAN(String code)
throws IllegalArgumentException
IllegalArgumentException
public static int calculateEANChecksum(String codeWithoutCheckDigit)
throws IllegalArgumentException
IllegalArgumentException
public static String getOption(String optionKey,
String[] args)
optionKey - the plain option key you look for, e.g. '-user'args - the argument list
public static boolean isClassAvailable(String className)
Settings.getClassLoader()
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||