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

The raw string list value

* @return

The value as a string list, or null if not compatible

*/ public static @NotNull List 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 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 * *

This will throw an exception if used for a non-boolean value

* * @param value

The object value to get

* @return

The value of the given object as a boolean

* @throws ClassCastException

If the given value is not a boolean

*/ 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(); } } }