tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pottlin...@apache.org
Subject [10/50] [abbrv] incubator-tamaya-extensions git commit: TAMAYA-113: Added default getters: fixed implementations of Config.
Date Mon, 17 Oct 2016 18:55:22 GMT
TAMAYA-113: Added default getters: fixed implementations of Config.


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

Branch: refs/heads/master
Commit: 4fa9154a054e09cd9388df6d42ac0e0bcc092854
Parents: 25d1b3e
Author: anatole <anatole@apache.org>
Authored: Thu Oct 1 19:39:35 2015 +0200
Committer: Oliver B. Fischer <plexus@apache.org>
Committed: Tue Sep 27 00:18:31 2016 +0200

----------------------------------------------------------------------
 .../tamaya/events/FrozenConfiguration.java      | 27 ++++++++++++++++++++
 .../apache/tamaya/events/TestConfigView.java    | 27 ++++++++++++++++++++
 2 files changed, 54 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/4fa9154a/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java b/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
index 7afac7a..14c9b30 100644
--- a/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
+++ b/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
@@ -76,6 +76,24 @@ public final class FrozenConfiguration implements Configuration, Serializable
{
     }
 
     @Override
+    public String getOrDefault(String key, String defaultValue) {
+        String val = get(key);
+        if(val==null){
+            return defaultValue;
+        }
+        return val;
+    }
+
+    @Override
+    public <T> T getOrDefault(String key, Class<T> type, T defaultValue) {
+        T val = get(key, type);
+        if(val==null){
+            return defaultValue;
+        }
+        return val;
+    }
+
+    @Override
     public <T> T get(String key, Class<T> type) {
         return (T) get(key, TypeLiteral.of(type));
     }
@@ -116,6 +134,15 @@ public final class FrozenConfiguration implements Configuration, Serializable
{
     }
 
     @Override
+    public <T> T getOrDefault(String key, TypeLiteral<T> type, T defaultValue)
{
+        T val = get(key, type);
+        if(val==null){
+            return defaultValue;
+        }
+        return val;
+    }
+
+    @Override
     public Map<String, String> getProperties() {
         return properties;
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/4fa9154a/src/test/java/org/apache/tamaya/events/TestConfigView.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/events/TestConfigView.java b/src/test/java/org/apache/tamaya/events/TestConfigView.java
index 6ee5397..379f660 100644
--- a/src/test/java/org/apache/tamaya/events/TestConfigView.java
+++ b/src/test/java/org/apache/tamaya/events/TestConfigView.java
@@ -78,6 +78,24 @@ public class TestConfigView implements ConfigOperator{
             }
 
             @Override
+            public String getOrDefault(String key, String defaultValue) {
+                String val = get(key);
+                if(val==null){
+                    return defaultValue;
+                }
+                return val;
+            }
+
+            @Override
+            public <T> T getOrDefault(String key, Class<T> type, T defaultValue)
{
+                T val = get(key, type);
+                if(val==null){
+                    return defaultValue;
+                }
+                return val;
+            }
+
+            @Override
             public <T> T get(String key, Class<T> type) {
                 return (T) get(key, TypeLiteral.of(type));
             }
@@ -115,6 +133,15 @@ public class TestConfigView implements ConfigOperator{
                 }
                 return null;
             }
+
+            @Override
+            public <T> T getOrDefault(String key, TypeLiteral<T> type, T defaultValue)
{
+                T val = get(key, type);
+                if(val==null){
+                    return defaultValue;
+                }
+                return val;
+            }
         };
     }
 }


Mime
View raw message