Class PropertyUtil

java.lang.Object
org.omegazero.common.util.PropertyUtil

public final class PropertyUtil extends Object
Contains utility methods for reading Properties and system properties.
Since:
2.2
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    getBoolean(String key, boolean def)
    Gets the system property value associated with the given key and attempts to parse it a boolean.
    static boolean
    getBoolean(Properties props, String key, boolean def)
    Gets the string associated with the given key in the Properties object and attempts to parse it a boolean.
    static double
    getDouble(String key, double def)
    Gets the system property value associated with the given key and attempts to parse it as a double-precision floating point number.
    static double
    getDouble(Properties props, String key, double def)
    Gets the string associated with the given key in the Properties object and attempts to parse it as a double-precision floating point number.
    static float
    getFloat(String key, float def)
    Gets the system property value associated with the given key and attempts to parse it as a floating point number.
    static float
    getFloat(Properties props, String key, float def)
    Gets the string associated with the given key in the Properties object and attempts to parse it as a floating point number.
    static int
    getInt(String key, int def)
    Gets the system property value associated with the given key and attempts to parse it as an integer.
    static int
    getInt(Properties props, String key, int def)
    Gets the string associated with the given key in the Properties object and attempts to parse it as an integer.
    static long
    getLong(String key, long def)
    Gets the system property value associated with the given key and attempts to parse it as a long integer.
    static long
    getLong(Properties props, String key, long def)
    Gets the string associated with the given key in the Properties object and attempts to parse it as a long integer.
    static String
    getString(String key, String def)
    Returns the system property value associated with the given key.
    static String
    getString(Properties props, String key, String def)
    Returns the string associated with the given key in the Properties object.
    static boolean
    Returns whether the system property identified by the given key is set.
    static boolean
    setDefault(String key, String value)
    Sets the system property with the given key to the given value, if no property with the given key is already set.

    Methods inherited from class java.lang.Object

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

    • getString

      public static String getString(String key, String def)
      Returns the system property value associated with the given key. If the property does not exist, def is returned.
      Parameters:
      key - The key
      def - The default value
      Returns:
      The value of key, or def if the property does not exist
      See Also:
    • getInt

      public static int getInt(String key, int def)
      Gets the system property value associated with the given key and attempts to parse it as an integer. If the property does not exist or the value is not a valid number, def is returned.
      Parameters:
      key - The key
      def - The default value
      Returns:
      The numeric value of key, or def if the property is invalid
      See Also:
    • getLong

      public static long getLong(String key, long def)
      Gets the system property value associated with the given key and attempts to parse it as a long integer. If the property does not exist or the value is not a valid number, def is returned.
      Parameters:
      key - The key
      def - The default value
      Returns:
      The numeric value of key, or def if the property is invalid
      See Also:
    • getFloat

      public static float getFloat(String key, float def)
      Gets the system property value associated with the given key and attempts to parse it as a floating point number. If the property does not exist or the value is not a valid number, def is returned.
      Parameters:
      key - The key
      def - The default value
      Returns:
      The numeric value of key, or def if the property is invalid
      See Also:
    • getDouble

      public static double getDouble(String key, double def)
      Gets the system property value associated with the given key and attempts to parse it as a double-precision floating point number. If the property does not exist or the value is not a valid number, def is returned.
      Parameters:
      key - The key
      def - The default value
      Returns:
      The numeric value of key, or def if the property is invalid
      See Also:
    • getBoolean

      public static boolean getBoolean(String key, boolean def)
      Gets the system property value associated with the given key and attempts to parse it a boolean. If the property does not exist or the value is not a valid boolean, def is returned.
      Parameters:
      key - The key
      def - The default value
      Returns:
      The boolean value of key, or def if the property is invalid
      See Also:
    • isPropertySet

      public static boolean isPropertySet(String key)
      Returns whether the system property identified by the given key is set.
      Parameters:
      key - The key
      Returns:
      true if a system property with the given key exists
      Since:
      2.8
    • setDefault

      public static boolean setDefault(String key, String value)
      Sets the system property with the given key to the given value, if no property with the given key is already set.
      Parameters:
      key - The key
      value - The value
      Returns:
      true if a system property with the given key existed already
      Since:
      2.11.0
    • getString

      public static String getString(Properties props, String key, String def)
      Returns the string associated with the given key in the Properties object. If there is no mapping for the given key, the value passed to def is returned.
      Parameters:
      props - The properties
      key - The key
      def - The default value to return if there is no value for the key
      Returns:
      The value of key, or def if there is no value associated with the key
      See Also:
    • getInt

      public static int getInt(Properties props, String key, int def)
      Gets the string associated with the given key in the Properties object and attempts to parse it as an integer. If there is no mapping for the given key or the value is not a valid number, the value passed to def is returned.
      Parameters:
      props - The properties
      key - The key
      def - The default value to return if there is no value for the key or the value is not valid
      Returns:
      The numeric value of key, or def if there is no value associated with the key or the value is not a valid number
      See Also:
    • getLong

      public static long getLong(Properties props, String key, long def)
      Gets the string associated with the given key in the Properties object and attempts to parse it as a long integer. If there is no mapping for the given key or the value is not a valid number, the value passed to def is returned.
      Parameters:
      props - The properties
      key - The key
      def - The default value to return if there is no value for the key or the value is not valid
      Returns:
      The numeric value of key, or def if there is no value associated with the key or the value is not a valid number
      See Also:
    • getFloat

      public static float getFloat(Properties props, String key, float def)
      Gets the string associated with the given key in the Properties object and attempts to parse it as a floating point number. If there is no mapping for the given key or the value is not a valid number, the value passed to def is returned.
      Parameters:
      props - The properties
      key - The key
      def - The default value to return if there is no value for the key or the value is not valid
      Returns:
      The numeric value of key, or def if there is no value associated with the key or the value is not a valid number
      See Also:
    • getDouble

      public static double getDouble(Properties props, String key, double def)
      Gets the string associated with the given key in the Properties object and attempts to parse it as a double-precision floating point number. If there is no mapping for the given key or the value is not a valid number, the value passed to def is returned.
      Parameters:
      props - The properties
      key - The key
      def - The default value to return if there is no value for the key or the value is not valid
      Returns:
      The numeric value of key, or def if there is no value associated with the key or the value is not a valid number
      See Also:
    • getBoolean

      public static boolean getBoolean(Properties props, String key, boolean def)
      Gets the string associated with the given key in the Properties object and attempts to parse it a boolean. If there is no mapping for the given key or the value is not a valid boolean, the value passed to def is returned.

      A string will be interpreted as the boolean value true if the string equals "true" or "1" and as false if the string equals "false" or "0".

      Parameters:
      props - The properties
      key - The key
      def - The default value to return if there is no value for the key or the value is not valid
      Returns:
      The boolean value of key, or def if there is no value associated with the key or the value is not a valid boolean
      See Also: