Class ValueConverter<T>
java.lang.Object
net.ixdarklord.coolcatcore.api.utils.ValueConverter<T>
- Type Parameters:
T- The type of value to parse and convert.
A utility class for parsing strings into values of type T and converting values of type T into strings.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ValueConverter<Boolean>A ValueConverter for Boolean values.static final ValueConverter<Double>A ValueConverter for Double values.static final ValueConverter<Integer>A ValueConverter for Integer values.static final ValueConverter<String>A ValueConverter for String values. -
Method Summary
Modifier and TypeMethodDescriptionstatic <E extends Enum<E>>
ValueConverter<E>A ValueConverter for Enum values.static <T> ValueConverter<T>Static factory method to create a ValueConverter instance.Parses a string into the type T.Converts a value of type T to a string.
-
Field Details
-
STRING
A ValueConverter for String values. -
INTEGER
A ValueConverter for Integer values. -
DOUBLE
A ValueConverter for Double values. -
BOOLEAN
A ValueConverter for Boolean values.
-
-
Method Details
-
forEnum
A ValueConverter for Enum values. This method creates a ValueConverter for a specific enum class.- Parameters:
enumClass- The class of the enum.- Returns:
- A ValueConverter for the specified enum type.
-
of
public static <T> ValueConverter<T> of(Function<String, T> parser, Function<T, String> toStringConverter) Static factory method to create a ValueConverter instance.- Parameters:
parser- A function to parse a string into the type T.toStringConverter- A function to convert the type T to a string.- Returns:
- A new ValueConverter instance.
-
parse
Parses a string into the type T.- Parameters:
input- The input string to parse.- Returns:
- The parsed value of type T.
- Throws:
IllegalArgumentException- If the input cannot be parsed.
-
toString
Converts a value of type T to a string.- Parameters:
value- The value to convert.- Returns:
- The string representation of the value.
-