Rogue: Savage Rats, a retro-themed dungeon crawler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
rogue-savage-rats/src/mightypork/gamecore/util/Utils.java

48 lines
850 B

package mightypork.gamecore.util;
import java.lang.annotation.Annotation;
/**
* Assorted utils
*
* @author MightyPork
*/
public final class Utils {
public static Thread runAsThread(Runnable r)
{
final Thread t = new Thread(r);
t.start();
return t;
}
public static boolean hasAnnotation(Object tested, Class<? extends Annotation> annotation)
{
return tested.getClass().isAnnotationPresent(annotation);
}
public static <T extends Annotation> T getAnnotation(Object tested, Class<T> annotation)
{
return tested.getClass().getAnnotation(annotation);
}
/**
* Pick first non-null option
*
* @param options options
* @return the selected option
*/
public static Object fallback(Object... options)
{
for (final Object o : options) {
if (o != null) return o;
}
return null; // all null
}
}