Class JPropertyParsing

java.lang.Object
com.io7m.jproperties.monad.JPropertyParsing

public final class JPropertyParsing
extends java.lang.Object
Parser monad functions.
Since:
3.0.0
  • Method Details

    • parseAny

      public static <T> JPropertyParseMonadType<T> parseAny​(java.util.Properties properties, java.lang.String key, java.lang.String format, JPropertyParsing.ParseFunctionType<T> parser)
      Parse anything. The given parser function is used to parse the given text value, and any exception raised will be converted into a parse failure result and a useful error message constructed. The given format names the target format and should be worded similarly to "a URI" or "an ISO time duration".
      Type Parameters:
      T - The type of returned values
      Parameters:
      properties - The properties from which to extract values
      key - The property key
      format - The name of the format used for error messages
      parser - The parse function
      Returns:
      A parse result
    • parseAnyOptional

      public static <T> JPropertyParseMonadType<java.util.Optional<T>> parseAnyOptional​(java.util.Properties properties, java.lang.String key, java.lang.String format, JPropertyParsing.ParseFunctionType<T> parser)
      Parse anything. The given parser function is used to parse the given text value, and any exception raised will be converted into a parse failure result and a useful error message constructed. The given format names the target format and should be worded similarly to "a URI" or "an ISO time duration".
      Type Parameters:
      T - The type of returned values
      Parameters:
      properties - The properties from which to extract values
      key - The property key
      format - The name of the format used for error messages
      parser - The parse function
      Returns:
      A parse result
    • parseAnyWithDefault

      public static <T> JPropertyParseMonadType<T> parseAnyWithDefault​(java.util.Properties properties, java.lang.String key, java.lang.String format, T defaultValue, JPropertyParsing.ParseFunctionType<T> parser)
      Parse anything. The given parser function is used to parse the given text value, and any exception raised will be converted into a parse failure result and a useful error message constructed. The given format names the target format and should be worded similarly to "a URI" or "an ISO time duration".
      Type Parameters:
      T - The type of returned values
      Parameters:
      properties - The properties from which to extract values
      key - The property key
      format - The name of the format used for error messages
      defaultValue - The default value
      parser - The parse function
      Returns:
      A parse result
    • parseBigInteger

      public static JPropertyParseMonadType<java.math.BigInteger> parseBigInteger​(java.util.Properties properties, java.lang.String key)
      Parse a BigInteger.
      Parameters:
      properties - The properties
      key - The key
      Returns:
      A parse result
    • parseBigIntegerWithDefault

      public static JPropertyParseMonadType<java.math.BigInteger> parseBigIntegerWithDefault​(java.util.Properties properties, java.lang.String key, java.math.BigInteger defaultValue)
      Parse a BigInteger returning the default value if the key does not exist.
      Parameters:
      properties - The properties
      key - The key
      defaultValue - The default value
      Returns:
      A parse result
    • parseBoolean

      public static JPropertyParseMonadType<java.lang.Boolean> parseBoolean​(java.util.Properties properties, java.lang.String key)
      Parse a Boolean.
      Parameters:
      properties - The properties
      key - The key
      Returns:
      A parse result
    • parseBooleanWithDefault

      public static JPropertyParseMonadType<java.lang.Boolean> parseBooleanWithDefault​(java.util.Properties properties, java.lang.String key, boolean defaultValue)
      Parse a Boolean returning the default value if the key does not exist.
      Parameters:
      properties - The properties
      key - The key
      defaultValue - The default value
      Returns:
      A parse result
    • parseString

      public static JPropertyParseMonadType<java.lang.String> parseString​(java.util.Properties properties, java.lang.String key)
      Parse a String.
      Parameters:
      properties - The properties
      key - The key
      Returns:
      A parse result
    • parseStringOptional

      public static JPropertyParseMonadType<java.util.Optional<java.lang.String>> parseStringOptional​(java.util.Properties properties, java.lang.String key)
      Parse a String.
      Parameters:
      properties - The properties
      key - The key
      Returns:
      A parse result
    • parseStringWithDefault

      public static JPropertyParseMonadType<java.lang.String> parseStringWithDefault​(java.util.Properties properties, java.lang.String key, java.lang.String defaultValue)
      Parse a String returning the default value if the key does not exist.
      Parameters:
      properties - The properties
      key - The key
      defaultValue - The default value
      Returns:
      A parse result
    • parseBigDecimal

      public static JPropertyParseMonadType<java.math.BigDecimal> parseBigDecimal​(java.util.Properties properties, java.lang.String key)
      Parse a BigDecimal.
      Parameters:
      properties - The properties
      key - The key
      Returns:
      A parse result
    • parseBigDecimalWithDefault

      public static JPropertyParseMonadType<java.math.BigDecimal> parseBigDecimalWithDefault​(java.util.Properties properties, java.lang.String key, java.math.BigDecimal defaultValue)
      Parse a BigDecimal returning the default value if the key does not exist.
      Parameters:
      properties - The properties
      key - The key
      defaultValue - The default value
      Returns:
      A parse result
    • parseURI

      public static JPropertyParseMonadType<java.net.URI> parseURI​(java.util.Properties properties, java.lang.String key)
      Parse a URI.
      Parameters:
      properties - The properties
      key - The key
      Returns:
      A parse result
    • parseURIWithDefault

      public static JPropertyParseMonadType<java.net.URI> parseURIWithDefault​(java.util.Properties properties, java.lang.String key, java.net.URI defaultValue)
      Parse a URI returning the default value if the key does not exist.
      Parameters:
      properties - The properties
      key - The key
      defaultValue - The default value
      Returns:
      A parse result
    • parseUUID

      public static JPropertyParseMonadType<java.util.UUID> parseUUID​(java.util.Properties properties, java.lang.String key)
      Parse a UUID.
      Parameters:
      properties - The properties
      key - The key
      Returns:
      A parse result
    • parseUUIDWithDefault

      public static JPropertyParseMonadType<java.util.UUID> parseUUIDWithDefault​(java.util.Properties properties, java.lang.String key, java.util.UUID defaultValue)
      Parse a UUID returning the default value if the key does not exist.
      Parameters:
      properties - The properties
      key - The key
      defaultValue - The default value
      Returns:
      A parse result
    • parseDuration

      public static JPropertyParseMonadType<java.time.Duration> parseDuration​(java.util.Properties properties, java.lang.String key)
      Parse a Duration.
      Parameters:
      properties - The properties
      key - The key
      Returns:
      A parse result
    • parseDurationWithDefault

      public static JPropertyParseMonadType<java.time.Duration> parseDurationWithDefault​(java.util.Properties properties, java.lang.String key, java.time.Duration defaultValue)
      Parse a Duration returning the default value if the key does not exist.
      Parameters:
      properties - The properties
      key - The key
      defaultValue - The default value
      Returns:
      A parse result
    • parseOffsetDateTime

      public static JPropertyParseMonadType<java.time.OffsetDateTime> parseOffsetDateTime​(java.util.Properties properties, java.lang.String key)
      Parse a OffsetDateTime.
      Parameters:
      properties - The properties
      key - The key
      Returns:
      A parse result
    • parseOffsetDateTimeWithDefault

      public static JPropertyParseMonadType<java.time.OffsetDateTime> parseOffsetDateTimeWithDefault​(java.util.Properties properties, java.lang.String key, java.time.OffsetDateTime defaultValue)
      Parse a OffsetDateTime returning the default value if the key does not exist.
      Parameters:
      properties - The properties
      key - The key
      defaultValue - The default value
      Returns:
      A parse result
    • successOf

      public static <T> JPropertyParseMonadType<T> successOf​(T result)
      Trivially succeed.
      Type Parameters:
      T - The type of returned values
      Parameters:
      result - The returned value
      Returns:
      A parse result
    • warn

      public static JPropertyParseMonadType<JPropertyParseMonadType.Unit> warn​(java.lang.String message)
      Publish a warning.
      Parameters:
      message - The warning message
      Returns:
      A warning result
    • warn

      public static JPropertyParseMonadType<JPropertyParseMonadType.Unit> warn​(java.lang.String key, java.lang.String message)
      Publish a warning.
      Parameters:
      key - The key associated with the warning
      message - The warning message
      Returns:
      A warning result
    • fail

      public static JPropertyParseMonadType<JPropertyParseMonadType.Unit> fail​(java.lang.Exception e)
      Publish an error.
      Parameters:
      e - The exception
      Returns:
      A failure result
    • allOf

      public static <T> JPropertyParseMonadType<java.util.List<T>> allOf​(java.util.List<JPropertyParseMonadType<? extends T>> operations)
      Evaluate all of the given operations and return a list of the results (including the union of all of the warnings) if all of them succeeded. Otherwise, return a failure result that accumulates all of the warnings and errors.
      Type Parameters:
      T - The common type of the results
      Parameters:
      operations - The list of parse operations
      Returns:
      The result of evaluating all of the operations
    • allOf

      public static <T> JPropertyParseMonadType<java.util.List<T>> allOf​(JPropertyParseMonadType<? extends T>... operations)
      Evaluate all of the given operations and return a list of the results (including the union of all of the warnings) if all of them succeeded. Otherwise, return a failure result that accumulates all of the warnings and errors.
      Type Parameters:
      T - The common type of the results
      Parameters:
      operations - The list of parse operations
      Returns:
      The result of evaluating all of the operations