Module ultimategdbot.api
Interface PropertyReader
-
public interface PropertyReader
Allows to read values from an abstracted source of properties.
-
-
Field Summary
Fields Modifier and Type Field Description static PropertyReader
EMPTY
APropertyReader
that doesn't contain any property.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static PropertyReader
fromProperties(Properties props)
Creates a newPropertyReader
reading properties from the givenProperties
object.static reactor.core.publisher.Mono<PropertyReader>
fromPropertiesFile(Path path)
Reads the properties from a Java properties file located at the givenPath
.String
read(String key)
Reads a value associated with the given key.<T> T
readAs(String key, Function<? super String,? extends T> mapper)
Reads the value associated with the given key and maps it to an object via the given function.Stream<String>
readAsStream(String key, String separator)
Reads the value as a stream of values, each element being separated with a separator character.Optional<String>
readOptional(String key)
Reads a value associated with the given key, if present.Properties
toJdkProperties()
Converts thisPropertyReader
into a JDKProperties
object.
-
-
-
Field Detail
-
EMPTY
static final PropertyReader EMPTY
APropertyReader
that doesn't contain any property.
-
-
Method Detail
-
read
String read(String key)
Reads a value associated with the given key. If no value is present,NoSuchElementException
is thrown.- Parameters:
key
- the configuration key- Returns:
- the value associated with the key,
- Throws:
NoSuchElementException
- if no value is present
-
readAs
<T> T readAs(String key, Function<? super String,? extends T> mapper)
Reads the value associated with the given key and maps it to an object via the given function. If no value is present,NoSuchElementException
is thrown.- Type Parameters:
T
- the type of object to map the value to- Parameters:
key
- the configuration keymapper
- the function that maps the read value into an object- Returns:
- the object produced from the read value
-
readOptional
Optional<String> readOptional(String key)
Reads a value associated with the given key, if present.- Parameters:
key
- the configuration key- Returns:
- the value associated with the key, if present
-
readAsStream
Stream<String> readAsStream(String key, String separator)
Reads the value as a stream of values, each element being separated with a separator character. Let's say the value of the configuration entry "foo" is formatted as:bar:test:demon:hamburger
Calling this method this way:readAsStream("foo", ":", String::toString);
would return a Stream with the following elements:["bar", "test", "demon", "hamburger"]
- Parameters:
key
- the configuration keyseparator
- the character (or sequence of characters) that separates the elements in the raw string. Note that this is actually a regex as this parameter is directly passed to theString.split(String)
method internally. So characters like $ or | should be properly escaped- Returns:
- a Stream containing all elements
-
toJdkProperties
Properties toJdkProperties()
Converts thisPropertyReader
into a JDKProperties
object. Modifications to the properties object will not be reflected to this property reader.- Returns:
- a
Properties
object containing same data as thisPropertyReader
.
-
fromProperties
static PropertyReader fromProperties(Properties props)
Creates a newPropertyReader
reading properties from the givenProperties
object.- Parameters:
props
- theProperties
object to read- Returns:
- a new
PropertyReader
-
fromPropertiesFile
static reactor.core.publisher.Mono<PropertyReader> fromPropertiesFile(Path path)
Reads the properties from a Java properties file located at the givenPath
.- Parameters:
path
- the path where the properties file is located- Returns:
- a Mono emitting a PropertyReader backed by the properties read from file
-
-