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 2016/07/15 14:56:27 UTC
incubator-tamaya git commit: - Added Java 8 based type support.
Repository: incubator-tamaya
Updated Branches:
refs/heads/tamaya-next 434689876 -> 13fd04cc4
- Added Java 8 based type support.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/13fd04cc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/13fd04cc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/13fd04cc
Branch: refs/heads/tamaya-next
Commit: 13fd04cc4d2b03edc64ed67200511e4583e60228
Parents: 4346898
Author: anatole <an...@apache.org>
Authored: Fri Jul 15 16:56:20 2016 +0200
Committer: anatole <an...@apache.org>
Committed: Fri Jul 15 16:56:20 2016 +0200
----------------------------------------------------------------------
.../java/org/apache/tamaya/Configuration.java | 66 +++++++++++++++++++-
1 file changed, 65 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/13fd04cc/code/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/code/api/src/main/java/org/apache/tamaya/Configuration.java b/code/api/src/main/java/org/apache/tamaya/Configuration.java
index a0e83b6..580ec5e 100644
--- a/code/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/code/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -54,7 +54,71 @@ public interface Configuration {
* @param defaultValue value to be returned, if no value is present.
* @return the property's keys.
*/
- String getOrDefault(String key, String defaultValue);
+ default String getOrDefault(String key, final String defaultValue){
+ return getOrDefault(key, () -> defaultValue);
+ }
+
+ /**
+ * Access a property providing a value supplier called, if no configured value is available.
+ *
+ * @param key the property's key, not null.
+ * @param defaultValueSupplier value supplier to be called, if no value is present.
+ * @return the property value.
+ */
+ default String getOrDefault(String key, Supplier<String> defaultValueSupplier){
+ String value = get(key);
+ if(value==null){
+ return defaultValueSupplier.supply();
+ }
+ return value;
+ }
+
+ /**
+ * Access a typed property providing a conversion.
+ *
+ * @param key the property's key, not null.
+ * @param conversion the value conversion, called if a configured value is present for the given key,
+ * not null.
+ * @return the property value, or null, if no such value has been found.
+ */
+ default <T> T get(String key, Function<String,T> conversion){
+ String value = get(key);
+ if(value!=null){
+ return conversion.apply(value);
+ }
+ return null;
+ }
+
+ /**
+ * Access a typed property providing a conversion and a default value.
+ *
+ * @param key the property's key, not null.
+ * @param conversion the value conversion, called if a configured value is present for the given key,
+ * not null.
+ * @param defaultValue the default value to be returned, if no configured value has been found, including
+ * {@code null}.
+ * @return the property value, or null, if no such value has been found.
+ */
+ default <T> T getOrDefault(String key, Function<String,T> conversion, final T defaultValue){
+ return getOrDefault(key, conversion, () -> defaultValue);
+ }
+
+ /**
+ * Access a typed property providing a conversion and a default value supplier.
+ *
+ * @param key the property's key, not null.
+ * @param conversion the value conversion, called if a configured value is present for the given key,
+ * not null.
+ * @param defaultValueSupplier the default value supplier to be called, if no configured value has been found..
+ * @return the property value, or null, if no such value has been found.
+ */
+ default <T> T getOrDefault(String key, Function<String,T> conversion, Supplier<T> defaultValueSupplier){
+ String value = get(key);
+ if(value!=null){
+ return conversion.apply(value);
+ }
+ return defaultValueSupplier.supply();
+ }
/**
* Access all currently known configuration properties as a full {@code Map<String,String>}.