Class ValueConverter<T>

java.lang.Object
net.ixdarklord.coolcatcore.api.utils.ValueConverter<T>
Type Parameters:
T - The type of value to parse and convert.

public class ValueConverter<T> extends Object
A utility class for parsing strings into values of type T and converting values of type T into strings.
  • Field Details

  • Method Details

    • forEnum

      public static <E extends Enum<E>> ValueConverter<E> forEnum(Class<E> enumClass)
      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

      public T parse(String input)
      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

      public String toString(T value)
      Converts a value of type T to a string.
      Parameters:
      value - The value to convert.
      Returns:
      The string representation of the value.