Class JPropertyParsing

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

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

    • parseAny

      public static <T> JPropertyParseMonadType<T> parseAny(Properties properties, String key, 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<Optional<T>> parseAnyOptional(Properties properties, String key, 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(Properties properties, String key, 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<BigInteger> parseBigInteger(Properties properties, String key)
      Parse a BigInteger.
      Parameters:
      properties - The properties
      key - The key
      Returns:
      A parse result
    • parseBigIntegerWithDefault

      public static JPropertyParseMonadType<BigInteger> parseBigIntegerWithDefault(Properties properties, String key, 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<Boolean> parseBoolean(Properties properties, String key)
      Parse a Boolean.
      Parameters:
      properties - The properties
      key - The key
      Returns:
      A parse result
    • parseBooleanWithDefault

      public static JPropertyParseMonadType<Boolean> parseBooleanWithDefault(Properties properties, 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<String> parseString(Properties properties, String key)
      Parse a String.
      Parameters:
      properties - The properties
      key - The key
      Returns:
      A parse result
    • parseStringOptional

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

      public static JPropertyParseMonadType<String> parseStringWithDefault(Properties properties, String key, 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<BigDecimal> parseBigDecimal(Properties properties, String key)
      Parse a BigDecimal.
      Parameters:
      properties - The properties
      key - The key
      Returns:
      A parse result
    • parseBigDecimalWithDefault

      public static JPropertyParseMonadType<BigDecimal> parseBigDecimalWithDefault(Properties properties, String key, 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<URI> parseURI(Properties properties, String key)
      Parse a URI.
      Parameters:
      properties - The properties
      key - The key
      Returns:
      A parse result
    • parseURIWithDefault

      public static JPropertyParseMonadType<URI> parseURIWithDefault(Properties properties, String key, 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<UUID> parseUUID(Properties properties, String key)
      Parse a UUID.
      Parameters:
      properties - The properties
      key - The key
      Returns:
      A parse result
    • parseUUIDWithDefault

      public static JPropertyParseMonadType<UUID> parseUUIDWithDefault(Properties properties, String key, 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<Duration> parseDuration(Properties properties, String key)
      Parse a Duration.
      Parameters:
      properties - The properties
      key - The key
      Returns:
      A parse result
    • parseDurationWithDefault

      public static JPropertyParseMonadType<Duration> parseDurationWithDefault(Properties properties, String key, 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<OffsetDateTime> parseOffsetDateTime(Properties properties, String key)
      Parse a OffsetDateTime.
      Parameters:
      properties - The properties
      key - The key
      Returns:
      A parse result
    • parseOffsetDateTimeWithDefault

      public static JPropertyParseMonadType<OffsetDateTime> parseOffsetDateTimeWithDefault(Properties properties, String key, 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

      Publish a warning.
      Parameters:
      message - The warning message
      Returns:
      A warning result
    • warn

      Publish a warning.
      Parameters:
      key - The key associated with the warning
      message - The warning message
      Returns:
      A warning result
    • fail

      Publish an error.
      Parameters:
      e - The exception
      Returns:
      A failure result
    • allOf

      public static <T> JPropertyParseMonadType<List<T>> allOf(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<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