Skip to content

Commit

Permalink
Apply formatter and import plugins.
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Cortez <[email protected]>
  • Loading branch information
radcortez committed Sep 24, 2020
1 parent 6c5aa18 commit 562ece3
Show file tree
Hide file tree
Showing 73 changed files with 1,473 additions and 1,363 deletions.
156 changes: 90 additions & 66 deletions api/src/main/java/org/eclipse/microprofile/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
* Additional reviews and feedback by Tomas Langer.
*/
package org.eclipse.microprofile.config;
import java.util.Arrays;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -60,9 +61,9 @@
*
* <pre>
* public void doSomething() {
* Config cfg = ConfigProvider.getConfig();
* String archiveUrl = cfg.getValue("my.project.archive.endpoint", String.class);
* Integer archivePort = cfg.getValue("my.project.archive.port", Integer.class);
* Config cfg = ConfigProvider.getConfig();
* String archiveUrl = cfg.getValue("my.project.archive.endpoint", String.class);
* Integer archivePort = cfg.getValue("my.project.archive.port", Integer.class);
* }
* </pre>
*
Expand All @@ -71,17 +72,17 @@
*
* <pre>
* public class MyService {
* &#064;Inject
* private Config config;
* &#064;Inject
* private Config config;
* }
* </pre>
*
* <p>
* See {@link #getValue(String, Class)} and {@link #getOptionalValue(String, Class)} for accessing a configured value.
*
* <p>
* Configured values can also be accessed via injection.
* See {@link org.eclipse.microprofile.config.inject.ConfigProperty} for more information.
* Configured values can also be accessed via injection. See
* {@link org.eclipse.microprofile.config.inject.ConfigProperty} for more information.
*
* @author <a href="mailto:[email protected]">Mark Struberg</a>
* @author <a href="mailto:[email protected]">Gerhard Petracek</a>
Expand All @@ -105,61 +106,70 @@ public interface Config {
String PROPERTY_EXPRESSIONS_ENABLED = "mp.config.property.expressions.enabled";

/**
* Return the resolved property value with the specified type for the
* specified property name from the underlying {@linkplain ConfigSource configuration sources}.
* Return the resolved property value with the specified type for the specified property name from the underlying
* {@linkplain ConfigSource configuration sources}.
* <p>
* The configuration value is not guaranteed to be cached by the implementation, and may be expensive
* to compute; therefore, if the returned value is intended to be frequently used, callers should consider storing
* rather than recomputing it.
* The configuration value is not guaranteed to be cached by the implementation, and may be expensive to compute;
* therefore, if the returned value is intended to be frequently used, callers should consider storing rather than
* recomputing it.
* <p>
* The result of this method is identical to the result of calling {@code getOptionalValue(propertyName, propertyType).get()}.
* In particular, If the given property name or the value element of this property does not exist,
* the {@link java.util.NoSuchElementException} is thrown. This method never returns {@code null}.
* The result of this method is identical to the result of calling
* {@code getOptionalValue(propertyName, propertyType).get()}. In particular, If the given property name or the
* value element of this property does not exist, the {@link java.util.NoSuchElementException} is thrown. This
* method never returns {@code null}.
*
* @param <T>
* The property type
* The property type
* @param propertyName
* The configuration property name
* The configuration property name
* @param propertyType
* The type into which the resolved property value should get converted
* The type into which the resolved property value should get converted
* @return the resolved property value as an instance of the requested type (not {@code null})
* @throws IllegalArgumentException if the property cannot be converted to the specified type
* @throws java.util.NoSuchElementException if the property is not defined or is defined as an empty string
* @throws IllegalArgumentException
* if the property cannot be converted to the specified type
* @throws java.util.NoSuchElementException
* if the property is not defined or is defined as an empty string
*/
<T> T getValue(String propertyName, Class<T> propertyType);

/**
* Return the {@link ConfigValue} for the specified property name from the underlying
* {@linkplain ConfigSource configuration source}. The lookup of the configuration is performed immediatily,
* meaning that calls to {@link ConfigValue} will always yeld the same results.
* Return the {@link ConfigValue} for the specified property name from the underlying {@linkplain ConfigSource
* configuration source}. The lookup of the configuration is performed immediatily, meaning that calls to
* {@link ConfigValue} will always yeld the same results.
* <p>
* The configuration value is not guaranteed to be cached by the implementation, and may be expensive
* to compute; therefore, if the returned value is intended to be frequently used, callers should consider storing
* rather than recomputing it.
* The configuration value is not guaranteed to be cached by the implementation, and may be expensive to compute;
* therefore, if the returned value is intended to be frequently used, callers should consider storing rather than
* recomputing it.
* <p>
* A {@link ConfigValue} is always returned even if a property name cannot be found. In this case, every method in
* {@link ConfigValue} returns {@code null} except for {@link ConfigValue#getName()}, which includes the original
* property name being looked up.
*
* @param propertyName The configuration property name
* @param propertyName
* The configuration property name
* @return the resolved property value as a {@link ConfigValue}
*/
ConfigValue getConfigValue(String propertyName);

/**
* Return the resolved property values with the specified type for the
* specified property name from the underlying {@linkplain ConfigSource configuration sources}.
* Return the resolved property values with the specified type for the specified property name from the underlying
* {@linkplain ConfigSource configuration sources}.
* <p>
* The configuration values are not guaranteed to be cached by the implementation, and may be expensive
* to compute; therefore, if the returned values are intended to be frequently used, callers should consider storing
* rather than recomputing them.
* The configuration values are not guaranteed to be cached by the implementation, and may be expensive to compute;
* therefore, if the returned values are intended to be frequently used, callers should consider storing rather than
* recomputing them.
*
* @param <T> The property type
* @param propertyName The configuration property name
* @param propertyType The type into which the resolved property values should get converted
* @param <T>
* The property type
* @param propertyName
* The configuration property name
* @param propertyType
* The type into which the resolved property values should get converted
* @return the resolved property values as a list of instances of the requested type
* @throws java.lang.IllegalArgumentException if the property values cannot be converted to the specified type
* @throws java.util.NoSuchElementException if the property isn't present in the configuration
* @throws java.lang.IllegalArgumentException
* if the property values cannot be converted to the specified type
* @throws java.util.NoSuchElementException
* if the property isn't present in the configuration
*/
default <T> List<T> getValues(String propertyName, Class<T> propertyType) {
@SuppressWarnings("unchecked")
Expand All @@ -168,38 +178,46 @@ default <T> List<T> getValues(String propertyName, Class<T> propertyType) {
}

/**
* Return the resolved property value with the specified type for the
* specified property name from the underlying {@linkplain ConfigSource configuration sources}.
* Return the resolved property value with the specified type for the specified property name from the underlying
* {@linkplain ConfigSource configuration sources}.
* <p>
* The configuration value is not guaranteed to be cached by the implementation, and may be expensive
* to compute; therefore, if the returned value is intended to be frequently used, callers should consider storing
* rather than recomputing it.
* The configuration value is not guaranteed to be cached by the implementation, and may be expensive to compute;
* therefore, if the returned value is intended to be frequently used, callers should consider storing rather than
* recomputing it.
* <p>
* If this method is used very often then consider to locally store the configured value.
*
* @param <T> The property type
* @param propertyName The configuration property name
* @param propertyType The type into which the resolved property value should be converted
* @param <T>
* The property type
* @param propertyName
* The configuration property name
* @param propertyType
* The type into which the resolved property value should be converted
* @return The resolved property value as an {@code Optional} wrapping the requested type
*
* @throws IllegalArgumentException if the property cannot be converted to the specified type
* @throws IllegalArgumentException
* if the property cannot be converted to the specified type
*/
<T> Optional<T> getOptionalValue(String propertyName, Class<T> propertyType);

/**
* Return the resolved property values with the specified type for the
* specified property name from the underlying {@linkplain ConfigSource configuration sources}.
* Return the resolved property values with the specified type for the specified property name from the underlying
* {@linkplain ConfigSource configuration sources}.
* <p>
* The configuration values are not guaranteed to be cached by the implementation, and may be expensive
* to compute; therefore, if the returned values are intended to be frequently used, callers should consider storing
* rather than recomputing them.
* The configuration values are not guaranteed to be cached by the implementation, and may be expensive to compute;
* therefore, if the returned values are intended to be frequently used, callers should consider storing rather than
* recomputing them.
*
* @param <T> The property type
* @param propertyName The configuration property name
* @param propertyType The type into which the resolved property values should be converted
* @param <T>
* The property type
* @param propertyName
* The configuration property name
* @param propertyType
* The type into which the resolved property values should be converted
* @return The resolved property values as an {@code Optional} wrapping a list of the requested type
*
* @throws java.lang.IllegalArgumentException if the property cannot be converted to the specified type
* @throws java.lang.IllegalArgumentException
* if the property cannot be converted to the specified type
*/
default <T> Optional<List<T>> getOptionalValues(String propertyName, Class<T> propertyType) {
@SuppressWarnings("unchecked")
Expand All @@ -216,8 +234,8 @@ default <T> Optional<List<T>> getOptionalValues(String propertyName, Class<T> pr
* There is no guarantee about the completeness or currency of the names returned, nor is there any guarantee that a
* name that is returned by the iterator will resolve to a non-empty value or be found in any configuration source
* associated with the configuration; for example, it is allowed for this method to return an empty set always.
* However, the implementation <em>should</em> return a set of names that is useful to a
* user that wishes to browse the configuration.
* However, the implementation <em>should</em> return a set of names that is useful to a user that wishes to browse
* the configuration.
* <p>
* It is implementation-defined whether the returned names reflect a point-in-time "snapshot" of names, or an
* aggregation of multiple point-in-time "snapshots", or a more dynamic view of the available property names.
Expand All @@ -236,19 +254,22 @@ default <T> Optional<List<T>> getOptionalValues(String propertyName, Class<T> pr
* Return all of the currently registered {@linkplain ConfigSource configuration sources} for this configuration.
* <p>
* The returned sources will be sorted by descending ordinal value and name, which can be iterated in a thread-safe
* manner. The {@link java.lang.Iterable Iterable} contains a fixed number of {@linkplain ConfigSource configuration sources},
* determined at application start time, and the config sources themselves may be static or dynamic.
* manner. The {@link java.lang.Iterable Iterable} contains a fixed number of {@linkplain ConfigSource configuration
* sources}, determined at application start time, and the config sources themselves may be static or dynamic.
*
* @return the configuration sources
*/
Iterable<ConfigSource> getConfigSources();

/**
* Return the {@link Converter} used by this instance to produce instances of the specified type from string values.
*
* @param <T> the conversion type
* @param forType the type to be produced by the converter
* @param <T>
* the conversion type
* @param forType
* the type to be produced by the converter
* @return an {@link Optional} containing the converter, or empty if no converter is available for the specified
* type
* type
*/
<T> Optional<Converter<T>> getConverter(Class<T> forType);

Expand All @@ -260,10 +281,13 @@ default <T> Optional<List<T>> getOptionalValues(String propertyName, Class<T> pr
* <p>
* Unwraping to the provider specific API may lead to non-portable behaviour.
*
* @param type Class representing the type to unwrap to
* @param <T> The type to unwrap to
* @param type
* Class representing the type to unwrap to
* @param <T>
* The type to unwrap to
* @return An instance of the given type
* @throws IllegalArgumentException If the current provider does not support unwrapping to the given type
* @throws IllegalArgumentException
* If the current provider does not support unwrapping to the given type
*/
<T> T unwrap(Class<T> type);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@
* A {@link Config} provides access to the application's configuration. It may have been automatically discovered, or
* manually created and registered.
* <p>
* The default usage is to use {@link #getConfig()} to automatically pick up the
* <em>configuration</em> for the current thread's {@linkplain Thread#getContextClassLoader() context class loader}.
* The default usage is to use {@link #getConfig()} to automatically pick up the <em>configuration</em> for the current
* thread's {@linkplain Thread#getContextClassLoader() context class loader}.
* <p>
* A <em>configuration</em> consists of information collected from the registered
* <em>{@linkplain org.eclipse.microprofile.config.spi.ConfigSource configuration sources}</em>, combined with the set
* of registered {@linkplain org.eclipse.microprofile.config.spi.Converter converters}.
* The <em>configuration sources</em> get sorted according to their
* <em>{@linkplain org.eclipse.microprofile.config.spi.ConfigSource#getOrdinal() ordinal value}</em>.
* Thus it is possible to override a lower-priority <em>configuration source</em> with a higher-priority one.
* of registered {@linkplain org.eclipse.microprofile.config.spi.Converter converters}. The <em>configuration
* sources</em> get sorted according to their
* <em>{@linkplain org.eclipse.microprofile.config.spi.ConfigSource#getOrdinal() ordinal value}</em>. Thus it is
* possible to override a lower-priority <em>configuration source</em> with a higher-priority one.
* <p>
* It is also possible to register custom <em>configuration sources</em> to flexibly
* extend the configuration mechanism. For example, a configuration source could be provided which reads
* configuration values from a database table.
* It is also possible to register custom <em>configuration sources</em> to flexibly extend the configuration mechanism.
* For example, a configuration source could be provided which reads configuration values from a database table.
*
* <p>
* Example:
*
* <pre>
* String restUrl = ConfigProvider.getConfig().getValue(&quot;myproject.some.remote.service.url&quot;, String.class);
* Integer port = ConfigProvider.getConfig().getValue(&quot;myproject.some.remote.service.port&quot;, Integer.class);
Expand All @@ -71,8 +71,8 @@ private ConfigProvider() {
}

/**
* Get the {@linkplain Config configuration} corresponding to the current application, as defined by the
* calling thread's {@linkplain Thread#getContextClassLoader() context class loader}.
* Get the {@linkplain Config configuration} corresponding to the current application, as defined by the calling
* thread's {@linkplain Thread#getContextClassLoader() context class loader}.
* <p>
* The {@link Config} instance will be created and registered to the context class loader if no such configuration
* is already created and registered.
Expand All @@ -88,12 +88,13 @@ public static Config getConfig() {
/**
* Get the {@linkplain Config configuration} for the application corresponding to the given class loader instance.
* <p>
* The {@link Config} instance will be created and registered to the given class loader if no such configuration
* is already created and registered.
* The {@link Config} instance will be created and registered to the given class loader if no such configuration is
* already created and registered.
* <p>
* Each class loader corresponds to exactly one configuration.
*
* @param cl the Classloader used to register the configuration instance
* @param cl
* the Classloader used to register the configuration instance
* @return the configuration instance for the given class loader
*/
public static Config getConfig(ClassLoader cl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public interface ConfigValue {
/**
* The {@link org.eclipse.microprofile.config.spi.ConfigSource} ordinal that loaded the property lookup.
*
* @return the ConfigSource ordinal that loaded the property lookup or {@code 0} if the property could not be
* found
* @return the ConfigSource ordinal that loaded the property lookup or {@code 0} if the property could not be found
*/
int getSourceOrdinal();
}
Loading

0 comments on commit 562ece3

Please sign in to comment.