tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [8/8] incubator-tamaya git commit: Applied several quality fixes. Aligned Java 7 with Java 8.
Date Fri, 27 Feb 2015 02:40:53 GMT
Applied several quality fixes.
Aligned Java 7 with Java 8.


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

Branch: refs/heads/master
Commit: 1f7eb1ceaea7d40b006abdbc57991e0997465c4c
Parents: 0ce780d
Author: anatole <anatole@apache.org>
Authored: Fri Feb 27 03:40:09 2015 +0100
Committer: anatole <anatole@apache.org>
Committed: Fri Feb 27 03:40:38 2015 +0100

----------------------------------------------------------------------
 .../core/config/ConfigChangeSetBuilder.java     | 359 -------------------
 .../internal/config/FileChangeListener.java     |   7 +-
 .../tamaya/builder/TestPropertySource.java      |   5 +
 .../builder/TestPropertySourceProvider.java     |  10 +
 .../builder/TestPropertySourceProviderB.java    |  10 +
 .../org/apache/tamaya/events/EventSupport.java  |  10 +-
 .../tamaya/events/FrozenConfiguration.java      |  37 +-
 .../tamaya/events/FrozenPropertySource.java     |  49 ++-
 .../java/org/apache/tamaya/events/Listener.java |   8 +-
 .../events/delta/ConfigurationChange.java       |   2 +-
 .../delta/ConfigurationContextChange.java       |   2 +-
 .../events/delta/PropertySourceChange.java      |   2 +-
 .../folderobserver/FileChangeListener.java      |  29 +-
 .../ObservingPropertySourceProvider.java        |   1 -
 ...faultConfigurationContextChangeListener.java |   5 +-
 .../events/internal/DefaultEventSupportSpi.java |   9 +-
 .../tamaya/events/tests/ObservedConfigTest.java |  22 +-
 .../events/tests/TestObservingProvider.java     |  23 +-
 .../format/FlattenedDefaultPropertySource.java  |  14 +-
 19 files changed, 170 insertions(+), 434 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f7eb1ce/dormant/core/src/main/java/org/apache/tamaya/core/config/ConfigChangeSetBuilder.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/config/ConfigChangeSetBuilder.java
