Skip to content

Commit

Permalink
refs: #70 remove ProjectStage from doc
Browse files Browse the repository at this point in the history
Also includes finishing the rename from ConfigValue to ConfigAccessor
  • Loading branch information
struberg committed Jun 28, 2018
1 parent e7a8986 commit 3e5ceef
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
5 changes: 3 additions & 2 deletions api/src/main/java/javax/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,14 @@ public interface Config {
*
* <pre>
* // get the current host value
* ConfigValue&lt;String&gt; hostCfg config.resolve("myapp.host")
* ConfigAccessor&lt;String&gt; hostCfg config.resolve("myapp.host")
* .cacheFor(60, TimeUnit.MINUTES);
*
* // and right inbetween the underlying values get changed to 'newserver' and port 8082
*
* // get the current port for the host
* ConfigValue&lt;Integer&gt; portCfg config.resolve("myapp.port")
* ConfigAccessor&lt;Integer&gt; portCfg config.resolve("myapp.port")
* .as(Integer.class)
* .cacheFor(60, TimeUnit.MINUTES);
* </pre>
*
Expand Down
16 changes: 8 additions & 8 deletions api/src/main/java/javax/config/ConfigAccessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public interface ConfigAccessor<T> {

/**
* Sets the type of the configuration entry to the given class and returns this builder.
* The default type of a ConfigValue is {@code String}.
* The default type of a ConfigAccessor is {@code String}.
*
* <p>Usage:
* <pre>
Expand All @@ -59,39 +59,39 @@ public interface ConfigAccessor<T> {
* </pre>
*
* Attention: this method should always be the first to be used and might
* return a new {@code ConfigValue} for the given target clazz.
* return a new {@code ConfigAccessor} for the given target clazz.
*
*
* @param clazz The target type
* @param <N> The target type
* @return This builder as a typed ConfigValue
* @return This builder as a typed ConfigAccessor
*/
<N> ConfigAccessor<N> as(Class<N> clazz);

/**
* Declare the ConfigValue to return a List of the given Type.
* Declare the ConfigAccessor to return a List of the given Type.
* When getting value it will be split on each comma (',') character.
* If a comma is contained in the values it must get escaped with a preceding backslash (&quot;\,&quot;).
* Any backslash needs to get escaped via double-backslash (&quot;\\&quot;).
* Note that in property files this leads to &quot;\\\\&quot; as properties escape themselves.
*
* @return a ConfigValue for a list of configured comma separated values
* @return a ConfigAccessor for a list of configured comma separated values
*/
ConfigAccessor<List<T>> asList();

/**
* Declare the ConfigValue to return a Set of the given Type.
* Declare the ConfigAccessor to return a Set of the given Type.
* The notation and escaping rules are the same like explained in {@link #asList()}
*
* @return a ConfigValue for a list of configured comma separated values
* @return a ConfigAccessor for a list of configured comma separated values
*/
ConfigAccessor<Set<T>> asSet();

/**
* Defines a {@link Converter} to be used instead of the default Converter resolving logic.
*
* @param converter The converter for the target type
* @return This builder as a typed ConfigValue
* @return This builder as a typed ConfigAccessor
*/
ConfigAccessor<T> useConverter(Converter<T> converter);

Expand Down
16 changes: 10 additions & 6 deletions spec/src/main/asciidoc/configaccessor.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,31 @@
== ConfigAccessor


The `ConfigValue` API is intended for typed configuration values and precise control over resolution.
The `ConfigAccessor` API is intended for typed configuration values and precise control over resolution.

=== ConfigAccessor Usage

The simplest usage of the API is resolution of a String property, equivalent to a call to `Config.getValue(propertyKey, String.class)`.
This can also be handled via `ConfigValue` as shown in the following example:
This can also be handled via `ConfigAccessor` as shown in the following example:

.Simple example of ConfigValue
.Simple example of ConfigAccessor
[source,java]
-----------------------------------------------------------------
String userName = config.access("user.name").getValue();
Config config = ConfigProvider.getConfig();
ConfigAccessor<Integer> ftpPortCfg = config.access("myapp.someftp.port")
.as(Integer.class);
...
Integer port = ftpPortCfg.getValue();
-----------------------------------------------------------------


The call to `Config.access(..)` returns a builder which has methods to refine the resolution, including the
The call to `config.access(..)` returns a builder which has methods to refine the resolution, including the
following:

* `as(Class<N> clazz)` -- defines the return type of the property
* `asList()` --
* `parameterizedBy(String propertyName)` -- sets a parameter for the resolution, similarly as in
<<_getpropertyawarepropertyvalue, ConfigResolver.getPropertyAwarePropertyValue>>
* `withCurrentProjectStage(boolean with)` -- indicates whether the current ProjectStage should be taken into account
for the resolution
* `strictly(boolean strictly)` -- indicates, whether the <<_property_value_resolution_sequence, property value
resolution sequence>> should be taken into account. When set to true, the sequence is not followed.
Expand Down

0 comments on commit 3e5ceef

Please sign in to comment.