net.java.ao.util.EnumUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of activeobjects-core Show documentation
Show all versions of activeobjects-core Show documentation
This is the core library for Active Objects. It is generic and can be embedded in any environment.
As such it is generic and won't contain all connection pooling, etc.
package net.java.ao.util;
import com.google.common.collect.Iterables;
import java.lang.reflect.InvocationTargetException;
import static com.google.common.collect.Lists.newArrayList;
public final class EnumUtils {
public static Iterable values(Class extends Enum> type) {
try {
return newArrayList((Enum[]) type.getMethod("values").invoke(null));
} catch (IllegalArgumentException e) {
throw new IllegalStateException(e);
} catch (SecurityException e) {
throw new IllegalStateException(e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e);
} catch (InvocationTargetException e) {
throw new IllegalStateException(e);
} catch (NoSuchMethodException e) {
throw new IllegalStateException(e);
}
}
public static int size(Class extends Enum> type) {
return Iterables.size(values(type));
}
}