You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2015/03/18 00:49:14 UTC

[2/6] incubator-tamaya git commit: Fixed test bugs. Added default method for ordinal evaluation.

Fixed test bugs.
Added default method for ordinal evaluation.


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

Branch: refs/heads/master
Commit: 3bd3fe71dff5bdd015ebe81edd25c6d23fa8a662
Parents: b8aa9e8
Author: anatole <an...@apache.org>
Authored: Wed Mar 4 01:08:29 2015 +0100
Committer: anatole <an...@apache.org>
Committed: Wed Mar 4 01:08:29 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/tamaya/Configuration.java   | 21 ++++++++++++++++----
 .../org/apache/tamaya/spi/PropertySource.java   | 16 +++++++++++++--
 .../org/apache/tamaya/ConfigurationTest.java    |  8 +++++---
 .../org/apache/tamaya/TestConfiguration.java    |  4 ++--
 4 files changed, 38 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3bd3fe71/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 afaced9..468e9e1 100644
--- a/java8/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/java8/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -67,6 +67,7 @@ public interface Configuration {
      * @param key  the property's absolute, or relative path, e.g. @code
      *             a/b/c/d.myProperty}.
      * @param type The target type required, not null.
+     * @param <T>  the target type.
      * @return the property value, never null..
      * @throws ConfigException if the keys could not be converted to the required target type.
      */
@@ -82,6 +83,7 @@ public interface Configuration {
      * @param key  the property's absolute, or relative path, e.g. @code
      *             a/b/c/d.myProperty}.
      * @param type The target type required, not null.
+     * @param <T>  the target type.
      * @return the property value, or null, if the underlying value is null as well.
      * @throws ConfigException if the value could not be converted to the required target type by any of the
      *                         registered converters.
@@ -125,6 +127,7 @@ public interface Configuration {
      * @param key  the property's absolute, or relative path, e.g. @code
      *             a/b/c/d.myProperty}.
      * @param type The target type required, not null.
+     * @param <T>  the target type.
      * @return the property value, never null..
      * @throws ConfigException if the keys could not be converted to the required target type.
      */
@@ -140,6 +143,7 @@ public interface Configuration {
      * @param key  the property's absolute, or relative path, e.g. @code
      *             a/b/c/d.myProperty}.
      * @param type The target type required, not null.
+     * @param <T>  the target type.
      * @return the property value, never null..
      * @throws ConfigException if the keys could not be converted to the required target type.
      */
@@ -160,6 +164,7 @@ public interface Configuration {
      *                  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.
@@ -177,6 +182,9 @@ public interface Configuration {
      * 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
      * {@code get(...)} methods.
+     *
+     * @return the current properties. These may not include all properties from non-scannable
+     * {@link org.apache.tamaya.spi.PropertySource}s.
      */
     @SuppressWarnings("JavaDoc")
     Map<String, String> getProperties();
@@ -194,9 +202,11 @@ public interface Configuration {
      *                  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);
@@ -214,11 +224,10 @@ public interface Configuration {
      *            a/b/c/d.myProperty}.
      * @return the property's keys.
      * @throws ConfigException if the configured value could not be converted to the target type.
+     * @since Java8
      */
-    default Boolean getBoolean(String key) {
-        Optional<Boolean> val = getOptional(key, Boolean.class);
-
-        return val.orElse(null);
+    default Optional<Boolean> getBoolean(String key) {
+        return getOptional(key, Boolean.class);
     }
 
     /**
@@ -228,6 +237,7 @@ public interface Configuration {
      *            a/b/c/d.myProperty}.
      * @return the property's keys.
      * @throws ConfigException if the configured value could not be converted to the target type.
+     * @since Java8
      */
     default OptionalInt getInteger(String key) {
         Optional<Integer> val = getOptional(key, Integer.class);
@@ -245,6 +255,7 @@ public interface Configuration {
      *            a/b/c/d.myProperty}.
      * @return the property's keys.
      * @throws ConfigException if the configured value could not be converted to the target type.
+     * @since Java8
      */
     default OptionalLong getLong(String key) {
         Optional<Long> val = getOptional(key, Long.class);
@@ -261,6 +272,7 @@ public interface Configuration {
      *            a/b/c/d.myProperty}.
      * @return the property's keys.
      * @throws ConfigException if the configured value could not be converted to the target type.
+     * @since Java8
      */
     default OptionalDouble getDouble(String key) {
 
@@ -286,6 +298,7 @@ public interface Configuration {
      * Query a configuration.
      *
      * @param query the query, never {@code null}.
+     * @param <T>       the target query result type.
      * @return the result
      */
     default <T> T query(ConfigQuery<T> query) {

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3bd3fe71/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java b/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
index 20e8b88..7212bd3 100644
--- a/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
+++ b/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
@@ -20,6 +20,8 @@ package org.apache.tamaya.spi;
 
 
 import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 
 /**
@@ -78,9 +80,19 @@ public interface PropertySource {
      * config-source, but all of them have ordinal 400 by default (and can be reordered in a fine-grained manner.</p>
      *
      * @return the 'importance' aka ordinal of the configured values. The higher, the more important.
-     * //X TODO think about making this a default method which returns default priority
      */
-    int getOrdinal();
+    default int getOrdinal(){
+        String configuredOrdinal = get(TAMAYA_ORDINAL);
+        if(configuredOrdinal!=null){
+            try{
+                return Integer.parseInt(configuredOrdinal);
+            } catch(Exception e){
+                Logger.getLogger(getClass().getName()).log(Level.WARNING, e,
+                        () -> "Configured Ordinal is not an int number: " + configuredOrdinal);
+            }
+        }
+        return 0;
+    }
 
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3bd3fe71/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 28d25ba..240caf0 100644
--- a/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
+++ b/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
@@ -39,9 +39,11 @@ public class ConfigurationTest {
 
     @org.junit.Test
     public void testGetBoolean() throws Exception {
-        assertTrue(ConfigurationProvider.getConfiguration().getBoolean("booleanTrue"));
-        assertFalse(ConfigurationProvider.getConfiguration().getBoolean("booleanFalse"));
-        assertFalse(ConfigurationProvider.getConfiguration().getBoolean("foorBar"));
+        assertTrue(ConfigurationProvider.getConfiguration().getBoolean("booleanTrue").isPresent());
+        assertTrue(ConfigurationProvider.getConfiguration().getBoolean("booleanFalse").isPresent());
+        assertFalse(ConfigurationProvider.getConfiguration().getBoolean("booleanFalse").get());
+        assertTrue(ConfigurationProvider.getConfiguration().getBoolean("booleanTrue").get());
+        assertFalse(ConfigurationProvider.getConfiguration().getBoolean("fooBar").isPresent());
     }
 
     @org.junit.Test

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3bd3fe71/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
----------------------------------------------------------------------
diff --git a/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java b/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
index 31500ae..ef7cccf 100644
--- a/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
+++ b/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
@@ -63,13 +63,13 @@ public class TestConfiguration implements Configuration {
         } else if (type.getType().equals(Boolean.class)) {
             if ("booleanTrue".equals(key)) {
                 return (T) (Object) Boolean.TRUE;
-            } else {
+            } else if ("booleanFalse".equals(key)) {
                 return (T) (Object) Boolean.FALSE;
             }
         } else if (type.getType().equals(String.class)) {
             return (T) (Object) "aStringValue";
         }
-        throw new ConfigException("No such property: " + key);
+        return null;
     }
 
     @Override