diff --git a/src/main/java/com/llmproxy/model/TaskType.java b/src/main/java/com/llmproxy/model/TaskType.java index 64265d6..bef7580 100644 --- a/src/main/java/com/llmproxy/model/TaskType.java +++ b/src/main/java/com/llmproxy/model/TaskType.java @@ -1,5 +1,8 @@ package com.llmproxy.model; +import java.util.Map; +import java.util.HashMap; + public enum TaskType { TEXT_GENERATION("text_generation"), SUMMARIZATION("summarization"), @@ -9,6 +12,15 @@ public enum TaskType { private final String value; + // Cache for fromString method to improve performance + private static final Map STRING_TO_ENUM_MAP = new HashMap<>(); + + static { + for (TaskType type : values()) { + STRING_TO_ENUM_MAP.put(type.value.toLowerCase(), type); + } + } + TaskType(String value) { this.value = value; } @@ -18,16 +30,15 @@ public String getValue() { } public static TaskType fromString(String text) { - for (TaskType type : TaskType.values()) { - if (type.value.equalsIgnoreCase(text)) { - return type; - } + if (text == null) { + return OTHER; // Or throw IllegalArgumentException, depending on desired behavior } - return OTHER; + TaskType type = STRING_TO_ENUM_MAP.get(text.toLowerCase()); + return type != null ? type : OTHER; } @Override public String toString() { return value; } -} +} \ No newline at end of file