All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good
61 lines
1.7 KiB
Java
61 lines
1.7 KiB
Java
package net.knarcraft.ffmpegconverter.utility;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* A helper class for dealing with configuration value types
|
|
*/
|
|
public final class ConfigHelper {
|
|
|
|
private ConfigHelper() {
|
|
|
|
}
|
|
|
|
/**
|
|
* Gets the given value as a string list
|
|
*
|
|
* @param value <p>The raw string list value</p>
|
|
* @return <p>The value as a string list, or null if not compatible</p>
|
|
*/
|
|
public static @NotNull List<String> asStringList(@Nullable Object value) {
|
|
if (value == null) {
|
|
return new ArrayList<>();
|
|
}
|
|
if (value instanceof String string) {
|
|
return List.of((string).split(","));
|
|
} else if (value instanceof List<?> list) {
|
|
List<String> strings = new ArrayList<>();
|
|
for (Object object : list) {
|
|
strings.add(String.valueOf(object));
|
|
}
|
|
return strings;
|
|
} else {
|
|
return new ArrayList<>();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Gets the given value as a boolean
|
|
*
|
|
* <p>This will throw an exception if used for a non-boolean value</p>
|
|
*
|
|
* @param value <p>The object value to get</p>
|
|
* @return <p>The value of the given object as a boolean</p>
|
|
* @throws ClassCastException <p>If the given value is not a boolean</p>
|
|
*/
|
|
public static boolean asBoolean(@Nullable Object value) throws ClassCastException {
|
|
if (value instanceof Boolean booleanValue) {
|
|
return booleanValue;
|
|
} else if (value instanceof String) {
|
|
return Boolean.parseBoolean((String) value);
|
|
} else {
|
|
throw new ClassCastException();
|
|
}
|
|
}
|
|
|
|
}
|