Class JProperties

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

public final class JProperties extends Object
Type-safe interface to Properties.
  • Method Details

    • fromFile

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

      public static BigDecimal getBigDecimal(Properties properties, 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 BigDecimal getBigDecimalWithDefault(Properties properties, String key, 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 BigInteger getBigInteger(Properties properties, 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 BigInteger getBigIntegerWithDefault(Properties properties, String key, 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(Properties properties, 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(Properties properties, 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 String getString(Properties properties, 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 Optional<String> getStringOptional(Properties properties, 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 String getStringWithDefault(Properties properties, String key, 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(Properties properties, 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(Properties properties, 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(Properties properties, 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(Properties properties, 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(Properties properties, 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(Properties properties, 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 URI getURI(Properties properties, 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 URI getURIWithDefault(Properties properties, String key, 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 UUID getUUID(Properties properties, 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 UUID getUUIDWithDefault(Properties properties, String key, 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 InetAddress getInetAddress(Properties properties, 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 InetAddress getInetAddressWithDefault(Properties properties, String key, 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 Duration getDuration(Properties properties, 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 Duration getDurationWithDefault(Properties properties, String key, 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