Package com.io7m.jproperties.monad
Class JPropertyParsing
java.lang.Object
com.io7m.jproperties.monad.JPropertyParsing
Parser monad functions.
- Since:
- 3.0.0
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
A parse function. -
Method Summary
Modifier and TypeMethodDescriptionstatic <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.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.Publish an error.static <T> JPropertyParseMonadType<T>
parseAny
(Properties properties, String key, String format, JPropertyParsing.ParseFunctionType<T> parser) Parse anything.static <T> JPropertyParseMonadType<Optional<T>>
parseAnyOptional
(Properties properties, String key, String format, JPropertyParsing.ParseFunctionType<T> parser) Parse anything.static <T> JPropertyParseMonadType<T>
parseAnyWithDefault
(Properties properties, String key, String format, T defaultValue, JPropertyParsing.ParseFunctionType<T> parser) Parse anything.static JPropertyParseMonadType<BigDecimal>
parseBigDecimal
(Properties properties, String key) Parse aBigDecimal
.static JPropertyParseMonadType<BigDecimal>
parseBigDecimalWithDefault
(Properties properties, String key, BigDecimal defaultValue) Parse aBigDecimal
returning the default value if the key does not exist.static JPropertyParseMonadType<BigInteger>
parseBigInteger
(Properties properties, String key) Parse aBigInteger
.static JPropertyParseMonadType<BigInteger>
parseBigIntegerWithDefault
(Properties properties, String key, BigInteger defaultValue) Parse aBigInteger
returning the default value if the key does not exist.static JPropertyParseMonadType<Boolean>
parseBoolean
(Properties properties, String key) Parse aBoolean
.static JPropertyParseMonadType<Boolean>
parseBooleanWithDefault
(Properties properties, String key, boolean defaultValue) Parse aBoolean
returning the default value if the key does not exist.static JPropertyParseMonadType<Duration>
parseDuration
(Properties properties, String key) Parse aDuration
.static JPropertyParseMonadType<Duration>
parseDurationWithDefault
(Properties properties, String key, Duration defaultValue) Parse aDuration
returning the default value if the key does not exist.parseOffsetDateTime
(Properties properties, String key) Parse aOffsetDateTime
.parseOffsetDateTimeWithDefault
(Properties properties, String key, OffsetDateTime defaultValue) Parse aOffsetDateTime
returning the default value if the key does not exist.static JPropertyParseMonadType<String>
parseString
(Properties properties, String key) Parse aString
.static JPropertyParseMonadType<Optional<String>>
parseStringOptional
(Properties properties, String key) Parse aString
.static JPropertyParseMonadType<String>
parseStringWithDefault
(Properties properties, String key, String defaultValue) Parse aString
returning the default value if the key does not exist.static JPropertyParseMonadType<URI>
parseURI
(Properties properties, String key) Parse aURI
.static JPropertyParseMonadType<URI>
parseURIWithDefault
(Properties properties, String key, URI defaultValue) Parse aURI
returning the default value if the key does not exist.static JPropertyParseMonadType<UUID>
parseUUID
(Properties properties, String key) Parse aUUID
.static JPropertyParseMonadType<UUID>
parseUUIDWithDefault
(Properties properties, String key, UUID defaultValue) Parse aUUID
returning the default value if the key does not exist.static <T> JPropertyParseMonadType<T>
successOf
(T result) Trivially succeed.Publish a warning.Publish a warning.
-
Method Details
-
parseAny
public static <T> JPropertyParseMonadType<T> parseAny(Properties properties, String key, String format, JPropertyParsing.ParseFunctionType<T> parser) Parse anything. The givenparser
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 givenformat
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 valueskey
- The property keyformat
- The name of the format used for error messagesparser
- 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 givenparser
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 givenformat
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 valueskey
- The property keyformat
- The name of the format used for error messagesparser
- 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 givenparser
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 givenformat
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 valueskey
- The property keyformat
- The name of the format used for error messagesdefaultValue
- The default valueparser
- The parse function- Returns:
- A parse result
-
parseBigInteger
public static JPropertyParseMonadType<BigInteger> parseBigInteger(Properties properties, String key) Parse aBigInteger
.- Parameters:
properties
- The propertieskey
- The key- Returns:
- A parse result
-
parseBigIntegerWithDefault
public static JPropertyParseMonadType<BigInteger> parseBigIntegerWithDefault(Properties properties, String key, BigInteger defaultValue) Parse aBigInteger
returning the default value if the key does not exist.- Parameters:
properties
- The propertieskey
- The keydefaultValue
- The default value- Returns:
- A parse result
-
parseBoolean
Parse aBoolean
.- Parameters:
properties
- The propertieskey
- The key- Returns:
- A parse result
-
parseBooleanWithDefault
public static JPropertyParseMonadType<Boolean> parseBooleanWithDefault(Properties properties, String key, boolean defaultValue) Parse aBoolean
returning the default value if the key does not exist.- Parameters:
properties
- The propertieskey
- The keydefaultValue
- The default value- Returns:
- A parse result
-
parseString
Parse aString
.- Parameters:
properties
- The propertieskey
- The key- Returns:
- A parse result
-
parseStringOptional
public static JPropertyParseMonadType<Optional<String>> parseStringOptional(Properties properties, String key) Parse aString
.- Parameters:
properties
- The propertieskey
- The key- Returns:
- A parse result
-
parseStringWithDefault
public static JPropertyParseMonadType<String> parseStringWithDefault(Properties properties, String key, String defaultValue) Parse aString
returning the default value if the key does not exist.- Parameters:
properties
- The propertieskey
- The keydefaultValue
- The default value- Returns:
- A parse result
-
parseBigDecimal
public static JPropertyParseMonadType<BigDecimal> parseBigDecimal(Properties properties, String key) Parse aBigDecimal
.- Parameters:
properties
- The propertieskey
- The key- Returns:
- A parse result
-
parseBigDecimalWithDefault
public static JPropertyParseMonadType<BigDecimal> parseBigDecimalWithDefault(Properties properties, String key, BigDecimal defaultValue) Parse aBigDecimal
returning the default value if the key does not exist.- Parameters:
properties
- The propertieskey
- The keydefaultValue
- The default value- Returns:
- A parse result
-
parseURI
Parse aURI
.- Parameters:
properties
- The propertieskey
- The key- Returns:
- A parse result
-
parseURIWithDefault
public static JPropertyParseMonadType<URI> parseURIWithDefault(Properties properties, String key, URI defaultValue) Parse aURI
returning the default value if the key does not exist.- Parameters:
properties
- The propertieskey
- The keydefaultValue
- The default value- Returns:
- A parse result
-
parseUUID
Parse aUUID
.- Parameters:
properties
- The propertieskey
- The key- Returns:
- A parse result
-
parseUUIDWithDefault
public static JPropertyParseMonadType<UUID> parseUUIDWithDefault(Properties properties, String key, UUID defaultValue) Parse aUUID
returning the default value if the key does not exist.- Parameters:
properties
- The propertieskey
- The keydefaultValue
- The default value- Returns:
- A parse result
-
parseDuration
Parse aDuration
.- Parameters:
properties
- The propertieskey
- The key- Returns:
- A parse result
-
parseDurationWithDefault
public static JPropertyParseMonadType<Duration> parseDurationWithDefault(Properties properties, String key, Duration defaultValue) Parse aDuration
returning the default value if the key does not exist.- Parameters:
properties
- The propertieskey
- The keydefaultValue
- The default value- Returns:
- A parse result
-
parseOffsetDateTime
public static JPropertyParseMonadType<OffsetDateTime> parseOffsetDateTime(Properties properties, String key) Parse aOffsetDateTime
.- Parameters:
properties
- The propertieskey
- The key- Returns:
- A parse result
-
parseOffsetDateTimeWithDefault
public static JPropertyParseMonadType<OffsetDateTime> parseOffsetDateTimeWithDefault(Properties properties, String key, OffsetDateTime defaultValue) Parse aOffsetDateTime
returning the default value if the key does not exist.- Parameters:
properties
- The propertieskey
- The keydefaultValue
- The default value- Returns:
- A parse result
-
successOf
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
public static JPropertyParseMonadType<JPropertyParseMonadType.Unit> warn(String key, String message) Publish a warning.- Parameters:
key
- The key associated with the warningmessage
- 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
-