Class JProperties

java.lang.Object
com.io7m.jproperties.JProperties

public final class JProperties
extends java.lang.Object
Type-safe interface to Properties.
  • Method Summary

    Modifier and Type Method Description
    static java.util.Properties fromFile​(java.io.File file)
    Load properties from the given file.
    static java.math.BigDecimal getBigDecimal​(java.util.Properties properties, java.lang.String key)
    Returns the real value associated with key in the properties referenced by properties.
    static java.math.BigDecimal getBigDecimalWithDefault​(java.util.Properties properties, java.lang.String key, java.math.BigDecimal other)
    Returns the real value associated with key in the properties referenced by properties if it exists, otherwise returns the given default value.
    static java.math.BigInteger getBigInteger​(java.util.Properties properties, java.lang.String key)
    Returns the integer value associated with key in the properties referenced by properties.
    static java.math.BigInteger getBigIntegerWithDefault​(java.util.Properties properties, java.lang.String key, java.math.BigInteger other)
    Returns the integer value associated with key in the properties referenced by properties if it exists, otherwise returns other.
    static boolean getBoolean​(java.util.Properties properties, java.lang.String key)
    Returns the boolean value associated with key in the properties referenced by properties.
    static boolean getBooleanWithDefault​(java.util.Properties properties, java.lang.String key, boolean other)
    Returns the boolean value associated with key in the properties referenced by properties if it exists, otherwise returns other.
    static double getDouble​(java.util.Properties properties, java.lang.String key)
    Returns the double value associated with key in the properties referenced by properties.
    static double getDoubleWithDefault​(java.util.Properties properties, java.lang.String key, double other)
    Returns the double value associated with key in the properties referenced by properties if it exists, otherwise returns other.
    static java.time.Duration getDuration​(java.util.Properties properties, java.lang.String key)
    Returns the Duration value associated with key in the properties referenced by properties.
    static java.time.Duration getDurationWithDefault​(java.util.Properties properties, java.lang.String key, java.time.Duration other)
    Returns the Duration value associated with key in the properties referenced by properties if it exists, otherwise returns other.
    static java.net.InetAddress getInetAddress​(java.util.Properties properties, java.lang.String key)
    Returns the InetAddress value associated with key in the properties referenced by properties.
    static java.net.InetAddress getInetAddressWithDefault​(java.util.Properties properties, java.lang.String key, java.net.InetAddress other)
    Returns the InetAddress value associated with key in the properties referenced by properties if it exists, otherwise returns other.
    static int getInteger​(java.util.Properties properties, java.lang.String key)
    Returns the integer value associated with key in the properties referenced by properties.
    static int getIntegerWithDefault​(java.util.Properties properties, java.lang.String key, int other)
    Returns the integer value associated with key in the properties referenced by properties if it exists, otherwise returns other.
    static long getLong​(java.util.Properties properties, java.lang.String key)
    Returns the integer value associated with key in the properties referenced by properties.
    static long getLongWithDefault​(java.util.Properties properties, java.lang.String key, long other)
    Returns the integer value associated with key in the properties referenced by properties if it exists, otherwise returns other.
    static java.lang.String getString​(java.util.Properties properties, java.lang.String key)
    Returns the string value associated with key in the properties referenced by props
    static java.util.Optional<java.lang.String> getStringOptional​(java.util.Properties properties, java.lang.String key)
    Returns the string value associated with key in the properties referenced by props
    static java.lang.String getStringWithDefault​(java.util.Properties properties, java.lang.String key, java.lang.String other)
    Returns the string value associated with key in the properties referenced by props if it exists, otherwise returns other.
    static java.net.URI getURI​(java.util.Properties properties, java.lang.String key)
    Returns the URI value associated with key in the properties referenced by properties.
    static java.net.URI getURIWithDefault​(java.util.Properties properties, java.lang.String key, java.net.URI other)
    Returns the URI value associated with key in the properties referenced by properties if it exists, otherwise returns other.
    static java.util.UUID getUUID​(java.util.Properties properties, java.lang.String key)
    Returns the UUID value associated with key in the properties referenced by properties.
    static java.util.UUID getUUIDWithDefault​(java.util.Properties properties, java.lang.String key, java.util.UUID other)
    Returns the UUID value associated with key in the properties referenced by properties if it exists, otherwise returns other.

    Methods inherited from class java.lang.Object

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

    • fromFile

      public static java.util.Properties fromFile​(java.io.File file) throws java.io.IOException
      Load properties from the given file.
      Parameters:
      file - The file.
      Returns:
      The loaded properties.
      Throws:
      java.io.IOException - On I/O errors.
    • getBigDecimal

      public static java.math.BigDecimal getBigDecimal​(java.util.Properties properties, java.lang.String key) throws JPropertyNonexistent, JPropertyIncorrectType

      Returns the real value associated with key in the properties referenced by properties.

      Parameters:
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed as an real.
      Throws:
      JPropertyNonexistent - If the key does not exist in the given properties.
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as a real.
    • getBigDecimalWithDefault

      public static java.math.BigDecimal getBigDecimalWithDefault​(java.util.Properties properties, java.lang.String key, java.math.BigDecimal other) throws JPropertyIncorrectType

      Returns the real value associated with key in the properties referenced by properties if it exists, otherwise returns the given default value.

      Parameters:
      other - The default value
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed as an real.
      Throws:
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as a real.
      Since:
      3.0.0
    • getBigInteger

      public static java.math.BigInteger getBigInteger​(java.util.Properties properties, java.lang.String key) throws JPropertyNonexistent, JPropertyIncorrectType

      Returns the integer value associated with key in the properties referenced by properties.

      Parameters:
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed as an integer.
      Throws:
      JPropertyNonexistent - If the key does not exist in the given properties.
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as an integer.
    • getBigIntegerWithDefault

      public static java.math.BigInteger getBigIntegerWithDefault​(java.util.Properties properties, java.lang.String key, java.math.BigInteger other) throws JPropertyIncorrectType

      Returns the integer value associated with key in the properties referenced by properties if it exists, otherwise returns other.

      Parameters:
      other - The default value
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed as an integer.
      Throws:
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as an integer.
      Since:
      3.0.0
    • getBoolean

      public static boolean getBoolean​(java.util.Properties properties, java.lang.String key) throws JPropertyNonexistent, JPropertyIncorrectType

      Returns the boolean value associated with key in the properties referenced by properties.

      A boolean value is syntactically the strings "true" or "false", case insensitive.

      Parameters:
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed as a boolean.
      Throws:
      JPropertyNonexistent - If the key does not exist in the given properties.
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as a boolean.
    • getBooleanWithDefault

      public static boolean getBooleanWithDefault​(java.util.Properties properties, java.lang.String key, boolean other) throws JPropertyIncorrectType

      Returns the boolean value associated with key in the properties referenced by properties if it exists, otherwise returns other.

      A boolean value is syntactically the strings "true" or "false", case insensitive.

      Parameters:
      other - The default value
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed as a boolean.
      Throws:
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as a boolean.
      Since:
      3.0.0
    • getString

      public static java.lang.String getString​(java.util.Properties properties, java.lang.String key) throws JPropertyNonexistent

      Returns the string value associated with key in the properties referenced by props

      Parameters:
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the given key
      Throws:
      JPropertyNonexistent - If the given key is not present in the given properties.
    • getStringOptional

      public static java.util.Optional<java.lang.String> getStringOptional​(java.util.Properties properties, java.lang.String key)

      Returns the string value associated with key in the properties referenced by props

      Parameters:
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the given key
      Since:
      3.0.0
    • getStringWithDefault

      public static java.lang.String getStringWithDefault​(java.util.Properties properties, java.lang.String key, java.lang.String other)

      Returns the string value associated with key in the properties referenced by props if it exists, otherwise returns other.

      Parameters:
      other - The default value
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the given key
      Since:
      3.0.0
    • getInteger

      public static int getInteger​(java.util.Properties properties, java.lang.String key) throws JPropertyNonexistent, JPropertyIncorrectType

      Returns the integer value associated with key in the properties referenced by properties.

      Parameters:
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed as an integer.
      Throws:
      JPropertyNonexistent - If the key does not exist in the given properties.
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as an integer.
      Since:
      3.0.0
    • getIntegerWithDefault

      public static int getIntegerWithDefault​(java.util.Properties properties, java.lang.String key, int other) throws JPropertyIncorrectType

      Returns the integer value associated with key in the properties referenced by properties if it exists, otherwise returns other.

      Parameters:
      other - The default value
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed as an integer.
      Throws:
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as an integer.
      Since:
      3.0.0
    • getLong

      public static long getLong​(java.util.Properties properties, java.lang.String key) throws JPropertyNonexistent, JPropertyIncorrectType

      Returns the integer value associated with key in the properties referenced by properties.

      Parameters:
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed as an integer.
      Throws:
      JPropertyNonexistent - If the key does not exist in the given properties.
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as an integer.
      Since:
      3.0.0
    • getLongWithDefault

      public static long getLongWithDefault​(java.util.Properties properties, java.lang.String key, long other) throws JPropertyIncorrectType

      Returns the integer value associated with key in the properties referenced by properties if it exists, otherwise returns other.

      Parameters:
      other - The default value
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed as an integer.
      Throws:
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as an integer.
      Since:
      3.0.0
    • getDouble

      public static double getDouble​(java.util.Properties properties, java.lang.String key) throws JPropertyNonexistent, JPropertyIncorrectType

      Returns the double value associated with key in the properties referenced by properties.

      Parameters:
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed a double
      Throws:
      JPropertyNonexistent - If the key does not exist in the given properties.
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as an integer.
      Since:
      3.0.0
    • getDoubleWithDefault

      public static double getDoubleWithDefault​(java.util.Properties properties, java.lang.String key, double other) throws JPropertyIncorrectType

      Returns the double value associated with key in the properties referenced by properties if it exists, otherwise returns other.

      Parameters:
      other - The default value
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed as a double
      Throws:
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as an integer.
      Since:
      3.0.0
    • getURI

      public static java.net.URI getURI​(java.util.Properties properties, java.lang.String key) throws JPropertyNonexistent, JPropertyIncorrectType

      Returns the URI value associated with key in the properties referenced by properties.

      Parameters:
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed as a URI.
      Throws:
      JPropertyNonexistent - If the key does not exist in the given properties.
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as a URI.
      Since:
      3.0.0
    • getURIWithDefault

      public static java.net.URI getURIWithDefault​(java.util.Properties properties, java.lang.String key, java.net.URI other) throws JPropertyIncorrectType

      Returns the URI value associated with key in the properties referenced by properties if it exists, otherwise returns other.

      Parameters:
      other - The default value
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed as a URI.
      Throws:
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as a URI.
      Since:
      3.0.0
    • getUUID

      public static java.util.UUID getUUID​(java.util.Properties properties, java.lang.String key) throws JPropertyNonexistent, JPropertyIncorrectType

      Returns the UUID value associated with key in the properties referenced by properties.

      Parameters:
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed as a UUID.
      Throws:
      JPropertyNonexistent - If the key does not exist in the given properties.
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as a UUID.
      Since:
      3.0.0
    • getUUIDWithDefault

      public static java.util.UUID getUUIDWithDefault​(java.util.Properties properties, java.lang.String key, java.util.UUID other) throws JPropertyIncorrectType

      Returns the UUID value associated with key in the properties referenced by properties if it exists, otherwise returns other.

      Parameters:
      other - The default value
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed as a UUID.
      Throws:
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as a UUID.
      Since:
      3.0.0
    • getInetAddress

      public static java.net.InetAddress getInetAddress​(java.util.Properties properties, java.lang.String key) throws JPropertyNonexistent, JPropertyIncorrectType

      Returns the InetAddress value associated with key in the properties referenced by properties.

      Parameters:
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed as an InetAddress.
      Throws:
      JPropertyNonexistent - If the key does not exist in the given properties.
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as a InetAddress.
      Since:
      3.0.0
    • getInetAddressWithDefault

      public static java.net.InetAddress getInetAddressWithDefault​(java.util.Properties properties, java.lang.String key, java.net.InetAddress other) throws JPropertyIncorrectType

      Returns the InetAddress value associated with key in the properties referenced by properties if it exists, otherwise returns other.

      Parameters:
      other - The default value
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed as an InetAddress.
      Throws:
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as a InetAddress.
      Since:
      3.0.0
    • getDuration

      public static java.time.Duration getDuration​(java.util.Properties properties, java.lang.String key) throws JPropertyNonexistent, JPropertyIncorrectType

      Returns the Duration value associated with key in the properties referenced by properties.

      Parameters:
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed as an Duration.
      Throws:
      JPropertyNonexistent - If the key does not exist in the given properties.
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as a Duration.
      Since:
      3.1.0
    • getDurationWithDefault

      public static java.time.Duration getDurationWithDefault​(java.util.Properties properties, java.lang.String key, java.time.Duration other) throws JPropertyIncorrectType

      Returns the Duration value associated with key in the properties referenced by properties if it exists, otherwise returns other.

      Parameters:
      other - The default value
      properties - The loaded properties.
      key - The requested key.
      Returns:
      The value associated with the key, parsed as an Duration.
      Throws:
      JPropertyIncorrectType - If the value associated with the key cannot be parsed as a Duration.
      Since:
      3.1.0