This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
2020-04-28 00:15:24 +00:00
|
|
|
package com.thebrokenrail.scriptcraft.core;
|
2020-04-25 13:33:17 +00:00
|
|
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
@SuppressWarnings("UnnecessaryUnboxing")
|
2020-04-28 00:15:24 +00:00
|
|
|
public class ValueUtil {
|
2020-04-25 13:33:17 +00:00
|
|
|
public static <T extends Enum<T>> T getEnumValue(Class<T> clazz, String value, T defaultValue) {
|
|
|
|
try {
|
|
|
|
return Enum.valueOf(clazz, value.toUpperCase(Locale.ROOT));
|
|
|
|
} catch (NullPointerException e) {
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static double toDouble(Object value, double defaultValue) {
|
|
|
|
try {
|
|
|
|
return ((Double) value).doubleValue();
|
|
|
|
} catch (NullPointerException e) {
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean toBoolean(Object value, boolean defaultValue) {
|
|
|
|
try {
|
|
|
|
return ((Boolean) value).booleanValue();
|
|
|
|
} catch (NullPointerException e) {
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|