T - public interface Property<T>
extends java.util.function.Supplier<T>
PropertyRepository implementation normally implements some level of caching
to reduce the overhead of interpolating and converting values.
class MyService {
private final Property<String> prop;
MyService(PropertyRepository repository) {
prop = repository.get("foo.prop", String.class).orElse("defaultValue");
}
public void doSomething() {
String currentValue = prop.get();
}
}
| Modifier and Type | Interface and Description |
|---|---|
static interface |
Property.Subscription
Token returned when calling
subscribe(Consumer) or onChange(Consumer) through which change
notification can be unsubscribed. |
| Modifier and Type | Method and Description |
|---|---|
default void |
addListener(PropertyListener<T> listener)
Deprecated.
Use
subscribe(Consumer) instead |
T |
get()
Return the most recent value of the property.
|
java.lang.String |
getKey() |
default <S> Property<S> |
map(java.util.function.Function<T,S> mapper)
Create a new Property object that will map the current object's property value
to a new type.
|
default Property.Subscription |
onChange(java.util.function.Consumer<T> consumer)
Deprecated.
Use
subscribe(Consumer) instead. |
default Property<T> |
orElse(T defaultValue)
Create a new Property object that will return the specified defaultValue if
this object's property is not found.
|
default Property<T> |
orElseGet(java.lang.String key)
Create a new Property object that will fetch the property backed by the provided
key.
|
default void |
removeListener(PropertyListener<T> listener)
Deprecated.
Use the
Property.Subscription object returned by subscribe(Consumer) instead. |
default Property.Subscription |
subscribe(java.util.function.Consumer<T> consumer)
Subscribe for notification whenever the property value changes.
|
T get()
get in interface java.util.function.Supplier<T>@Deprecated default void addListener(PropertyListener<T> listener)
subscribe(Consumer) instead@Deprecated default void removeListener(PropertyListener<T> listener)
Property.Subscription object returned by subscribe(Consumer) instead.@Deprecated default Property.Subscription onChange(java.util.function.Consumer<T> consumer)
subscribe(Consumer) instead.default Property.Subscription subscribe(java.util.function.Consumer<T> consumer)
onChange(Consumer) should be called last when chaining properties
since the notification only applies to the state of the chained property
up until this point. Changes to subsequent Property objects returned from orElse(T)
or map(Function) will not trigger calls to this consumer.default Property<T> orElse(T defaultValue)
default Property<T> orElseGet(java.lang.String key)
default <S> Property<S> map(java.util.function.Function<T,S> mapper)
java.lang.String getKey()