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.
ScriptCraft/scriptcraft/src/main/java/com/thebrokenrail/scriptcraft/core/ValueUtil.java
TheBrokenRail 0e3b0cbc87
Some checks failed
ScriptCraft/pipeline/head There was a failure building this commit
Use Composite Builds
2020-05-31 13:25:16 -04:00

31 lines
881 B
Java

package com.thebrokenrail.scriptcraft.core;
import java.util.Locale;
@SuppressWarnings("UnnecessaryUnboxing")
public class ValueUtil {
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;
}
}
}