tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject [1/9] incubator-tamaya git commit: TAMAYA-49 make getOptional default interfaces
Date Wed, 07 Jan 2015 22:21:34 GMT
Repository: incubator-tamaya
Updated Branches:
  refs/heads/master 7985c039c -> 585167aa8


TAMAYA-49 make getOptional default interfaces


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

Branch: refs/heads/master
Commit: 3d6456d255eb741936d027afcd81b356c2b11168
Parents: b4bde92
Author: Mark Struberg <struberg@apache.org>
Authored: Tue Jan 6 23:34:54 2015 +0100
Committer: Mark Struberg <struberg@apache.org>
Committed: Wed Jan 7 23:17:58 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/tamaya/Configuration.java   | 16 ++++++-------
 .../org/apache/tamaya/TestConfiguration.java    | 25 ++++++++++----------
 .../core/internal/DefaultConfiguration.java     | 11 +++++----
 3 files changed, 26 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3d6456d2/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 d5bd4f7..b86c94f 100644
--- a/java8/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/java8/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -50,9 +50,7 @@ public interface Configuration {
      * @param key the property's key, not null.
      * @return the property's value or {@code null}.
      */
-    default String get(String key) {
-        return getOptional(key).orElse(null);
-    }
+    String get(String key);
 
     /**
      * Get the property keys as type T. This will implicitly require a corresponding {@link
@@ -65,9 +63,7 @@ public interface Configuration {
      * @return the property value, never null..
      * @throws ConfigException if the keys could not be converted to the required target
type.
      */
-    default <T> T get(String key, Class<T> type) {
-        return getOptional(key, type).orElse(null);
-    }
+    <T> T get(String key, Class<T> type);
 
     /**
      * Access a property.
@@ -75,7 +71,9 @@ public interface Configuration {
      * @param key the property's key, not null.
      * @return the property's keys.
      */
-    Optional<String> getOptional(String key);
+    default Optional<String> getOptional(String key) {
+        return Optional.ofNullable(get(key));
+    }
 
     /**
      * Get the property keys as type T. This will implicitly require a corresponding {@link
@@ -88,7 +86,9 @@ public interface Configuration {
      * @return the property value, never null..
      * @throws ConfigException if the keys could not be converted to the required target
type.
      */
-    <T> Optional<T> getOptional(String key, Class<T> type);
+    default <T> Optional<T> getOptional(String key, Class<T> type) {
+        return Optional.ofNullable(get(key, type));
+    }
 
     /**
      * Access all current known Configuration properties as a full {@code Map<String,String>}.

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3d6456d2/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 459cb9f..ac3b646 100644
--- a/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
+++ b/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
@@ -20,7 +20,6 @@ package org.apache.tamaya;
 
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Optional;
 
 /**
  * Test Configuration class, that is used to testdata the default methods provided by the
API.
@@ -42,40 +41,40 @@ public class TestConfiguration implements Configuration {
     }
 
     @Override
-    public Optional<String> getOptional(String key) {
-        return Optional.ofNullable(VALUES.get(key));
+    public String get(String key) {
+        return VALUES.get(key);
     }
 
     @Override
-    public <T> Optional<T> getOptional(String key, Class<T> type) {
+    public <T> T get(String key, Class<T> type) {
         if(type.equals(Long.class)){
-            return Optional.class.cast(Optional.ofNullable(Long.MAX_VALUE));
+            return (T)(Object)Long.MAX_VALUE;
         }
         else if(type.equals(Integer.class)){
-            return Optional.class.cast(Optional.ofNullable(Integer.MAX_VALUE));
+            return (T)(Object) Integer.MAX_VALUE;
         }
         else if(type.equals(Double.class)){
-            return Optional.class.cast(Optional.ofNullable(Double.MAX_VALUE));
+            return (T)(Object) Double.MAX_VALUE;
         }
         else if(type.equals(Float.class)){
-            return Optional.class.cast(Optional.ofNullable(Float.MAX_VALUE));
+            return (T)(Object) Float.MAX_VALUE;
         }
         else if(type.equals(Short.class)){
-            return Optional.class.cast(Optional.ofNullable(Short.MAX_VALUE));
+            return (T)(Object) Short.MAX_VALUE;
         }
         else if(type.equals(Byte.class)){
-            return Optional.class.cast(Optional.ofNullable(Byte.MAX_VALUE));
+            return (T)(Object) Byte.MAX_VALUE;
         }
         else if(type.equals(Boolean.class)){
             if("booleanTrue".equals(key)) {
-                return Optional.class.cast(Optional.ofNullable(Boolean.TRUE));
+                return (T)(Object) Boolean.TRUE;
             }
             else{
-                return Optional.class.cast(Optional.ofNullable(Boolean.FALSE));
+                return (T)(Object) Boolean.FALSE;
             }
         }
         else if(type.equals(String.class)){
-            return Optional.class.cast(Optional.ofNullable("aStringValue"));
+            return (T)(Object) "aStringValue";
         }
         throw new ConfigException("No such property: " + key);
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3d6456d2/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
index a0bf190..e862d02 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
@@ -68,7 +68,7 @@ public class DefaultConfiguration implements Configuration {
      * @return the optional configuration value, never null.
      */
     @Override
-    public Optional<String> getOptional(String key) {
+    public String get(String key) {
         List<PropertySource> propertySources = configurationContext.getPropertySources();
         String unfilteredValue = null;
         for (PropertySource propertySource : propertySources) {
@@ -78,7 +78,7 @@ public class DefaultConfiguration implements Configuration {
                 break;
             }
         }
-        return Optional.ofNullable(applyFilter(key, unfilteredValue));
+        return applyFilter(key, unfilteredValue);
     }
 
     /**
@@ -204,7 +204,7 @@ public class DefaultConfiguration implements Configuration {
      * @return the converted value, never null.
      */
     @Override
-    public <T> Optional<T> getOptional(String key, Class<T> type) {
+    public <T> T get(String key, Class<T> type) {
         Optional<String> value = getOptional(key);
         if (value.isPresent()) {
             List<PropertyConverter<T>> converters = configurationContext.getPropertyConverters(type);
@@ -212,7 +212,7 @@ public class DefaultConfiguration implements Configuration {
                 try {
                     T t = converter.convert(value.get());
                     if (t != null) {
-                        return Optional.of(t);
+                        return t;
                     }
                 } catch (Exception e) {
                     LOG.log(Level.FINEST, e, () -> "PropertyConverter: " + converter +
@@ -221,6 +221,7 @@ public class DefaultConfiguration implements Configuration {
             }
             throw new ConfigException("Unparseable config value for type: " + type.getName()
+ ": " + key);
         }
-        return Optional.empty();
+
+        return null;
     }
 }


Mime
View raw message