Class Utils

java.lang.Object
com.hw.langchain.utils.Utils

public class Utils extends Object
Author:
HamaWhite
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • getFromDictOrEnv

      public static String getFromDictOrEnv(Map<String,Object> data, String key, String envKey, String... defaultValue)
      Retrieves the value from the dictionary or environment variable.
      Parameters:
      data - The dictionary data.
      key - The key to lookup in the dictionary.
      envKey - The key to lookup in the environment variables.
      defaultValue - The default value(s) to return if the key is not found or the value is null or empty.
      Returns:
      The retrieved value. If the key is found and the value is not null or empty, it is returned. Otherwise, the value from the environment variable is returned if it is not null or empty. If the default value(s) are provided, the first default value is returned. If none of the above conditions are met, null is returned.
    • getFromEnv

      public static String getFromEnv(String key, String envKey, String... defaultValue)
      Retrieves the value from the environment variable or the default value.
      Parameters:
      key - The key to lookup in the environment variables.
      envKey - The key to lookup in the environment variables.
      defaultValue - The default value(s) to return if the environment variable is not found or its value is null or empty.
      Returns:
      The retrieved value. If the environment variable is not null or empty, it is returned. If the default value(s) are provided, the first default value is returned. If none of the above conditions are met, an IllegalArgumentException is thrown.
      Throws:
      IllegalArgumentException - if the environment variable is not found and no default value is provided.
    • getOrEnvOrDefault

      public static String getOrEnvOrDefault(String originalValue, String envKey, String... defaultValue)
      Retrieves the value from the original value, environment variable, or default value.
      Parameters:
      originalValue - The original value to check.
      envKey - The key to lookup in the environment variables.
      defaultValue - The default value(s) to return if the original value and environment variable are empty or null.
      Returns:
      The retrieved value. If the original value is not empty, it is returned. If the environment variable is not empty, it is returned. If the default value(s) are provided, the first default value is returned. If none of the above conditions are met, null is returned.