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 Show documentation
Show all versions of activeobjects Show documentation
This is the full Active Objects library, if you don't know which one to use, you probably want this one.
The newest version!
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));
}
}