Class EnumParser
java.lang.Object
com.wontlost.ckeditor.internal.EnumParser
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 Summary
Modifier and TypeMethodDescriptionstatic <T extends Enum<T>>
TSafely parse an enum value.static <T extends Enum<T>>
TSafely parse an enum value with a custom log message context.static <T extends Enum<T>>
TparseStrict(String value, Class<T> enumType) Strictly parse an enum value, throwing an exception for invalid values.
-
Method Details
-
parse
Safely parse an enum value.Parsing rules:
- Uses
Locale.ROOTfor 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 parseenumType- the target enum typedefaultValue- the default value when parsing fails- Returns:
- the parsed enum value, or the default value on failure
- Uses
-
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 parseenumType- the target enum typedefaultValue- the default value when parsing failscontext- context description (used in log messages)- Returns:
- the parsed enum value, or the default value on failure
-
parseStrict
Strictly parse an enum value, throwing an exception for invalid values.- Type Parameters:
T- the enum type- Parameters:
value- the string value to parseenumType- the target enum type- Returns:
- the parsed enum value
- Throws:
IllegalArgumentException- if the value is null, empty, or invalid
-