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 onChange through which change notification can be
unsubscribed.
|
| Modifier and Type | Method and Description |
|---|---|
default void |
addListener(PropertyListener<T> listener)
Deprecated.
|
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.
|
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.
|
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)
listener - @Deprecated default void removeListener(PropertyListener<T> listener)
listener - @Deprecated default Property.Subscription onChange(java.util.function.Consumer<T> consumer)
subscribe(Consumer)consumer - 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.consumer - default Property<T> orElse(T defaultValue)
defaultValue - default Property<T> orElseGet(java.lang.String key)
key - default <S> Property<S> map(java.util.function.Function<T,S> mapper)
delegate - java.lang.String getKey()