Class PropertyManager

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String generateEnvironmentVariableNameFromPropertyName​(java.lang.String propertyName)
      Generates an alternative environment variable name that can be used for a given property name.
      static java.lang.String get​(java.lang.String propertyName)
      Retrieves the value of the specified system property or environment variable.
      static java.lang.String get​(java.lang.String propertyName, java.lang.String defaultValue)
      Retrieves the value of the specified system property or environment variable.
      static java.lang.Boolean getBoolean​(java.lang.String propertyName)
      Retrieves the value of the specified property or environment variable as a Boolean value.
      static java.lang.Boolean getBoolean​(java.lang.String propertyName, java.lang.Boolean defaultValue)
      Retrieves the value of the specified property or environment variable as a Boolean value.
      static java.lang.Boolean getBoolean​(java.lang.String propertyName, java.lang.Boolean defaultValue, boolean throwOnInvalidValue)
      Retrieves the value of the specified property or environment variable as a Boolean value.
      static java.util.List<java.lang.String> getCommaDelimitedList​(java.lang.String propertyName)
      Retrieves the value of the specified property or environment variable as a list of comma-delimited values.
      static java.util.List<java.lang.String> getCommaDelimitedList​(java.lang.String propertyName, boolean trimItems)
      Retrieves the value of the specified property or environment variable as a list of comma-delimited values.
      static java.lang.Integer getInt​(java.lang.String propertyName)
      Retrieves the value of the specified property or environment variable as an integer.
      static java.lang.Integer getInt​(java.lang.String propertyName, java.lang.Integer defaultValue)
      Retrieves the value of the specified property or environment variable as an integer.
      static java.lang.Integer getInt​(java.lang.String propertyName, java.lang.Integer defaultValue, boolean throwOnInvalidValue)
      Retrieves the value of the specified property or environment variable as an integer.
      static java.lang.Long getLong​(java.lang.String propertyName)
      Retrieves the value of the specified property or environment variable as a long.
      static java.lang.Long getLong​(java.lang.String propertyName, java.lang.Long defaultValue)
      Retrieves the value of the specified property or environment variable as a long.
      static java.lang.Long getLong​(java.lang.String propertyName, java.lang.Long defaultValue, boolean throwOnInvalidValue)
      Retrieves the value of the specified property or environment variable as a long.
      static java.util.Properties getProperties​(java.lang.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 Detail

      • get

        @Nullable
        public static java.lang.String get​(@NotNull
                                           java.lang.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 java.lang.String get​(@NotNull
                                           java.lang.String propertyName,
                                           @Nullable
                                           java.lang.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 java.lang.Boolean getBoolean​(@NotNull
                                                   java.lang.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 java.lang.Boolean getBoolean​(@NotNull
                                                   java.lang.String propertyName,
                                                   @Nullable
                                                   java.lang.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 java.lang.Boolean getBoolean​(@NotNull
                                                   java.lang.String propertyName,
                                                   @Nullable
                                                   java.lang.Boolean defaultValue,
                                                   boolean throwOnInvalidValue)
                                            throws java.lang.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:
        java.lang.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 java.lang.Integer getInt​(@NotNull
                                               java.lang.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 java.lang.Integer getInt​(@NotNull
                                               java.lang.String propertyName,
                                               @Nullable
                                               java.lang.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 java.lang.Integer getInt​(@NotNull
                                               java.lang.String propertyName,
                                               @Nullable
                                               java.lang.Integer defaultValue,
                                               boolean throwOnInvalidValue)
                                        throws java.lang.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:
        java.lang.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 java.lang.Long getLong​(@NotNull
                                             java.lang.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 java.lang.Long getLong​(@NotNull
                                             java.lang.String propertyName,
                                             @Nullable
                                             java.lang.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 java.lang.Long getLong​(@NotNull
                                             java.lang.String propertyName,
                                             @Nullable
                                             java.lang.Long defaultValue,
                                             boolean throwOnInvalidValue)
                                      throws java.lang.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:
        java.lang.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 java.util.List<java.lang.String> getCommaDelimitedList​(@NotNull
                                                                             java.lang.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 java.util.List<java.lang.String> getCommaDelimitedList​(@NotNull
                                                                             java.lang.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 java.util.Properties getProperties​(@NotNull
                                                         java.lang.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

        @NotNull
        public static java.lang.String generateEnvironmentVariableNameFromPropertyName​(@NotNull
                                                                                       java.lang.String propertyName)
        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.