tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ple...@apache.org
Subject incubator-tamaya git commit: Removed the possibility to explicit provide a PropertyConverter to get a configuration value.
Date Wed, 15 Apr 2015 20:22:37 GMT
Repository: incubator-tamaya
Updated Branches:
  refs/heads/master d0deb9c06 -> a7d555c19


Removed the possibility to explicit provide a PropertyConverter to get a configuration value.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/a7d555c1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/a7d555c1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/a7d555c1

Branch: refs/heads/master
Commit: a7d555c198119eff9879c27b32aa6afd7f975d32
Parents: d0deb9c
Author: Oliver B. Fischer <plexus@apache.org>
Authored: Wed Apr 15 22:21:35 2015 +0200
Committer: Oliver B. Fischer <plexus@apache.org>
Committed: Wed Apr 15 22:21:35 2015 +0200

----------------------------------------------------------------------
 docs/API.adoc                                   | 20 ++------
 .../java/org/apache/tamaya/Configuration.java   | 13 -----
 .../org/apache/tamaya/TestConfiguration.java    |  5 --
 .../core/internal/DefaultConfiguration.java     |  5 --
 .../java/org/apache/tamaya/Configuration.java   | 54 --------------------
 .../org/apache/tamaya/ConfigurationTest.java    | 37 ++++++--------
 .../inject/internal/DefaultDynamicValue.java    | 12 +++--
 7 files changed, 28 insertions(+), 118 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a7d555c1/docs/API.adoc
