Skip to content

Commit a74f35c

Browse files
committed
Updates according to findings when refactoring.
1 parent 9783b54 commit a74f35c

1 file changed

Lines changed: 16 additions & 18 deletions

File tree

docs-internal/config-api.md

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,26 @@ This is caused by:
4343
1. asOptionalBooleanSupplier()
4444

4545
#### Proposal
46-
Create a typed config value `Config.Value<T>` (requires the @Value to be moved as part of "Java Beans") that
47-
would be returned by typed methods.
46+
Create a typed config value `ConfigValue<T>`.
4847
This would leave config with the following accessor methods:
4948
1. Required:
50-
1. `Value<T> as(Class<? extends T> type) throws ConfigMappingException`
51-
2. `Value<List<T>> asList(Class<? extends T> type) throws ConfigMappingException`
52-
3. `Value<Map<String, String>> asMap()`
49+
1. `ConfigValue<T> as(Class<? extends T> type) throws ConfigMappingException`
50+
2. `ConfigValue<List<T>> asList(Class<? extends T> type) throws ConfigMappingException`
51+
3. `ConfigValue<Map<String, String>> asMap()`
5352
2. Optional (shortcut):
54-
1. `T as(Class<? extends T> type, T defaultValue) throws ConfigMappingException`
55-
2. `Value<Config> asNode()`
56-
3. `Value<List<Config>> asNodeList()`
57-
4. `Value<Boolean> asBoolean() throws ConfigMappingException`
53+
2. `ConfigValue<Config> asNode()`
54+
3. `ConfigValue<List<Config>> asNodeList()`
55+
4. `ConfigValue<Boolean> asBoolean() throws ConfigMappingException`
5856
5. other shortcut methods for primitive types
5957

60-
The `Value` interface would have the following methods to access typed value (as supported in original API):
61-
1. `Optional<T> value()`
62-
2. `T get() throws MissingValueException`
63-
2. `T get(T defaultValue)`
64-
3. `Supplier<T> asSupplier()`
65-
4. `Supplier<T> asSupplier(T defaultValue)`
66-
5. `Supplier<Optional<T>> asOptionalSupplier()`
67-
6. and a shortcut method `void ifPresent(Consumer<? super T> consumer)`
58+
The `ConfigValue` interface would have the following methods to access typed value (as supported in original API):
59+
1. `Optional<T> asOptional()` - to get the "real" Optional value
60+
3. `Supplier<T> asSupplier()` - supplier of current value (if config changes)
61+
4. `Supplier<T> asSupplier(T defaultValue)` - supplier of current value with default
62+
5. `Supplier<Optional<T>> asOptionalSupplier()` - supplier of current value as an optional
63+
2. `T get() throws MissingValueException` - same as in java.util.Optional, just throws a different exception
64+
6. and all methods of java.util.Optional<T> (unfortunatelly optional is a final class, so we have no choice but to copy
65+
the methods) - including the methods from java9+ (stream(), ifPresentOrElse(), or())
6866

6967
Example:
7068
```java
@@ -158,7 +156,7 @@ Add SPI to allow for such (more complex) config.as(AClass.class) transformation
158156
### No reflection as()
159157
Do not use reflection in T Config.as(Class<T> type) method. Currently there is a complicated
160158
code that introspects the class to find suitable constructor or factory method.
161-
Create a new method `T as(Function<Config, T> factoryMethod)`.
159+
Create a new method `ConfigValue<T> as(Function<Config, T> factoryMethod)`.
162160

163161
We can then use:
164162
```java

0 commit comments

Comments
 (0)