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/11/12 00:32:55 UTC
incubator-tamaya-extensions git commit: TAMAYA-194: Factored out
ConfiguredItemSupplier,
replacing it with Supplier from the functs modul for impl and commented out
the methods in the API to avoid deps until Java 8 is available (which has a
supplier in t
Repository: incubator-tamaya-extensions
Updated Branches:
refs/heads/master 15fe93587 -> 0c9dc212e
TAMAYA-194: Factored out ConfiguredItemSupplier, replacing it with Supplier from the functs modul for impl and commented out the methods in the API to avoid deps until Java 8 is available (which has a supplier in the util.function package). Fixed checkstyle issues.
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/0c9dc212
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/0c9dc212
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/0c9dc212
Branch: refs/heads/master
Commit: 0c9dc212eb3e7562d8d735f14211f8c615d6fed8
Parents: 15fe935
Author: anatole <an...@apache.org>
Authored: Sat Nov 12 01:32:46 2016 +0100
Committer: anatole <an...@apache.org>
Committed: Sat Nov 12 01:32:46 2016 +0100
----------------------------------------------------------------------
.../inject/api/ConfiguredItemSupplier.java | 41 ---------
.../apache/tamaya/inject/api/DynamicValue.java | 59 ++++++-------
.../tamaya/inject/spi/BaseDynamicValue.java | 85 ++++++++++---------
.../tamaya/inject/ConfigurationInjector.java | 6 +-
.../internal/DefaultConfigurationInjector.java | 10 +--
.../internal/DefaultDynamicValueTest.java | 88 ++++++++++----------
.../LazyRefreshablePropertySource.java | 8 +-
.../tamaya/optional/OptionalConfiguration.java | 12 ++-
8 files changed, 141 insertions(+), 168 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0c9dc212/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfiguredItemSupplier.java
----------------------------------------------------------------------
diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfiguredItemSupplier.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfiguredItemSupplier.java
deleted file mode 100644
index 5e57121..0000000
--- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/ConfiguredItemSupplier.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.inject.api;
-
-/**
- * Represents a supplier of results.
- *
- * There is no requirement that a new or distinct result be returned each
- * time the supplier is invoked.
- *
- * This is a functional interface,
- * whose functional method is {@link #get()}.
- *
- * @param <T> the type of results supplied by this supplier
- */
-//@FunctionalInterface
-public interface ConfiguredItemSupplier<T> {
-
- /**
- * Gets a result.
- *
- * @return a result
- */
- T get();
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0c9dc212/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java
index 4cc29da..d56e29c 100644
--- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java
+++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java
@@ -128,34 +128,35 @@ public interface DynamicValue<T> {
*/
T orElse(T other);
- /**
- * Return the value if present, otherwise invoke {@code other} and return
- * the result of that invocation.
- *
- * @param other a {@code ConfiguredItemSupplier} whose result is returned if no value
- * is present
- * @return the value if present otherwise the result of {@code other.get()}
- * @throws NullPointerException if value is not present and {@code other} is
- * null
- */
- T orElseGet(ConfiguredItemSupplier<? extends T> other);
-
- /**
- * Return the contained value, if present, otherwise throw an exception
- * to be created by the provided supplier.
- *
- * NOTE A method reference to the exception constructor with an empty
- * argument list can be used as the supplier. For example,
- * {@code IllegalStateException::new}
- *
- * @param <X> Type of the exception to be thrown
- * @param exceptionSupplier The supplier which will return the exception to
- * be thrown
- * @return the present value
- * @throws X if there is no value present
- * @throws NullPointerException if no value is present and
- * {@code exceptionSupplier} is null
- */
- <X extends Throwable> T orElseThrow(ConfiguredItemSupplier<? extends X> exceptionSupplier) throws X;
+ // TODO enable with Java 8
+// /**
+// * Return the value if present, otherwise invoke {@code other} and return
+// * the result of that invocation.
+// *
+// * @param other a {@code ConfiguredItemSupplier} whose result is returned if no value
+// * is present
+// * @return the value if present otherwise the result of {@code other.get()}
+// * @throws NullPointerException if value is not present and {@code other} is
+// * null
+// */
+// T orElseGet(ConfiguredItemSupplier<? extends T> other);
+//
+// /**
+// * Return the contained value, if present, otherwise throw an exception
+// * to be created by the provided supplier.
+// *
+// * NOTE A method reference to the exception constructor with an empty
+// * argument list can be used as the supplier. For example,
+// * {@code IllegalStateException::new}
+// *
+// * @param <X> Type of the exception to be thrown
+// * @param exceptionSupplier The supplier which will return the exception to
+// * be thrown
+// * @return the present value
+// * @throws X if there is no value present
+// * @throws NullPointerException if no value is present and
+// * {@code exceptionSupplier} is null
+// */
+// <X extends Throwable> T orElseThrow(ConfiguredItemSupplier<? extends X> exceptionSupplier) throws X;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0c9dc212/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java
index 38703b2..f9e2079 100644
--- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java
+++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java
@@ -18,8 +18,6 @@
*/
package org.apache.tamaya.inject.spi;
-
-import org.apache.tamaya.inject.api.ConfiguredItemSupplier;
import org.apache.tamaya.inject.api.DynamicValue;
import java.io.Serializable;
@@ -82,46 +80,47 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T>, Serializab
return value;
}
- /**
- * Return the value if present, otherwise invoke {@code other} and return
- * the result of that invocation.
- *
- * @param other a {@code ConfiguredItemSupplier} whose result is returned if no value
- * is present
- * @return the value if present otherwise the result of {@code other.get()}
- * @throws NullPointerException if value is not present and {@code other} is
- * null
- */
- public T orElseGet(ConfiguredItemSupplier<? extends T> other) {
- T value = get();
- if (value == null) {
- return other.get();
- }
- return value;
- }
-
- /**
- * Return the contained value, if present, otherwise throw an exception
- * to be created by the provided supplier.
- * <p>
- * NOTE A method reference to the exception constructor with an empty
- * argument list can be used as the supplier. For example,
- * {@code IllegalStateException::new}
- *
- * @param <X> Type of the exception to be thrown
- * @param exceptionSupplier The supplier which will return the exception to
- * be thrown
- * @return the present value
- * @throws X if there is no value present
- * @throws NullPointerException if no value is present and
- * {@code exceptionSupplier} is null
- */
- public <X extends Throwable> T orElseThrow(ConfiguredItemSupplier<? extends X> exceptionSupplier) throws X {
- T value = get();
- if (value == null) {
- throw exceptionSupplier.get();
- }
- return value;
- }
+ // TODO: Enable with Java 8 support.
+// /**
+// * Return the value if present, otherwise invoke {@code other} and return
+// * the result of that invocation.
+// *
+// * @param other a {@code ConfiguredItemSupplier} whose result is returned if no value
+// * is present
+// * @return the value if present otherwise the result of {@code other.get()}
+// * @throws NullPointerException if value is not present and {@code other} is
+// * null
+// */
+// public T orElseGet(Supplier<? extends T> other) {
+// T value = get();
+// if (value == null) {
+// return other.get();
+// }
+// return value;
+// }
+//
+// /**
+// * Return the contained value, if present, otherwise throw an exception
+// * to be created by the provided supplier.
+// * <p>
+// * NOTE A method reference to the exception constructor with an empty
+// * argument list can be used as the supplier. For example,
+// * {@code IllegalStateException::new}
+// *
+// * @param <X> Type of the exception to be thrown
+// * @param exceptionSupplier The supplier which will return the exception to
+// * be thrown
+// * @return the present value
+// * @throws X if there is no value present
+// * @throws NullPointerException if no value is present and
+// * {@code exceptionSupplier} is null
+// */
+// public <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
+// T value = get();
+// if (value == null) {
+// throw exceptionSupplier.get();
+// }
+// return value;
+// }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0c9dc212/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java
index 563ae47..075a62d 100644
--- a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java
+++ b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/ConfigurationInjector.java
@@ -20,7 +20,7 @@ package org.apache.tamaya.inject;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.inject.api.ConfiguredItemSupplier;
+import org.apache.tamaya.functions.Supplier;
/**
* Accessor interface for injection of configuration and configuration templates.
@@ -79,7 +79,7 @@ public interface ConfigurationInjector {
* @param <T> the target type.
* @return a supplier creating configured instances of {@code T}.
*/
- <T> ConfiguredItemSupplier<T> getConfiguredSupplier(ConfiguredItemSupplier<T> supplier);
+ <T> Supplier<T> getConfiguredSupplier(Supplier<T> supplier);
/**
* Creates a supplier for configured instances of the given type {@code T}.
@@ -89,6 +89,6 @@ public interface ConfigurationInjector {
* @param <T> the target type.
* @return a supplier creating configured instances of {@code T}.
*/
- <T> ConfiguredItemSupplier<T> getConfiguredSupplier(ConfiguredItemSupplier<T> supplier, Configuration config);
+ <T> Supplier<T> getConfiguredSupplier(Supplier<T> supplier, Configuration config);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0c9dc212/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
index a3a7015..ff9448b 100644
--- a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
+++ b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultConfigurationInjector.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.inject.internal;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.functions.Supplier;
import org.apache.tamaya.inject.ConfigurationInjector;
import javax.annotation.Priority;
@@ -31,7 +32,6 @@ import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
-import org.apache.tamaya.inject.api.ConfiguredItemSupplier;
import org.apache.tamaya.inject.api.NoConfig;
import org.apache.tamaya.inject.api.Config;
import org.apache.tamaya.inject.api.ConfigDefaultSections;
@@ -159,18 +159,18 @@ public final class DefaultConfigurationInjector implements ConfigurationInjector
if(cl==null){
cl = this.getClass().getClassLoader();
}
- return templateType.cast(Proxy.newProxyInstance(cl, new Class[]{ConfiguredItemSupplier.class, Objects.requireNonNull(templateType)},
+ return templateType.cast(Proxy.newProxyInstance(cl, new Class[]{Supplier.class, Objects.requireNonNull(templateType)},
new ConfigTemplateInvocationHandler(templateType)));
}
@Override
- public <T> ConfiguredItemSupplier<T> getConfiguredSupplier(final ConfiguredItemSupplier<T> supplier) {
+ public <T> Supplier<T> getConfiguredSupplier(final Supplier<T> supplier) {
return getConfiguredSupplier(supplier, ConfigurationProvider.getConfiguration());
}
@Override
- public <T> ConfiguredItemSupplier<T> getConfiguredSupplier(final ConfiguredItemSupplier<T> supplier, final Configuration config) {
- return new ConfiguredItemSupplier<T>() {
+ public <T> Supplier<T> getConfiguredSupplier(final Supplier<T> supplier, final Configuration config) {
+ return new Supplier<T>() {
public T get() {
return configure(supplier.get(), config);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0c9dc212/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java
----------------------------------------------------------------------
diff --git a/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java b/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java
index f82d04b..b3117fc 100644
--- a/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java
+++ b/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java
@@ -20,7 +20,6 @@ package org.apache.tamaya.inject.internal;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.inject.api.ConfiguredItemSupplier;
import org.apache.tamaya.inject.api.DynamicValue;
import org.apache.tamaya.inject.api.Config;
import org.apache.tamaya.inject.api.UpdatePolicy;
@@ -261,49 +260,50 @@ public class DefaultDynamicValueTest {
assertEquals("aValue", val.orElse("bla"));
}
- @Test
- public void testOrElseGet() throws Exception {
- DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"),
- config);
- val.setUpdatePolicy(UpdatePolicy.IMMEDEATE);
- assertEquals("bla", val.orElseGet(new ConfiguredItemSupplier() {
- @Override
- public Object get() {
- return "bla";
- }
- }));
- properties.put("a", "aValue");
- val.updateValue();
- assertEquals("aValue", val.orElseGet(new ConfiguredItemSupplier() {
- @Override
- public Object get() {
- return "bla";
- }
- }));
- }
-
- @Test(expected = ConfigException.class)
- public void testOrElseThrow() throws Throwable {
- DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"),
- config);
- val.setUpdatePolicy(UpdatePolicy.EXPLCIT);
- val.get();
- properties.put("a", "aValue");
- assertEquals("aValue", val.orElseThrow(new ConfiguredItemSupplier() {
- @Override
- public ConfigException get() {
- return new ConfigException("bla");
- }
- }));
- properties.remove("a");
- val.updateValue();
- assertEquals("aValue", val.orElseThrow(new ConfiguredItemSupplier() {
- @Override
- public ConfigException get() {
- return new ConfigException("bla");
- }
- }));
- }
+// TODO reenable with Java 8 support.
+// @Test
+// public void testOrElseGet() throws Exception {
+// DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"),
+// config);
+// val.setUpdatePolicy(UpdatePolicy.IMMEDEATE);
+// assertEquals("bla", val.orElseGet(new ConfiguredItemSupplier() {
+// @Override
+// public Object get() {
+// return "bla";
+// }
+// }));
+// properties.put("a", "aValue");
+// val.updateValue();
+// assertEquals("aValue", val.orElseGet(new ConfiguredItemSupplier() {
+// @Override
+// public Object get() {
+// return "bla";
+// }
+// }));
+// }
+//
+// @Test(expected = ConfigException.class)
+// public void testOrElseThrow() throws Throwable {
+// DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"),
+// config);
+// val.setUpdatePolicy(UpdatePolicy.EXPLCIT);
+// val.get();
+// properties.put("a", "aValue");
+// assertEquals("aValue", val.orElseThrow(new ConfiguredItemSupplier() {
+// @Override
+// public ConfigException get() {
+// return new ConfigException("bla");
+// }
+// }));
+// properties.remove("a");
+// val.updateValue();
+// assertEquals("aValue", val.orElseThrow(new ConfiguredItemSupplier() {
+// @Override
+// public ConfigException get() {
+// return new ConfigException("bla");
+// }
+// }));
+// }
private static final class DoublicatingConverter implements PropertyConverter<String>{
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0c9dc212/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/LazyRefreshablePropertySource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/LazyRefreshablePropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/LazyRefreshablePropertySource.java
index 7de7d53..d5fce6f 100644
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/LazyRefreshablePropertySource.java
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/LazyRefreshablePropertySource.java
@@ -189,8 +189,12 @@ implements RefreshablePropertySource {
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof LazyRefreshablePropertySource)) return false;
+ if (this == o){
+ return true;
+ }
+ if (!(o instanceof LazyRefreshablePropertySource)){
+ return false;
+ }
LazyRefreshablePropertySource that = (LazyRefreshablePropertySource) o;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0c9dc212/modules/optional/src/main/java/org/apache/tamaya/optional/OptionalConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/optional/src/main/java/org/apache/tamaya/optional/OptionalConfiguration.java b/modules/optional/src/main/java/org/apache/tamaya/optional/OptionalConfiguration.java
index 4868bc1..476d5b5 100644
--- a/modules/optional/src/main/java/org/apache/tamaya/optional/OptionalConfiguration.java
+++ b/modules/optional/src/main/java/org/apache/tamaya/optional/OptionalConfiguration.java
@@ -54,6 +54,14 @@ public final class OptionalConfiguration {
}
/**
+ * Allows to check if Tamaya is on the classpath.
+ * @return true, if Tamaya is available.
+ */
+ public static boolean isTamayaLoaded(){
+ return TAMAYA_LOADED;
+ }
+
+ /**
* Default value provider returning Strings from system properties and the system environment.
* In all other cases {@code null} is returned.
*/
@@ -204,11 +212,13 @@ public final class OptionalConfiguration {
* @param type the target type, not null.
* @param <T> The type param
* @return the corresponding value from Tamaya, or null.
+ * @throws IllegalStateException if Tamaya is not loaded.
+ * @see #isTamayaLoaded()
*/
private <T> T getTamaya(String key, Class<T> type) {
if (TAMAYA_LOADED) {
return ConfigurationProvider.getConfiguration().get(key, type);
}
- return null;
+ throw new IllegalStateException("Tamaya is not loaded.");
}
}