Class PropertyManager

java.lang.Object
com.unboundid.util.PropertyManager

This class provides a mechanism for retrieving the values of specified properties in the form of either Java system properties or process environment variables (using an alternative name generated from the provided property name using the generateEnvironmentVariableNameFromPropertyName(java.lang.String) method). System properties will be given a higher priority than environment variables, and the value can be parsed in accordance with a number of syntaxes.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Generates an alternative environment variable name that can be used for a given property name.
    static String
    get(String propertyName)
    Retrieves the value of the specified system property or environment variable.
    static String
    get(String propertyName, String defaultValue)
    Retrieves the value of the specified system property or environment variable.
    static Boolean
    getBoolean(String propertyName)
    Retrieves the value of the specified property or environment variable as a Boolean value.
    static Boolean
    getBoolean(String propertyName, Boolean defaultValue)
    Retrieves the value of the specified property or environment variable as a Boolean value.
    static Boolean
    getBoolean(String propertyName, Boolean defaultValue, boolean throwOnInvalidValue)
    Retrieves the value of the specified property or environment variable as a Boolean value.
    static List<String>
    Retrieves the value of the specified property or environment variable as a list of comma-delimited values.
    static List<String>
    getCommaDelimitedList(String propertyName, boolean trimItems)
    Retrieves the value of the specified property or environment variable as a list of comma-delimited values.
    static Integer
    getInt(String propertyName)
    Retrieves the value of the specified property or environment variable as an integer.
    static Integer
    getInt(String propertyName, Integer defaultValue)
    Retrieves the value of the specified property or environment variable as an integer.
    static Integer
    getInt(String propertyName, Integer defaultValue, boolean throwOnInvalidValue)
    Retrieves the value of the specified property or environment variable as an integer.
    static Long
    getLong(String propertyName)
    Retrieves the value of the specified property or environment variable as a long.
    static Long
    getLong(String propertyName, Long defaultValue)
    Retrieves the value of the specified property or environment variable as a long.
    static Long
    getLong(String propertyName, Long defaultValue, boolean throwOnInvalidValue)
    Retrieves the value of the specified property or environment variable as a long.
    static Properties
    getProperties(String... propertyNames)
    Retrieves a Properties object with values for any of the specified properties that are currently set.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • get

      @Nullable public static String get(@NotNull String propertyName)
      Retrieves the value of the specified system property or environment variable.
      Parameters:
      propertyName - The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not be null or empty.
      Returns:
      The requested value, or null if it has not been set as either a system property or an environment variable.
    • get

      @Nullable public static String get(@NotNull String propertyName, @Nullable String defaultValue)
      Retrieves the value of the specified system property or environment variable.
      Parameters:
      propertyName - The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not be null or empty.
      defaultValue - The default value to return if neither the system property nor associated environment variable have been set. It may be null if no default value should be returned.
      Returns:
      The requested value, or null if it has not been set as either a system property or an environment variable.
    • getBoolean

      @Nullable public static Boolean getBoolean(@NotNull String propertyName)
      Retrieves the value of the specified property or environment variable as a Boolean value.
      Parameters:
      propertyName - The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not be null or empty.
      Returns:
      The Boolean value of the specified property or environment variable, or null if neither are set or are set to a value that cannot be parsed as a Boolean.
    • getBoolean

      @Nullable public static Boolean getBoolean(@NotNull String propertyName, @Nullable Boolean defaultValue)
      Retrieves the value of the specified property or environment variable as a Boolean value.
      Parameters:
      propertyName - The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not be null or empty.
      defaultValue - The default value to return if neither the system property nor associated environment variable have been set, or if the value cannot be parsed as a Boolean. It may be null if no default value should be returned.
      Returns:
      The Boolean value of the specified property or environment variable, or the provided default value if neither are set or are set to a value that cannot be parsed as a Boolean.
    • getBoolean

      @Nullable public static Boolean getBoolean(@NotNull String propertyName, @Nullable Boolean defaultValue, boolean throwOnInvalidValue) throws IllegalArgumentException
      Retrieves the value of the specified property or environment variable as a Boolean value.
      Parameters:
      propertyName - The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not be null or empty.
      defaultValue - The default value to return if neither the system property nor associated environment variable have been set, or if the value cannot be parsed as a Boolean and throwOnInvalidValue is false. It may be null if no default value should be returned.
      throwOnInvalidValue - Indicates whether this method should throw an IllegalArgumentException if the system property or environment variable is set but its value cannot be parsed as a Boolean.
      Returns:
      The Boolean value of the specified property or environment variable, or the provided default value if neither are set or are set to a value that cannot be parsed as a Boolean and throwOnInvalidValue is false.
      Throws:
      IllegalArgumentException - If the property or environment variable is set, but its value cannot be parsed as a Boolean, and throwOnInvalidValue is true.
    • getInt

      @Nullable public static Integer getInt(@NotNull String propertyName)
      Retrieves the value of the specified property or environment variable as an integer.
      Parameters:
      propertyName - The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not be null or empty.
      Returns:
      The integer value of the specified property or environment variable, or null if neither are set or are set to a value that cannot be parsed as an integer.
    • getInt

      @Nullable public static Integer getInt(@NotNull String propertyName, @Nullable Integer defaultValue)
      Retrieves the value of the specified property or environment variable as an integer.
      Parameters:
      propertyName - The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not be null or empty.
      defaultValue - The default value to return if neither the system property nor associated environment variable have been set, or if the value cannot be parsed as an integer. It may be null if no default value should be returned.
      Returns:
      The integer value of the specified property or environment variable, or the provided default value if neither are set or are set to a value that cannot be parsed as an integer.
    • getInt

      @Nullable public static Integer getInt(@NotNull String propertyName, @Nullable Integer defaultValue, boolean throwOnInvalidValue) throws IllegalArgumentException
      Retrieves the value of the specified property or environment variable as an integer.
      Parameters:
      propertyName - The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not be null or empty.
      defaultValue - The default value to return if neither the system property nor associated environment variable have been set, or if the value cannot be parsed as an integer and throwOnInvalidValue is false. It may be null if no default value should be returned.
      throwOnInvalidValue - Indicates whether this method should throw an IllegalArgumentException if the system property or environment variable is set but its value cannot be parsed as an integer.
      Returns:
      The integer value of the specified property or environment variable, or the provided default value if neither are set or are set to a value that cannot be parsed as an integer and throwOnInvalidValue is false.
      Throws:
      IllegalArgumentException - If the property or environment variable is set, but its value cannot be parsed as an integer, and throwOnInvalidValue is true.
    • getLong

      @Nullable public static Long getLong(@NotNull String propertyName)
      Retrieves the value of the specified property or environment variable as a long.
      Parameters:
      propertyName - The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not be null or empty.
      Returns:
      The long value of the specified property or environment variable, or null if neither are set or are set to a value that cannot be parsed as a long.
    • getLong

      @Nullable public static Long getLong(@NotNull String propertyName, @Nullable Long defaultValue)
      Retrieves the value of the specified property or environment variable as a long.
      Parameters:
      propertyName - The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not be null or empty.
      defaultValue - The default value to return if neither the system property nor associated environment variable have been set, or if the value cannot be parsed as a long. It may be null if no default value should be returned.
      Returns:
      The long value of the specified property or environment variable, or the provided default value if neither are set or are set to a value that cannot be parsed as a long.
    • getLong

      @Nullable public static Long getLong(@NotNull String propertyName, @Nullable Long defaultValue, boolean throwOnInvalidValue) throws IllegalArgumentException
      Retrieves the value of the specified property or environment variable as a long.
      Parameters:
      propertyName - The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not be null or empty.
      defaultValue - The default value to return if neither the system property nor associated environment variable have been set, or if the value cannot be parsed as a long and throwOnInvalidValue is false. It may be null if no default value should be returned.
      throwOnInvalidValue - Indicates whether this method should throw an IllegalArgumentException if the system property or environment variable is set but its value cannot be parsed as a long.
      Returns:
      The long value of the specified property or environment variable, or the provided default value if neither are set or are set to a value that cannot be parsed as a long and throwOnInvalidValue is false.
      Throws:
      IllegalArgumentException - If the property or environment variable is set, but its value cannot be parsed as a long, and throwOnInvalidValue is true.
    • getCommaDelimitedList

      @NotNull public static List<String> getCommaDelimitedList(@NotNull String propertyName)
      Retrieves the value of the specified property or environment variable as a list of comma-delimited values. Any spaces around commas will be trimmed.
      Parameters:
      propertyName - The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not be null or empty.
      Returns:
      An unmodifiable list containing the comma-delimited values of the specified property or environment variable, or an empty list if neither is set.
    • getCommaDelimitedList

      @NotNull public static List<String> getCommaDelimitedList(@NotNull String propertyName, boolean trimItems)
      Retrieves the value of the specified property or environment variable as a list of comma-delimited values. Any spaces around commas will be trimmed.
      Parameters:
      propertyName - The name of the system property to retrieve, and to use to generate an alternative environment variable. It must not be null or empty.
      trimItems - Indicates whether the individual items in the list should be trimmed to remove leading and/or trailing spaces.
      Returns:
      An unmodifiable list containing the comma-delimited values of the specified property or environment variable, or an empty list if neither is set.
    • getProperties

      @NotNull public static Properties getProperties(@NotNull String... propertyNames)
      Retrieves a Properties object with values for any of the specified properties that are currently set.
      Parameters:
      propertyNames - The name of the properties whose values should be retrieved. It must not be null, but may be empty.
      Returns:
      A Properties object with any of the specified properties that are set as either JVM system properties or environment variables. It may be empty if none of the specified properties have been set.
    • generateEnvironmentVariableNameFromPropertyName

      Generates an alternative environment variable name that can be used for a given property name. All alphabetic letters in the provided name will be converted to uppercase, and all characters other than ASCII letters and digits will be converted to underscores.
      Parameters:
      propertyName - The property name to use to generate the environment variable name. It must not be null or empty.
      Returns:
      The alternative environment variable name generated from the given property name.