b/dormant/core/src/main/java/org/apache/tamaya/core/config/ConfigChangeSetBuilder.java
deleted file mode 100644
index 62b50ac..0000000
--- a/dormant/core/src/main/java/org/apache/tamaya/core/config/ConfigChangeSetBuilder.java
+++ /dev/null
@@ -1,359 +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.core.config;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.spi.PropertySource;
-
-import java.beans.PropertyChangeEvent;
-import java.util.*;
-import java.util.function.Function;
-
-/**
- * Models a set current changes to be applied to a configuration/property provider.  Such
a set can be applied
- * to any {@link org.apache.tamaya.spi.PropertySource} instance. If the provider is mutable
it may check the
- * version given and applyChanges the changes to the provider/configuration, including triggering
current regarding
- * change events.
- * <p>
- * For appropriate conversion a {@code Function<String, Codec>} can be applied, which
performs correct conversion,
- * when changed values are set. This function enables connecting e.g. setters on a configuration
template with
- * the corresponding conversion logic, so the template calls are correctly converted back.
- */
-public final class ConfigChangeSetBuilder {
-    /**
-     * The recorded changes.
-     */
-    final SortedMap<String, PropertyChangeEvent> delta = new TreeMap<>();
-    /**
-     * The underlying configuration/provider.
-     */
-    PropertySource source;
-
-    /**
-     * Constructor.
-     *
-     * @param source      the underlying configuration/provider, not null.
-     */
-    private ConfigChangeSetBuilder(PropertySource source) {
-        this.source = Objects.requireNonNull(source);
-    }
-
-    /**
-     * Creates a new instance current this builder.
-     *
-     * @param source the underlying property provider/configuration, not null.
-     * @return the builder for chaining.
-     */
-    public static ConfigChangeSetBuilder of(PropertySource source) {
-        return new ConfigChangeSetBuilder(source);
-    }
-
-
-    /**
-     * Creates a new instance current this builder.
-     *
-     * @param configuration the base configuration, not null.
-     * @return the builder for chaining.
-     */
-    public static ConfigChangeSetBuilder of(Configuration configuration) {
-        return new ConfigChangeSetBuilder(configuration);
-    }
-
-    /**
-     * This method records all changes to be applied to the base property provider/configuration
to
-     * achieve the given target state.
-     *
-     * @param newState the new target state, not null.
-     * @return the builder for chaining.
-     */
-    public ConfigChangeSetBuilder addChanges(PropertySource newState) {
-        compare(newState, this.source).forEach((c) -> this.delta.put(c.getPropertyName(),
c));
-        return this;
-    }
-
-    /**
-     * Get the current values, also considering any changes recorded within this change set.
-     *
-     * @param key the key current the entry, not null.
-     * @return the keys, or null.
-     */
-    public String get(String key) {
-        PropertyChangeEvent change = this.delta.get(key);
-        if (change != null && !(change.getNewValue() == null)) {
-            return (String) change.getNewValue();
-        }
-        return null;
-    }
-
-    /**
-     * Marks the given key(s) fromMap the configuration/properties to be removed.
-     *
-     * @param key       the key current the entry, not null.
-     * @param otherKeys additional keys to be removed (convenience), not null.
-     * @return the builder for chaining.
-     */
-    public ConfigChangeSetBuilder remove(String key, String... otherKeys) {
-        String oldValue = this.source.get(key).orElse(null);
-        if (oldValue == null) {
-            this.delta.remove(key);
-        }
-        this.delta.put(key, new PropertyChangeEvent(this.source, key, oldValue, null));
-        for (String addKey : otherKeys) {
-            oldValue = this.source.get(addKey).orElse(null);
-            if (oldValue == null) {
-                this.delta.remove(addKey);
-            }
-            this.delta.put(addKey, new PropertyChangeEvent(this.source, addKey, oldValue,
null));
-        }
-        return this;
-    }
-
-    /**
-     * Applies the given keys.
-     *
-     * @param key   the key current the entry, not null.
-     * @param value the keys to be applied, not null.
-     * @return the builder for chaining.
-     */
-    public ConfigChangeSetBuilder put(String key, boolean value) {
-        this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null),
String.valueOf(value)));
-        return this;
-    }
-
-    /**
-     s* Applies the given keys.
-     *
-     * @param key   the key current the entry, not null.
-     * @param value the keys to be applied, not null.
-     * @return the builder for chaining.
-     */
-    public ConfigChangeSetBuilder put(String key, byte value) {
-        this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null),
String.valueOf(value)));
-        return this;
-    }
-
-    /**
-     * Applies the given keys.
-     *
-     * @param key   the key current the entry, not null.
-     * @param value the keys to be applied, not null.
-     * @return the builder for chaining.
-     */
-    public ConfigChangeSetBuilder put(String key, char value) {
-        this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null),
String.valueOf(value)));
-        return this;
-    }
-
-    /**
-     * Applies the given keys.
-     *
-     * @param key   the key current the entry, not null.
-     * @param value the keys to be applied, not null.
-     * @return the builder for chaining.
-     */
-    public ConfigChangeSetBuilder put(String key, short value) {
-        this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null),
String.valueOf(value)));
-        return this;
-    }
-
-    /**
-     * Applies the given keys.
-     *
-     * @param key   the key current the entry, not null.
-     * @param value the keys to be applied, not null.
-     * @return the builder for chaining.
-     */
-    public ConfigChangeSetBuilder put(String key, int value) {
-        this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null),
String.valueOf(value)));
-        return this;
-    }
-
-    /**
-     * Applies the given keys.
-     *
-     * @param key   the key current the entry, not null.
-     * @param value the keys to be applied, not null.
-     * @return the builder for chaining.
-     */
-    public ConfigChangeSetBuilder put(String key, long value) {
-        this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null),
String.valueOf(value)));
-        return this;
-    }
-
-    /**
-     * Applies the given keys.
-     *
-     * @param key   the key current the entry, not null.
-     * @param value the keys to be applied, not null.
-     * @return the builder for chaining.
-     */
-    public ConfigChangeSetBuilder put(String key, float value) {
-        this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null),
String.valueOf(value)));
-        return this;
-    }
-
-    /**
-     * Applies the given keys.
-     *
-     * @param key   the key current the entry, not null.
-     * @param value the keys to be applied, not null.
-     * @return the builder for chaining.
-     */
-    public ConfigChangeSetBuilder put(String key, double value) {
-        this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null),
String.valueOf(value)));
-        return this;
-    }
-
-
-    /**
-     * Applies the given keys.
-     *
-     * @param key   the key current the entry, not null.
-     * @param value the keys to be applied, not null.
-     * @return the builder for chaining.
-     */
-    public ConfigChangeSetBuilder put(String key, String value) {
-        this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null),
String.valueOf(value)));
-        return this;
-    }
-
-    /**
-     * Applies the given keys.
-     *
-     * @param key   the key current the entry, not null.
-     * @param value the keys to be applied, not null.
-     * @return the builder for chaining.
-     * @throws org.apache.tamaya.ConfigException if no matching Codec could be found.
-     */
-    public <T> ConfigChangeSetBuilder put(String key, Class<T> type, T value)
{
-        put(key, type, value, null);
-        return this;
-    }
-
-    /**
-     * Applies the given keys.
-     *
-     * @param key   the key current the entry, not null.
-     * @param value the keys to be applied, not null.
-     * @param adapter the codec to be used, if set overrides any other codecs that may apply.
If null an appropriate
-     *              codec is tried to be evaluated as needed.
-     * @return the builder for chaining.
-     * @throws org.apache.tamaya.ConfigException if no matching Codec could be found.
-     */
-    public <T> ConfigChangeSetBuilder put(String key, Class<T> type, T value,
Function<T,String> adapter) {
-        this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key).orElse(null),
adapter.apply(Objects.requireNonNull(value))));
-        return this;
-    }
-
-
-    /**
-     * Apply all the given values to the base configuration/properties.
-     * Note that all values passed must be convertible to String, either
-     * <ul>
-     * <li>the registered codecs provider provides codecs for the corresponding keys,
or </li>
-     * <li>default codecs are present for the given type, or</li>
-     * <li>the value is an instanceof String</li>
-     * </ul>
-     *
-     * @param changes the changes to be applied, not null.
-     * @return the builder for chaining.
-     */
-    public ConfigChangeSetBuilder putAll(Map<String, String> changes) {
-        changes.putAll(changes);
-        return this;
-    }
-
-    /**
-     * This method will create a change set that clears all entries fromMap the given base
configuration/properties.
-     *
-     * @return the builder for chaining.
-     */
-    public ConfigChangeSetBuilder deleteAll() {
-        this.delta.clear();
-        this.source.getProperties().forEach((k, v) ->
-                this.delta.put(k, new PropertyChangeEvent(this.source, k, v, null)));
-        return this;
-    }
-
-    /**
-     * Checks if the change set is empty, i.e. does not contain any changes.
-     *
-     * @return true, if the set is empty.
-     */
-    public boolean isEmpty() {
-        return this.delta.isEmpty();
-    }
-
-    /**
-     * Resets this change set instance. This will clear all changes done to this builder,
so the
-     * set will be empty.
-     */
-    public void reset() {
-        this.delta.clear();
-    }
-
-    /**
-     * Builds the corresponding change set.
-     *
-     * @return the new change set, never null.
-     */
-    public ConfigChangeSet build() {
-        return new ConfigChangeSet(this.source, Collections.unmodifiableCollection(this.delta.values()));
-    }
-
-    /**
-     * Compares the two property config/configurations and creates a collection current all
changes
-     * that must be appied to render {@code map1} into {@code map2}.
-     *
-     * @param map1 the source map, not null.
-     * @param map2 the target map, not null.
-     * @return a collection current change events, never null.
-     */
-    public static Collection<PropertyChangeEvent> compare(PropertySource map1, PropertySource
map2) {
-        List<PropertyChangeEvent> changes = new ArrayList<>();
-        for (Map.Entry<String, String> en : map1.getProperties().entrySet()) {
-            Optional<String> val = map2.get(en.getKey());
-            if (!val.isPresent()) {
-                changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
-            } else if (!val.get().equals(en.getValue())) {
-                changes.add(new PropertyChangeEvent(map1, en.getKey(), val.get(), en.getValue()));
-            }
-        }
-        for (Map.Entry<String, String> en : map2.getProperties().entrySet()) {
-            Optional<String> val = map1.get(en.getKey());
-            if (!val.isPresent()) {
-                changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
-            } else if (!val.equals(Optional.ofNullable(en.getValue()))) {
-                changes.add(new PropertyChangeEvent(map1, en.getKey(), val.get(), en.getValue()));
-            }
-        }
-        return changes;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see java.lang.Object#toString()
-     */
-    @Override
-    public String toString() {
-        return "PropertyChangeEventBuilder [source=" + source + ", " +
-                ", delta=" + delta + "]";
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f7eb1ce/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java
----------------------------------------------------------------------
diff --git a/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java
b/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java
index cdb7b33..e1a3026 100644
--- a/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java
+++ b/dormant/core/src/main/java/org/apache/tamaya/core/internal/config/FileChangeListener.java
@@ -14,8 +14,9 @@ import java.nio.file.WatchKey;
 import java.nio.file.WatchService;
 import java.util.Map;
 import java.util.Objects;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
-import org.apache.log4j.Logger;
 import org.apache.tamaya.ConfigException;
 import old.ConfigurationProviderSpi;
 
@@ -30,7 +31,7 @@ import old.ConfigurationProviderSpi;
  */
 class FileChangeListener implements Runnable {
 
-    private static final Logger LOGGER = Logger.getLogger(FileChangeListener.class);
+    private static final Logger LOGGER = Logger.getLogger(FileChangeListener.class.getName());
 
     private WatchService watchService;
 
@@ -119,7 +120,7 @@ class FileChangeListener implements Runnable {
             FileSystem fileSystem = Paths.get(".").getFileSystem();
             return fileSystem.newWatchService();
         } catch (IOException e) {
-            LOGGER.warn("This file System does not supports WatchService", e);
+            LOGGER.log(Level.WARNING, "The file System does not supports WatchService", e);
             return null;
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f7eb1ce/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
b/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
index eb8f417..54deca3 100644
--- a/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
+++ b/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySource.java
@@ -42,6 +42,11 @@ public class TestPropertySource
     }
 
     @Override
+    public String getName() {
+        return "TestPropertySource";
+    }
+
+    @Override
     public String get(String key) {
         return getProperties().get(key);
     }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f7eb1ce/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
b/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
index f82a8e7..4e7db79 100644
--- a/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
+++ b/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProvider.java
@@ -48,6 +48,11 @@ public class TestPropertySourceProvider
         }
 
         @Override
+        public String getName() {
+            return "YProvidingPropertySource";
+        }
+
+        @Override
         public String get(String key) {
             return getProperties().get(key);
         }
@@ -75,5 +80,10 @@ public class TestPropertySourceProvider
         public int getOrdinal() {
             return 100;
         }
+
+        @Override
+        public String getName() {
+            return "XProvidingPropertySource";
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f7eb1ce/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
----------------------------------------------------------------------
diff --git a/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
b/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
index 6675d17..ddfb132 100644
--- a/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
+++ b/modules/builder/src/test/java/org/apache/tamaya/builder/TestPropertySourceProviderB.java
@@ -48,6 +48,11 @@ public class TestPropertySourceProviderB
         }
 
         @Override
+        public String getName() {
+            return "BProvidingPropertySource";
+        }
+
+        @Override
         public String get(String key) {
             return getProperties().get(key);
         }
@@ -75,5 +80,10 @@ public class TestPropertySourceProviderB
         public int getOrdinal() {
             return 100;
         }
+
+        @Override
+        public String getName() {
+            return "AProvidingPropertySource";
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f7eb1ce/modules/events/src/main/java/org/apache/tamaya/events/EventSupport.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/EventSupport.java b/modules/events/src/main/java/org/apache/tamaya/events/EventSupport.java
index 7082213..f3b9e19 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/EventSupport.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/EventSupport.java
@@ -28,9 +28,9 @@ import org.apache.tamaya.spi.ServiceContext;
  */
 public class EventSupport {
     /**
-     * The backing spi.
+     * The backing SPI.
      */
-    private static final EventSupportSpi spi = ServiceContext.getInstance()
+    private static final EventSupportSpi SPI = ServiceContext.getInstance()
             .getService(EventSupportSpi.class)
             .orElseThrow(() -> new ConfigException("No SPI registered for " +
                     EventSupport.class.getName()));
@@ -48,7 +48,7 @@ public class EventSupport {
      * @param l the listener not null.
      */
     public static <T> void addListener(Listener<T> l) {
-        spi.addListener(l);
+        SPI.addListener(l);
     }
 
     /**
@@ -58,7 +58,7 @@ public class EventSupport {
      * @param l the listener not null.
      */
     public static <T> void removeListener(Listener<T> l) {
-        spi.removeListener(l);
+        SPI.removeListener(l);
     }
 
     /**
@@ -77,7 +77,7 @@ public class EventSupport {
      *              @param eventType the event type, the vent may be a subclass.
      */
     public static <T> void fireEvent(T event, Class<T> eventType) {
-        spi.fireEvent(event, eventType);
+        SPI.fireEvent(event, eventType);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f7eb1ce/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
b/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
index 9a30325..a5ac071 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
@@ -30,16 +30,19 @@ import java.util.Map;
  * Configuration implementation that stores all current values of a given (possibly dynamic,
contextual and non remote
  * capable instance) and is fully serializable. Note that hereby only the scannable key/value
pairs are considered.
  */
-public final class FrozenConfiguration implements Configuration, Serializable{
+public final class FrozenConfiguration implements Configuration, Serializable {
     private static final long serialVersionUID = -6373137316556444171L;
-    /** The properties frozen. */
-    private Map<String,String> properties = new HashMap<>();
+    /**
+     * The properties frozen.
+     */
+    private Map<String, String> properties = new HashMap<>();
 
     /**
      * Constructor.
+     *
      * @param config The base configuration.
      */
-    private FrozenConfiguration(Configuration config){
+    private FrozenConfiguration(Configuration config) {
         this.properties.putAll(config.getProperties());
         this.properties.put("[meta]frozenAt", String.valueOf(System.currentTimeMillis()));
         this.properties = Collections.unmodifiableMap(this.properties);
@@ -47,36 +50,40 @@ public final class FrozenConfiguration implements Configuration, Serializable{
 
     /**
      * Creates a new FrozenConfiguration instance based on a Configuration given.
+     *
      * @param config the configuration to be frozen, not null.
      * @return the frozen Configuration.
      */
-    public static FrozenConfiguration of(Configuration config){
-        if(config instanceof FrozenConfiguration){
-            return (FrozenConfiguration)config;
+    public static FrozenConfiguration of(Configuration config) {
+        if (config instanceof FrozenConfiguration) {
+            return (FrozenConfiguration) config;
         }
         return new FrozenConfiguration(config);
     }
 
     @Override
-    public Map<String,String> getProperties(){
+    public Map<String, String> getProperties() {
         return properties;
     }
 
     @Override
     public boolean equals(Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
-
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
         FrozenConfiguration that = (FrozenConfiguration) o;
-
-        if (!properties.equals(that.properties)) return false;
+        if (!properties.equals(that.properties)) {
+            return false;
+        }
         return true;
     }
 
     @Override
     public int hashCode() {
-        int result = properties.hashCode();
-        return result;
+        return properties.hashCode();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f7eb1ce/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java
b/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java
index bcf1c6f..0b9dc69 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java
@@ -29,20 +29,27 @@ import java.util.Map;
  * PropertySource implementation that stores all current values of a given (possibly dynamic,
contextual and non remote
  * capable instance) and is fully serializable. Note that hereby only the scannable key/value
pairs are considered.
  */
-public final class FrozenPropertySource implements PropertySource, Serializable{
+public final class FrozenPropertySource implements PropertySource, Serializable {
     private static final long serialVersionUID = -6373137316556444171L;
-    /** The ordinal. */
+    /**
+     * The ordinal.
+     */
     private int ordinal;
-    /** The properties read. */
-    private Map<String,String> properties = new HashMap<>();
-    /** The PropertySource's name. */
+    /**
+     * The properties read.
+     */
+    private Map<String, String> properties = new HashMap<>();
+    /**
+     * The PropertySource's name.
+     */
     private String name;
 
     /**
      * Constructor.
+     *
      * @param propertySource The base PropertySource.
      */
-    private FrozenPropertySource(PropertySource propertySource){
+    private FrozenPropertySource(PropertySource propertySource) {
         this.properties.putAll(propertySource.getProperties());
         this.properties.put("[meta]frozenAt", String.valueOf(System.currentTimeMillis()));
         this.properties = Collections.unmodifiableMap(this.properties);
@@ -50,24 +57,25 @@ public final class FrozenPropertySource implements PropertySource, Serializable{
         this.name = propertySource.getName();
     }
 
-    @Override
-    public String getName(){
-        return this.name;
-    }
-
     /**
      * Creates a new FrozenPropertySource instance based on a PropertySource given.
+     *
      * @param propertySource the property source to be frozen, not null.
      * @return the frozen property source.
      */
-    public static FrozenPropertySource of(PropertySource propertySource){
-        if(propertySource instanceof FrozenPropertySource){
-            return (FrozenPropertySource)propertySource;
+    public static FrozenPropertySource of(PropertySource propertySource) {
+        if (propertySource instanceof FrozenPropertySource) {
+            return (FrozenPropertySource) propertySource;
         }
         return new FrozenPropertySource(propertySource);
     }
 
     @Override
+    public String getName() {
+        return this.name;
+    }
+
+    @Override
     public int getOrdinal() {
         return this.ordinal;
     }
@@ -78,15 +86,18 @@ public final class FrozenPropertySource implements PropertySource, Serializable{
     }
 
     @Override
-    public Map<String,String> getProperties(){
+    public Map<String, String> getProperties() {
         return properties;
     }
 
     @Override
     public boolean equals(Object o) {
-        if (this == o) return true;
-        if (!(o instanceof FrozenPropertySource)) return false;
-
+        if (this == o) {
+            return true;
+        }
+        if (!(o instanceof FrozenPropertySource)) {
+            return false;
+        }
         FrozenPropertySource that = (FrozenPropertySource) o;
         return ordinal == that.ordinal && properties.equals(that.properties);
     }
@@ -102,7 +113,7 @@ public final class FrozenPropertySource implements PropertySource, Serializable{
     public String toString() {
         return "FrozenPropertySource{" +
                 "properties=" + properties +
-                ", ordinal="+ordinal +
+                ", ordinal=" + ordinal +
                 '}';
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f7eb1ce/modules/events/src/main/java/org/apache/tamaya/events/Listener.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/Listener.java b/modules/events/src/main/java/org/apache/tamaya/events/Listener.java
index 623f1c7..538bc94 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/Listener.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/Listener.java
@@ -18,14 +18,16 @@
  */
 package org.apache.tamaya.events;
 
-import org.apache.tamaya.events.delta.ConfigurationChange;
-
 /**
  * Interface to be implemented for listening on changes on {@link org.apache.tamaya.Configuration}
instances.
+ * @param <T> the type listened to.
  */
 @FunctionalInterface
 public interface Listener<T> {
-
+    /**
+     * Called if an event occurred.
+     * @param event the event, not null.
+     */
     void onEvent(T event);
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f7eb1ce/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChange.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChange.java
b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChange.java
index 87023da..fcc10d5 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChange.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationChange.java
@@ -38,7 +38,7 @@ import java.util.UUID;
  */
 public final class ConfigurationChange implements Serializable{
 
-    private static final long serialVersionUID = 1l;
+    private static final long serialVersionUID = 1L;
     /** The base property provider/configuration. */
     private FrozenConfiguration configuration;
     /** The base version, usable for optimistic locking. */

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f7eb1ce/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationContextChange.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationContextChange.java
b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationContextChange.java
index 465352f..2ebc3ef 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationContextChange.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/delta/ConfigurationContextChange.java
@@ -37,7 +37,7 @@ import java.util.stream.Collectors;
  */
 public final class ConfigurationContextChange implements Serializable{
 
-    private static final long serialVersionUID = 1l;
+    private static final long serialVersionUID = 1L;
     /** The base property provider/configuration. */
     private List<PropertySourceChange> changedPropertySources = new ArrayList<>();
     /** The base version, usable for optimistic locking. */

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f7eb1ce/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChange.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChange.java
b/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChange.java
index 3ded83e..89554ee 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChange.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/delta/PropertySourceChange.java
@@ -38,7 +38,7 @@ import java.util.UUID;
  */
 public final class PropertySourceChange implements Serializable{
 
-    private static final long serialVersionUID = 1l;
+    private static final long serialVersionUID = 1L;
     /** The base property provider/configuration. */
     private FrozenPropertySource propertySource;
     /** The base version, usable for optimistic locking. */

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f7eb1ce/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/FileChangeListener.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/FileChangeListener.java
b/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/FileChangeListener.java
index d1563eb..b3767cc 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/FileChangeListener.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/FileChangeListener.java
@@ -32,7 +32,6 @@ import java.util.Objects;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import static java.nio.file.StandardWatchEventKinds.*;
 
 /**
  * Class that has the responsibility to watch the folder and then publish the changes to
a
@@ -62,14 +61,19 @@ class FileChangeListener implements Runnable {
 
         if (Objects.nonNull(watchService) && Objects.nonNull(directory)) {
             try {
-                directory.register(watchService, ENTRY_DELETE, ENTRY_MODIFY,
-                        ENTRY_CREATE);
+                directory.register(watchService,
+                        StandardWatchEventKinds.ENTRY_DELETE,
+                        StandardWatchEventKinds.ENTRY_MODIFY,
+                        StandardWatchEventKinds.ENTRY_CREATE);
             } catch (IOException e) {
                 throw new FileChangeListenerException("An error happened when does try to
registry to watch the folder", e);
             }
         }
     }
 
+    /**
+     * Stops the listener service from observing the target directory.
+     */
     public void stopListener(){
         running = false;
     }
@@ -84,7 +88,9 @@ class FileChangeListener implements Runnable {
         }
     }
 
-
+    /**
+     * Start watching the current folder.
+     */
     private void watchFolder() {
         try {
             WatchKey watckKey = watchService.take();
@@ -104,7 +110,10 @@ class FileChangeListener implements Runnable {
         }
     }
 
-
+    /**
+     * Get the watch service.
+     * @return the watch service, or null, if the watch service is not supported.
+     */
     private WatchService getWatchService() {
         try {
             FileSystem fileSystem = Paths.get(".").getFileSystem();
@@ -116,10 +125,18 @@ class FileChangeListener implements Runnable {
 
     }
 
+    /**
+     * Exception if file listening fails.
+     */
     static class FileChangeListenerException extends ConfigException {
-
+        /** Serialversion UID. */
         private static final long serialVersionUID = -8965486770881001513L;
 
+        /**
+         * Constructor.
+         * @param message a message
+         * @param cause an (optional) root cause.
+         */
         public FileChangeListenerException(String message, Throwable cause) {
             super(message, cause);
         }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f7eb1ce/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
b/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
index 7cf02fd..ed21d58 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
@@ -46,7 +46,6 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import java.util.stream.Collectors;
 
 /**
  * This implementation run in a folder taking up all file compatible with the given

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f7eb1ce/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigurationContextChangeListener.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigurationContextChangeListener.java
b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigurationContextChangeListener.java
index fe00053..fa658ef 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigurationContextChangeListener.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigurationContextChangeListener.java
@@ -42,7 +42,7 @@ public class DefaultConfigurationContextChangeListener implements Listener<Confi
         ConfigurationContext context = ConfigurationProvider.getConfigurationContext();
         Collection<PropertySource> affectedPropertySources = context.getPropertySources(ps
->
                 event.isAffected(ps));
-        if(!affectedPropertySources.isEmpty()){
+        if (!affectedPropertySources.isEmpty()) {
             ConfigurationContext newContext = context.toBuilder()
                     .removePropertySources(event.getRemovedPropertySources().stream()
                             .map(ps -> ps.getName()).collect(Collectors.toSet()))
@@ -51,8 +51,7 @@ public class DefaultConfigurationContextChangeListener implements Listener<Confi
                     .build();
             try {
                 ConfigurationProvider.setConfigurationContext(newContext);
-            }
-            catch(Exception e){
+            } catch (Exception e) {
                 LOG.log(Level.INFO, "Failed to update the current ConfigurationContext due
to config model changes", e);
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f7eb1ce/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultEventSupportSpi.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultEventSupportSpi.java
b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultEventSupportSpi.java
index 4164363..b92bc49 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultEventSupportSpi.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultEventSupportSpi.java
@@ -49,10 +49,9 @@ public class DefaultEventSupportSpi implements EventSupportSpi {
     public DefaultEventSupportSpi() {
         try {
             for (Listener<?> l : ServiceContext.getInstance().getServices(Listener.class))
{
-                try{
+                try {
                     addListener(l);
-                }
-                catch(Exception e){
+                } catch (Exception e) {
                     LOG.log(Level.WARNING, e, () -> "Failed to load configured listener:
" + l.getClass().getName());
                 }
             }
@@ -63,7 +62,7 @@ public class DefaultEventSupportSpi implements EventSupportSpi {
 
     @Override
     public <T> void addListener(Listener<T> l) {
-        Type type = TypeLiteral.getTypeParameter(l.getClass());
+        Type type = TypeLiteral.getTypeParameter(l.getClass(), Listener.class);
         List<Listener> listeners = listenerMap.computeIfAbsent(type,
                 (k) -> Collections.synchronizedList(new ArrayList<>()));
         synchronized (listeners) {
@@ -75,7 +74,7 @@ public class DefaultEventSupportSpi implements EventSupportSpi {
 
     @Override
     public <T> void removeListener(Listener<T> l) {
-        Type type = TypeLiteral.getTypeParameter(l.getClass());
+        Type type = TypeLiteral.getTypeParameter(l.getClass(), Listener.class);
         List<Listener> listeners = listenerMap.get(type);
         if (listeners != null) {
             synchronized (listeners) {

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f7eb1ce/modules/events/src/test/java/org/apache/tamaya/events/tests/ObservedConfigTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/tests/ObservedConfigTest.java
b/modules/events/src/test/java/org/apache/tamaya/events/tests/ObservedConfigTest.java
index e8e0b3f..e4a6ee5 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/tests/ObservedConfigTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/tests/ObservedConfigTest.java
@@ -1,16 +1,34 @@
+/*
+ * 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.events.tests;
 
 import org.apache.tamaya.ConfigurationProvider;
 import org.junit.Test;
 
 /**
- * Created by Anatole on 25.02.2015.
+ * Test (currently manual) to test configuration changes.
  */
 public class ObservedConfigTest {
 
     @Test
     public void testInitialConfig(){
-        for(int i=0;i<100;i++){
+        for(int i=0;i<20;i++){
             System.out.println("1: " + ConfigurationProvider.getConfiguration().get("1"));
             System.out.println("2: " + ConfigurationProvider.getConfiguration().get("2"));
             System.out.println("3: " + ConfigurationProvider.getConfiguration().get("3"));

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f7eb1ce/modules/events/src/test/java/org/apache/tamaya/events/tests/TestObservingProvider.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/tests/TestObservingProvider.java
b/modules/events/src/test/java/org/apache/tamaya/events/tests/TestObservingProvider.java
index 411ac5d..eae9c46 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/tests/TestObservingProvider.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/tests/TestObservingProvider.java
@@ -1,3 +1,21 @@
+/*
+ * 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.events.tests;
 
 import org.apache.tamaya.events.folderobserver.ObservingPropertySourceProvider;
@@ -16,11 +34,12 @@ import java.nio.file.WatchService;
 import java.util.Iterator;
 
 /**
- * Created by Anatole on 25.02.2015.
+ * Test configuration property source provider that observes a directory and updated the
config if necessary.
  */
 public class TestObservingProvider extends ObservingPropertySourceProvider{
 
     public TestObservingProvider(){
-        super(Paths.get("C:\\Users\\Anatole\\IdeaProjects\\incubator-tamaya\\modules\\events/src/test/data"),
new PropertiesFormat());
+        super(Paths.get("C:\\Users\\Anatole\\IdeaProjects\\incubator-tamaya\\modules\\events/src/test/data"),
+                new PropertiesFormat());
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1f7eb1ce/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
b/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
index b782be1..47c7ae6 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/FlattenedDefaultPropertySource.java
@@ -19,7 +19,6 @@
 package org.apache.tamaya.format;
 
 import org.apache.tamaya.spi.PropertySource;
-import sun.reflect.generics.reflectiveObjects.LazyReflectiveObjectGenerator;
 
 import java.util.Collections;
 import java.util.Map;
@@ -49,12 +48,12 @@ public class FlattenedDefaultPropertySource implements PropertySource
{
     }
 
     @Override
-    public String getName(){
+    public String getName() {
         String name = this.defaultSection.get("[meta].name");
-        if(name==null){
+        if (name == null) {
             name = this.data.getResource();
         }
-        if(name==null){
+        if (name == null) {
             name = getClass().getSimpleName();
         }
         return name;
@@ -63,11 +62,10 @@ public class FlattenedDefaultPropertySource implements PropertySource
{
     @Override
     public int getOrdinal() {
         String ordinalValue = this.defaultSection.get(PropertySource.TAMAYA_ORDINAL);
-        if(ordinalValue!=null){
-            try{
+        if (ordinalValue != null) {
+            try {
                 return Integer.parseInt(ordinalValue.trim());
-            }
-            catch(Exception e){
+            } catch (Exception e) {
                 LOG.log(Level.WARNING, e, () -> "Failed to parse Tamaya ordinal from "
+ data.getResource());
             }
         }


Mime
View raw message