Class EnumParser

java.lang.Object
com.wontlost.ckeditor.internal.EnumParser

public final class EnumParser extends Object
Safe enum parsing utility class.

Provides type-safe enum parsing, avoiding the following common issues:

  • Case-conversion issues caused by special locales such as Turkish
  • Exceptions caused by null or empty strings
  • IllegalArgumentException caused by invalid values

This class is an internal API and should not be used directly by external code.

  • Method Details

    • parse

      public static <T extends Enum<T>> T parse(String value, Class<T> enumType, T defaultValue)
      Safely parse an enum value.

      Parsing rules:

      • Uses Locale.ROOT for case conversion to ensure internationalization safety
      • Returns the default value for null or empty strings
      • Returns the default value and logs a warning for invalid values
      Type Parameters:
      T - the enum type
      Parameters:
      value - the string value to parse
      enumType - the target enum type
      defaultValue - the default value when parsing fails
      Returns:
      the parsed enum value, or the default value on failure
    • parse

      public static <T extends Enum<T>> T parse(String value, Class<T> enumType, T defaultValue, String context)
      Safely parse an enum value with a custom log message context.
      Type Parameters:
      T - the enum type
      Parameters:
      value - the string value to parse
      enumType - the target enum type
      defaultValue - the default value when parsing fails
      context - context description (used in log messages)
      Returns:
      the parsed enum value, or the default value on failure
    • parseStrict

      public static <T extends Enum<T>> T parseStrict(String value, Class<T> enumType)
      Strictly parse an enum value, throwing an exception for invalid values.
      Type Parameters:
      T - the enum type
      Parameters:
      value - the string value to parse
      enumType - the target enum type
      Returns:
      the parsed enum value
      Throws:
      IllegalArgumentException - if the value is null, empty, or invalid