Package com.io7m.jproperties.monad
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
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceJPropertyParsing.ParseFunctionType<T>A parse function. -
Method Summary
Modifier and Type Method Description 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.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.static JPropertyParseMonadType<JPropertyParseMonadType.Unit>fail(java.lang.Exception e)Publish an error.static <T> JPropertyParseMonadType<T>parseAny(java.util.Properties properties, java.lang.String key, java.lang.String format, JPropertyParsing.ParseFunctionType<T> parser)Parse anything.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.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.static JPropertyParseMonadType<java.math.BigDecimal>parseBigDecimal(java.util.Properties properties, java.lang.String key)Parse aBigDecimal.static JPropertyParseMonadType<java.math.BigDecimal>parseBigDecimalWithDefault(java.util.Properties properties, java.lang.String key, java.math.BigDecimal defaultValue)Parse aBigDecimalreturning the default value if the key does not exist.static JPropertyParseMonadType<java.math.BigInteger>parseBigInteger(java.util.Properties properties, java.lang.String key)Parse aBigInteger.static JPropertyParseMonadType<java.math.BigInteger>parseBigIntegerWithDefault(java.util.Properties properties, java.lang.String key, java.math.BigInteger defaultValue)Parse aBigIntegerreturning the default value if the key does not exist.static JPropertyParseMonadType<java.lang.Boolean>parseBoolean(java.util.Properties properties, java.lang.String key)Parse aBoolean.static JPropertyParseMonadType<java.lang.Boolean>parseBooleanWithDefault(java.util.Properties properties, java.lang.String key, boolean defaultValue)Parse aBooleanreturning the default value if the key does not exist.static JPropertyParseMonadType<java.time.Duration>parseDuration(java.util.Properties properties, java.lang.String key)Parse aDuration.static JPropertyParseMonadType<java.time.Duration>parseDurationWithDefault(java.util.Properties properties, java.lang.String key, java.time.Duration defaultValue)Parse aDurationreturning the default value if the key does not exist.static JPropertyParseMonadType<java.time.OffsetDateTime>parseOffsetDateTime(java.util.Properties properties, java.lang.String key)Parse aOffsetDateTime.static JPropertyParseMonadType<java.time.OffsetDateTime>parseOffsetDateTimeWithDefault(java.util.Properties properties, java.lang.String key, java.time.OffsetDateTime defaultValue)Parse aOffsetDateTimereturning the default value if the key does not exist.static JPropertyParseMonadType<java.lang.String>parseString(java.util.Properties properties, java.lang.String key)Parse aString.static JPropertyParseMonadType<java.util.Optional<java.lang.String>>parseStringOptional(java.util.Properties properties, java.lang.String key)Parse aString.static JPropertyParseMonadType<java.lang.String>parseStringWithDefault(java.util.Properties properties, java.lang.String key, java.lang.String defaultValue)Parse aStringreturning the default value if the key does not exist.static JPropertyParseMonadType<java.net.URI>parseURI(java.util.Properties properties, java.lang.String key)Parse aURI.static JPropertyParseMonadType<java.net.URI>parseURIWithDefault(java.util.Properties properties, java.lang.String key, java.net.URI defaultValue)Parse aURIreturning the default value if the key does not exist.static JPropertyParseMonadType<java.util.UUID>parseUUID(java.util.Properties properties, java.lang.String key)Parse aUUID.static JPropertyParseMonadType<java.util.UUID>parseUUIDWithDefault(java.util.Properties properties, java.lang.String key, java.util.UUID defaultValue)Parse aUUIDreturning the default value if the key does not exist.static <T> JPropertyParseMonadType<T>successOf(T result)Trivially succeed.static JPropertyParseMonadType<JPropertyParseMonadType.Unit>warn(java.lang.String message)Publish a warning.static JPropertyParseMonadType<JPropertyParseMonadType.Unit>warn(java.lang.String key, java.lang.String message)Publish a warning.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
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 givenparserfunction 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 givenformatnames 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<java.util.Optional<T>> parseAnyOptional(java.util.Properties properties, java.lang.String key, java.lang.String format, JPropertyParsing.ParseFunctionType<T> parser)Parse anything. The givenparserfunction 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 givenformatnames 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(java.util.Properties properties, java.lang.String key, java.lang.String format, T defaultValue, JPropertyParsing.ParseFunctionType<T> parser)Parse anything. The givenparserfunction 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 givenformatnames 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<java.math.BigInteger> parseBigInteger(java.util.Properties properties, java.lang.String key)Parse aBigInteger.- Parameters:
properties- The propertieskey- 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 aBigIntegerreturning the default value if the key does not exist.- Parameters:
properties- The propertieskey- The keydefaultValue- The default value- Returns:
- A parse result
-
parseBoolean
public static JPropertyParseMonadType<java.lang.Boolean> parseBoolean(java.util.Properties properties, java.lang.String key)Parse aBoolean.- Parameters:
properties- The propertieskey- 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 aBooleanreturning the default value if the key does not exist.- Parameters:
properties- The propertieskey- The keydefaultValue- The default value- Returns:
- A parse result
-
parseString
public static JPropertyParseMonadType<java.lang.String> parseString(java.util.Properties properties, java.lang.String key)Parse aString.- Parameters:
properties- The propertieskey- 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 aString.- Parameters:
properties- The propertieskey- 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 aStringreturning 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<java.math.BigDecimal> parseBigDecimal(java.util.Properties properties, java.lang.String key)Parse aBigDecimal.- Parameters:
properties- The propertieskey- 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 aBigDecimalreturning the default value if the key does not exist.- Parameters:
properties- The propertieskey- The keydefaultValue- The default value- Returns:
- A parse result
-
parseURI
public static JPropertyParseMonadType<java.net.URI> parseURI(java.util.Properties properties, java.lang.String key)Parse aURI.- Parameters:
properties- The propertieskey- 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 aURIreturning the default value if the key does not exist.- Parameters:
properties- The propertieskey- The keydefaultValue- The default value- Returns:
- A parse result
-
parseUUID
public static JPropertyParseMonadType<java.util.UUID> parseUUID(java.util.Properties properties, java.lang.String key)Parse aUUID.- Parameters:
properties- The propertieskey- 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 aUUIDreturning the default value if the key does not exist.- Parameters:
properties- The propertieskey- The keydefaultValue- The default value- Returns:
- A parse result
-
parseDuration
public static JPropertyParseMonadType<java.time.Duration> parseDuration(java.util.Properties properties, java.lang.String key)Parse aDuration.- Parameters:
properties- The propertieskey- 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 aDurationreturning 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<java.time.OffsetDateTime> parseOffsetDateTime(java.util.Properties properties, java.lang.String key)Parse aOffsetDateTime.- Parameters:
properties- The propertieskey- 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 aOffsetDateTimereturning 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(java.lang.String key, java.lang.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<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
-