Class PropertyNode
- java.lang.Object
-
- com.github.mizool.core.configuration.PropertyNode
-
- All Implemented Interfaces:
HasChildren
public final class PropertyNode extends Object implements HasChildren
An object that allows type-safe retrieval of property values and navigation to child properties.
-
-
Constructor Summary
Constructors Constructor Description PropertyNode(Properties properties, String key)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Value<BigDecimal>bigDecimalValue()Parses the property value as a big decimal.Value<Boolean>booleanValue()Parses the property value as a boolean.PropertyNodechild(String reference)Navigates to the given child node.<T> Value<T>convertedValue(Function<String,T> valueConversionFunction)Parses the property value using the given function.Value<Integer>intValue()Parses the property value as an integer.Value<Duration>isoDurationValue()Parses a string such asPT7HusingDuration.parse(CharSequence).Value<Period>isoPeriodValue()Parses a string such asP5Y12M7DusingPeriod.parse(CharSequence).Value<Long>longValue()Parses the property value as a long.Value<Path>pathValue()Interprets the property value as an absolute path.Value<Path>pathValue(Path basePath)Interprets the property value as a relative path for the given base path.Value<Duration>readableDuration()Parses a string such as30 seconds.Value<Stream<PropertyNode>>referencedNodes()Parses a comma-separated list of references and returns the respective property nodes.
Absolute and relative references
To increase readability of properties files, users can reference child nodes with a shortened syntax: if a reference starts with a '.', it is resolved starting with the current node (relative reference).Value<Stream<String>>stringsValue()Parses a comma-separated list of values.Value<String>stringValue()Gets the property value as a string.StringtoString()Value<Instant>unixTimestampValue()Parses a string containing the number of seconds from the epoch of 1970-01-01T00:00:00Z.Value<URL>urlValue()Parses the property value as an absolute URL.Value<URL>urlValue(URL context)Interprets the property value as a relative URL for the given context.Value<Instant>utcInstantValue()Parses a string such as2020-08-14T12:04:22.00ZusingDateTimeFormatter.ISO_INSTANT.Value<ZoneId>zoneIdValue()Parses a string such asEurope/BerlinusingZoneId.of(String).
-
-
-
Constructor Detail
-
PropertyNode
public PropertyNode(Properties properties, String key)
-
-
Method Detail
-
child
public PropertyNode child(String reference)
Navigates to the given child node.- Specified by:
childin interfaceHasChildren- Parameters:
reference- one or more segments of the key to append to the key of the current node- Returns:
- the child or descendant node, never
null.
-
stringValue
public Value<String> stringValue()
Gets the property value as a string.- Returns:
- the string
-
booleanValue
public Value<Boolean> booleanValue()
Parses the property value as a boolean.- Returns:
- the boolean
-
intValue
public Value<Integer> intValue()
Parses the property value as an integer.- Returns:
- the integer
-
bigDecimalValue
public Value<BigDecimal> bigDecimalValue()
Parses the property value as a big decimal.- Returns:
- the big decimal
-
pathValue
public Value<Path> pathValue()
Interprets the property value as an absolute path.- Returns:
- the absolute path
-
pathValue
public Value<Path> pathValue(Path basePath)
Interprets the property value as a relative path for the given base path.- Parameters:
basePath- the path the property value is relative to- Returns:
- the combined, absolute path
-
urlValue
public Value<URL> urlValue()
Parses the property value as an absolute URL.- Returns:
- the URL
-
urlValue
public Value<URL> urlValue(URL context)
Interprets the property value as a relative URL for the given context.- Parameters:
context- the URL the property value is relative to- Returns:
- the combined, absolute URL
-
unixTimestampValue
public Value<Instant> unixTimestampValue()
Parses a string containing the number of seconds from the epoch of 1970-01-01T00:00:00Z.- Returns:
- the instant
-
utcInstantValue
public Value<Instant> utcInstantValue()
Parses a string such as2020-08-14T12:04:22.00ZusingDateTimeFormatter.ISO_INSTANT.- Returns:
- the instant
-
readableDuration
public Value<Duration> readableDuration()
Parses a string such as30 seconds.- Returns:
- the duration
-
isoDurationValue
public Value<Duration> isoDurationValue()
Parses a string such asPT7HusingDuration.parse(CharSequence).- Returns:
- the duration
-
isoPeriodValue
public Value<Period> isoPeriodValue()
Parses a string such asP5Y12M7DusingPeriod.parse(CharSequence).- Returns:
- the period
-
zoneIdValue
public Value<ZoneId> zoneIdValue()
Parses a string such asEurope/BerlinusingZoneId.of(String).- Returns:
- the zone ID
-
stringsValue
public Value<Stream<String>> stringsValue()
Parses a comma-separated list of values. Empty and whitespace-only elements are skipped, and leading and trailing whitespace inside each value is removed.- Returns:
- the values
-
referencedNodes
public Value<Stream<PropertyNode>> referencedNodes()
Parses a comma-separated list of references and returns the respective property nodes.
Absolute and relative references
To increase readability of properties files, users can reference child nodes with a shortened syntax: if a reference starts with a '.', it is resolved starting with the current node (relative reference). Other references are resolved starting with the root node (absolute reference).
Whitespace
Whitespace is handled the same way asstringsValue().- Returns:
- the property nodes
-
convertedValue
public <T> Value<T> convertedValue(Function<String,T> valueConversionFunction)
Parses the property value using the given function.- Returns:
- the converted value
-
-