----------------------------------------------------------------------
diff --git a/docs/API.adoc b/docs/API.adoc
index 286a198..acec6ed 100644
--- a/docs/API.adoc
+++ b/docs/API.adoc
@@ -196,7 +196,6 @@ public interface Configuration{
     String get(String key);
     <T> T get(String key, Class<T> type);
     <T> T get(String key, TypeLiteral<T> type);
-    <T> T get(String key, PropertyConverter<T> type);
     Map<String,String> getProperties();
 
     // extension points
@@ -207,10 +206,7 @@ public interface Configuration{
 
 Hereby
 
-* +<T> T get(String, Class<T>)+ provides type safe accessors for all basic wrapper
types of the JDK. Basically all this
-  methods delegate to the +get(String, PropertyConverter)+ method, additionally passing the
required +PropertyConverter+.
-* +get(String, PropertyConverter)+ allow accessing any type, hereby also passing a +PropertyConverter+
explicitly
-  that converts  the configured literal value to the type required.
+* +<T> T get(String, Class<T>)+ provides type safe accessors for all basic wrapper
types of the JDK.
 * +with, query+ provide the extension points for adding additional functionality.
 * +getProperties()+ provides access to all key/values, whereas entries from non scannable
property sources may not
   be included.
@@ -264,7 +260,6 @@ public interface Configuration{
     String get(String key);
     <T> T get(String key, Class<T> type);
     <T> T get(String key, TypeLiteral<T> type);
-    <T> T get(String key, PropertyConverter<T> type);
     Map<String,String> getProperties();
     Configuration with(ConfigOperator operator);
     <T> T query(ConfigQuery<T> query);
@@ -273,7 +268,6 @@ public interface Configuration{
     default Optional<String> getOptional(String key){...}
     default <T> Optional<T> getOptional(String key, Class<T> type){...}
     default <T> Optional<T> getOptional(String key, TypeLiteral<T> type){...}
-    default <T> Optional<T> getOptional(String key, PropertyConverter<T>
converter){...}
 
     default Boolean getBoolean(String key){...}
     default OptionalInt getInteger(String key){...}
@@ -286,10 +280,9 @@ Hereby
 
 * +get(String)+ and +getOptional(String)+ provide easy access to any kind of configuration
properties in their
   String format.
-* +get(String, TypeLiteral)+, +getOptional(String, TypeLiteral)+, +get(String, Class), getOptional(String,
Class)+ and
-  +getOptional(String, PropertyConverter)+ provide type safe access to configuration properties.
If a
-  +PropertyConverter+ is passed, it will replace any predefined standard
-  converters defined for the type. By default several +PropertyConverter+ instances can be
registered for a given
+* +get(String, TypeLiteral)+, +getOptional(String, TypeLiteral)+, +get(String, Class)+ and
+  +getOptional(String, Class)+ provide type safe access to configuration properties.
+  +PropertyConverter+ instances can be registered for a given
   target type. The are managed in an ordered list, whereas the ordering is defined by +@Priority+
annotations
   on the converters.
 * +getProperties()+ gives access to all known (=scannable) properties.
@@ -326,11 +319,6 @@ public interface PropertyConverter<T>{
 a configuration String value is passed to all registered converters for a type in order of
their annotated +@Priority+
 value. The first non-null result of a converter is then returned as the current configuration
value.
 
-Also worth mentioning is the fact, that the +PropertyConverter+ to be used can also be explicitly
defined, when
-a configuration value is accessed, by using the methods
-+<T> Optional<T> Configuration#getOptional(String, PropertyConverter<T>
converter)+ (Java 8 only) and
-+<T> T Configuration#get(String, PropertyConverter<T> converter)+.
-
 Access to converters is provided by the current +ConfigurationContext+, which is accessible
from
 the +ConfigurationProvider+ singleton.
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a7d555c1/java7/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/Configuration.java b/java7/api/src/main/java/org/apache/tamaya/Configuration.java
index 3d06f6e..6d30d0b 100644
--- a/java7/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/java7/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -75,19 +75,6 @@ public interface Configuration {
     <T> T get(String key, TypeLiteral<T> type);
 
     /**
-     * Get the property keys as type T. This will implicitly require a corresponding {@link
-     * PropertyConverter} to be available that is capable current providing type T
-     * fromMap the given String keys.
-     *
-     * @param key          the property's absolute, or relative path, e.g. @code
-     *                     a/b/c/d.myProperty}.
-     * @param converter         The target converter to be used, not null.
-     * @return the property value, never null..
-     * @throws ConfigException if the keys could not be converted to the required target
type.
-     */
-    <T> T get(String key, PropertyConverter<T> converter);
-
-    /**
      * Access all current known Configuration properties as a full {@code Map<String,String>}.
      * Be aware that entries from non scannable parts of the registered {@link org.apache.tamaya.spi.PropertySource}
      * instances may not be contained in the result, but nevertheless be accessible calling
one of the

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a7d555c1/java7/api/src/test/java/org/apache/tamaya/TestConfiguration.java
----------------------------------------------------------------------
diff --git a/java7/api/src/test/java/org/apache/tamaya/TestConfiguration.java b/java7/api/src/test/java/org/apache/tamaya/TestConfiguration.java
index 0f19665..31de765 100644
--- a/java7/api/src/test/java/org/apache/tamaya/TestConfiguration.java
+++ b/java7/api/src/test/java/org/apache/tamaya/TestConfiguration.java
@@ -85,11 +85,6 @@ public class TestConfiguration implements Configuration{
     }
 
     @Override
-    public <T> T get(String key, PropertyConverter<T> converter) {
-        throw new RuntimeException("Method not implemented yet.");
-    }
-
-    @Override
     public Configuration with(ConfigOperator operator) {
         return null;
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a7d555c1/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
index c30c049..754afb2 100644
--- a/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
+++ b/java7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
@@ -256,11 +256,6 @@ public class DefaultConfiguration implements Configuration {
         return null;
     }
 
-    @Override
-    public <T> T get(String key, PropertyConverter<T> converter) {
-        return null;
-    }
-
     public Configuration with(ConfigOperator operator) {
         return operator.operate(this);
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a7d555c1/java8/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/Configuration.java b/java8/api/src/main/java/org/apache/tamaya/Configuration.java
index 468e9e1..6de3cb6 100644
--- a/java8/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/java8/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -20,7 +20,6 @@ package org.apache.tamaya;
 
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.Optional;
 import java.util.OptionalDouble;
 import java.util.OptionalInt;
@@ -152,32 +151,6 @@ public interface Configuration {
     }
 
     /**
-     * Get the property keys as type {@code Class<T>}.
-     * <p>
-     * If {@code Class<T>} is not one current
-     * {@code Boolean, Short, Integer, Long, Float, Double, BigInteger,
-     * BigDecimal, String} , an according converter must be
-     * available to perform the conversion fromMap {@link String} to
-     * {@code Class<T>}.
-     *
-     * @param key       the property's absolute, or relative path, e.g. @code
-     *                  a/b/c/d.myProperty}.
-     * @param converter the PropertyConverter to perform the conversion fromMap
-     *                  {@link String} to {@code Class<T>}, not {@code null}.
-     * @param <T>       the target type.
-     * @return the property's keys.
-     * @throws ConfigException if the keys could not be converted to the required target
-     *                         type, or no such property exists.
-     */
-    default <T> T get(String key, PropertyConverter<T> converter) {
-        String value = get(key);
-        if (value != null) {
-            return Objects.requireNonNull(converter).convert(value);
-        }
-        return null;
-    }
-
-    /**
      * Access all current known Configuration properties as a full {@code Map<String,String>}.
      * Be aware that entries from non scannable parts of the registered {@link org.apache.tamaya.spi.PropertySource}
      * instances may not be contained in the result, but nevertheless be accessible calling
one of the
@@ -189,33 +162,6 @@ public interface Configuration {
     @SuppressWarnings("JavaDoc")
     Map<String, String> getProperties();
 
-    /**
-     * Get the property keys as type {@code Class<T>}.
-     * <p>
-     * If {@code Class<T>} is not one current
-     * {@code Boolean, Short, Integer, Long, Float, Double, BigInteger,
-     * BigDecimal, String} , an according converter must be
-     * available to perform the conversion fromMap {@link String} to
-     * {@code Class<T>}.
-     *
-     * @param key       the property's absolute, or relative path, e.g. @code
-     *                  a/b/c/d.myProperty}.
-     * @param converter the PropertyConverter to perform the conversion fromMap
-     *                  {@link String} to {@code Class<T>}, not {@code null}.
-     * @param <T>       the target type.
-     * @return the property's keys.
-     * @throws ConfigException if the keys could not be converted to the required target
-     *                         type, or no such property exists.
-     * @since Java8
-     */
-    default <T> Optional<T> getOptional(String key, PropertyConverter<T>
converter) {
-        Optional<String> value = getOptional(key);
-        if (value.isPresent()) {
-            return Optional.ofNullable(converter.convert(value.get()));
-        }
-        return Optional.empty();
-    }
-
 
     /**
      * Get the property keys as {@link Boolean}.

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a7d555c1/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java b/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
index bb0508d..8490455 100644
--- a/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
+++ b/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
@@ -18,6 +18,8 @@
  */
 package org.apache.tamaya;
 
+import org.junit.Test;
+
 import static org.junit.Assert.*;
 
 /**
@@ -26,18 +28,18 @@ import static org.junit.Assert.*;
  */
 public class ConfigurationTest {
 
-    @org.junit.Test
+    @Test
     public void testget() throws Exception {
-        assertEquals(Boolean.TRUE, ConfigurationProvider.getConfiguration().getOptional("booleanTrue",
(s) -> Boolean.valueOf(s)).get());
-        assertEquals(Boolean.FALSE, ConfigurationProvider.getConfiguration().getOptional("booleanFalse",
(s) -> Boolean.valueOf(s)).get());
-        assertEquals((int) Byte.MAX_VALUE, (int) ConfigurationProvider.getConfiguration().getOptional("byte",
(s) -> Byte.valueOf(s)).get());
-        assertEquals((int) Integer.MAX_VALUE, (int) ConfigurationProvider.getConfiguration().getOptional("int",
(s) -> Integer.valueOf(s)).get());
-        assertEquals((long) Long.MAX_VALUE, (long) ConfigurationProvider.getConfiguration().getOptional("long",
(s) -> Long.valueOf(s)).get());
-        assertEquals((double) Float.MAX_VALUE, (double) ConfigurationProvider.getConfiguration().getOptional("float",
(s) -> Float.valueOf(s)).get(), 0.0d);
-        assertEquals((double) Double.MAX_VALUE, (double) ConfigurationProvider.getConfiguration().getOptional("double",
(s) -> Double.valueOf(s)).get(), 0.0d);
+        assertEquals(Boolean.TRUE, ConfigurationProvider.getConfiguration().getOptional("booleanTrue",
Boolean.class).get());
+        assertEquals(Boolean.FALSE, ConfigurationProvider.getConfiguration().getOptional("booleanFalse",
Boolean.class).get());
+        assertEquals((int) Byte.MAX_VALUE, (int) ConfigurationProvider.getConfiguration().getOptional("byte",
Byte.class).get());
+        assertEquals((int) Integer.MAX_VALUE, (int) ConfigurationProvider.getConfiguration().getOptional("int",
Integer.class).get());
+        assertEquals((long) Long.MAX_VALUE, (long) ConfigurationProvider.getConfiguration().getOptional("long",
Long.class).get());
+        assertEquals((double) Float.MAX_VALUE, (double) ConfigurationProvider.getConfiguration().getOptional("float",
Float.class).get(), 0.0d);
+        assertEquals((double) Double.MAX_VALUE, (double) ConfigurationProvider.getConfiguration().getOptional("double",
Double.class).get(), 0.0d);
     }
 
-    @org.junit.Test
+    @Test
     public void testGetBoolean() throws Exception {
         assertTrue(ConfigurationProvider.getConfiguration().getBoolean("booleanTrue").isPresent());
         assertTrue(ConfigurationProvider.getConfiguration().getBoolean("booleanFalse").isPresent());
@@ -46,35 +48,28 @@ public class ConfigurationTest {
         assertFalse(ConfigurationProvider.getConfiguration().getBoolean("fooBar").isPresent());
     }
 
-    @org.junit.Test
+    @Test
     public void testGetInteger() throws Exception {
         assertEquals(Integer.MAX_VALUE, ConfigurationProvider.getConfiguration().getInteger("int").getAsInt());
     }
 
-    @org.junit.Test
+    @Test
     public void testGetLong() throws Exception {
         assertEquals(Long.MAX_VALUE, ConfigurationProvider.getConfiguration().getLong("long").getAsLong());
     }
 
-    @org.junit.Test
+    @Test
     public void testGetDouble() throws Exception {
         assertEquals(Double.MAX_VALUE, ConfigurationProvider.getConfiguration().getDouble("double").getAsDouble(),
0.0d);
     }
 
-    @org.junit.Test
+    @Test
     public void testWith() throws Exception {
         assertEquals(ConfigurationProvider.getConfiguration(), ConfigurationProvider.getConfiguration().with(c
-> c));
     }
 
-    @org.junit.Test
+    @Test
     public void testQuery() throws Exception {
         assertEquals("myFooResult", ConfigurationProvider.getConfiguration().query(c ->
"myFooResult"));
     }
-
-    @org.junit.Test
-    public void testGetAdapted() throws Exception {
-        assertEquals("yes", ConfigurationProvider.getConfiguration().getOptional("booleanTrue",
(v) -> Boolean.parseBoolean(v) ? "yes" : "no").get());
-        assertEquals("no", ConfigurationProvider.getConfiguration().getOptional("booleanFalse",
(v) -> Boolean.parseBoolean(v) ? "yes" : "no").get());
-    }
-
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a7d555c1/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
index dd5684b..0af7aa8 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
@@ -314,18 +314,22 @@ public final class DefaultDynamicValue<T> implements DynamicValue<T>,
Serializab
      * @return the current actual value, or null.
      */
     public T evaluateValue() {
+        T value = null;
+
         for (String key : keys) {
-            T value;
             if (propertyConverter == null) {
                 value = configuration.get(key, targetType);
             } else {
-                value = configuration.get(key, propertyConverter);
+                String source = configuration.get(key);
+                value = propertyConverter.convert(source);
             }
+
             if (value != null) {
-                return value;
+                break;
             }
         }
-        return null;
+
+        return value;
     }
 
     /**


Mime
View raw message