http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java ---------------------------------------------------------------------- diff --git a/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java b/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java new file mode 100644 index 0000000..b20ebef --- /dev/null +++ b/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationChangeTest.java @@ -0,0 +1,163 @@ +/* + * 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.delta; + +import org.apache.tamaya.Configuration; +import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.events.ConfigurationChange; +import org.apache.tamaya.events.ConfigurationChangeBuilder; +import org.junit.Test; + +import java.util.Map; + +import static org.junit.Assert.*; + +/** + * Test class for {@link ConfigurationChange}. + */ +public class ConfigurationChangeTest { + + @Test + public void testEmptyChangeSet() throws Exception { + ConfigurationChange change = ConfigurationChange.emptyChangeSet(ConfigurationProvider.getConfiguration()); + assertNotNull(change); + assertTrue(change.isEmpty()); + } + + @Test + public void testGetConfiguration() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationChange change = ConfigurationChangeBuilder.of(config).build(); + assertNotNull(change); + assertTrue(change.getUpdatedSize()==0); + assertTrue(change.getAddedSize()==0); + assertTrue(change.getRemovedSize()==0); + assertTrue(change.getChanges().size()==0); + for (Map.Entry<String, String> en : config.getProperties().entrySet()) { + if (!"[meta]frozenAt".equals(en.getKey())) { + if(en.getKey().contains("random.new")){ // dynamic generated value! + continue; + } + assertEquals("Error for " + en.getKey(), en.getValue(), change.getResource().get(en.getKey())); + } + } + } + + @Test + public void testGetVersion() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationChange change = ConfigurationChangeBuilder.of(config).build(); + assertNotNull(change.getVersion()); + change = ConfigurationChangeBuilder.of(config).setVersion("version2").build(); + assertNotNull(change.getVersion()); + assertEquals("version2", change.getVersion()); + } + + @Test + public void testGetTimestamp() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationChange change = ConfigurationChangeBuilder.of(config).build(); + assertTrue((System.currentTimeMillis() - change.getTimestamp()) <= 10L); + change = ConfigurationChangeBuilder.of(config).setTimestamp(10L).build(); + assertEquals(10L, change.getTimestamp()); + } + + @Test + public void testGetEvents() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationChange change = ConfigurationChangeBuilder.of(config).removeKey("key1", "key2").build(); + assertTrue(change.getChanges().size() == 2); + change = ConfigurationChangeBuilder.of(config).addChange("key1Added", "value1Added").build(); + assertTrue(change.getChanges().size() == 1); + } + + @Test + public void testGetRemovedSize() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationChange change = ConfigurationChangeBuilder.of(config).removeKey("java.version", "key2").build(); + assertTrue(change.getRemovedSize() == 2); + assertTrue(change.getAddedSize() == 0); + } + + @Test + public void testGetAddedSize() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("key1", "key2").build(); + assertTrue(change.getAddedSize() == 1); + assertTrue(change.getRemovedSize() == 0); + } + + @Test + public void testGetUpdatedSize() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("java.version", "1.8").build(); + assertTrue(change.getUpdatedSize() == 1); + } + + @Test + public void testIsRemoved() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationChange change = ConfigurationChangeBuilder.of(config).removeKey("java.version").build(); + assertTrue(change.isRemoved("java.version")); + } + + @Test + public void testIsAdded() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("key1", "key2").build(); + assertTrue(change.isAdded("key1")); + } + + @Test + public void testIsUpdated() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("java.version", "1.8").build(); + assertTrue(change.isUpdated("java.version")); + } + + @Test + public void testContainsKey() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("key1", "key2").build(); + assertTrue(change.isKeyAffected("key1")); + assertFalse(change.isKeyAffected("key2")); + change = ConfigurationChangeBuilder.of(config).removeKey("java.version").build(); + assertFalse(change.isKeyAffected("java.version")); + assertFalse(change.isKeyAffected("key2")); + } + + @Test + public void testIsEmpty() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationChange change = ConfigurationChangeBuilder.of(config).build(); + assertTrue(change.isEmpty()); + } + + @Test + public void testToString() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("key1", "key2").build(); + change = ConfigurationChangeBuilder.of(config).removeKey("java.version").build(); + assertTrue(change.toString().contains("timestamp")); + assertTrue(change.toString().contains("version")); + assertTrue(change.toString().contains("configuration")); + assertFalse(change.toString().contains("key1")); + assertFalse(change.toString().contains("key2")); + } +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java ---------------------------------------------------------------------- diff --git a/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java b/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java new file mode 100644 index 0000000..ee631ce --- /dev/null +++ b/events/src/test/java/org/apache/tamaya/events/delta/ConfigurationContextChangeTest.java @@ -0,0 +1,138 @@ +/* + * 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.delta; + +import org.apache.tamaya.Configuration; +import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.core.propertysource.SystemPropertySource; +import org.apache.tamaya.events.ChangeType; +import org.apache.tamaya.events.ConfigurationContextChange; +import org.apache.tamaya.events.ConfigurationContextChangeBuilder; +import org.apache.tamaya.events.PropertySourceChangeBuilder; +import org.apache.tamaya.spi.PropertySource; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Test class for {@link ConfigurationContextChange}. + */ +public class ConfigurationContextChangeTest { + + @Test + public void testEmptyChangeSet() throws Exception { + ConfigurationContextChange change = ConfigurationContextChange.emptyChangeSet( + ConfigurationProvider.getConfigurationContext()); + assertNotNull(change); + assertTrue(change.isEmpty()); + } + + @Test + public void testGetVersion() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().build(); + assertNotNull(change.getVersion()); + change = ConfigurationContextChangeBuilder.of().setVersion("version2").build(); + assertNotNull(change.getVersion()); + assertEquals("version2", change.getVersion()); + } + + @Test + public void testGetTimestamp() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().build(); + assertTrue((System.currentTimeMillis() - change.getTimestamp()) <= 10L); + change = ConfigurationContextChangeBuilder.of().setTimestamp(10L).build(); + assertEquals(10L, change.getTimestamp()); + } + + @Test + public void testGetPropertySourceChanges() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().build(); + assertTrue(change.getPropertySourceChanges(). isEmpty()); + change = ConfigurationContextChangeBuilder.of().build(); + assertTrue(change.getPropertySourceChanges(). isEmpty()); + } + + @Test + public void testGetPropertySourceUpdates() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().build(); + assertTrue(change.getPropertySourceChanges(). isEmpty()); + change = ConfigurationContextChangeBuilder.of().build(); + assertTrue(change.getPropertySourceUpdates(). isEmpty()); + } + + @Test + public void testGetRemovedPropertySources() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().build(); + assertTrue(change.getPropertySourceChanges(). isEmpty()); + change = ConfigurationContextChangeBuilder.of().build(); + assertTrue(change.getRemovedPropertySources(). isEmpty()); + } + + @Test + public void testGetAddedPropertySources() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().build(); + assertTrue(change.getPropertySourceChanges(). isEmpty()); + change = ConfigurationContextChangeBuilder.of().build(); + assertTrue(change.getAddedPropertySources().isEmpty()); + } + + @Test + public void testGetUpdatedPropertySources() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().build(); + assertTrue(change.getPropertySourceChanges(). isEmpty()); + change = ConfigurationContextChangeBuilder.of().build(); + assertTrue(change.getUpdatedPropertySources().isEmpty()); + } + + @Test + public void testIsAffected() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + PropertySource ps = new SystemPropertySource(); + ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().changedPropertySource( + PropertySourceChangeBuilder.of(ps, ChangeType.UPDATED).build() + ).build(); + String toString = change.toString(); + assertTrue(change.isAffected(ps)); + } + + @Test + public void testIsEmpty() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().build(); + assertTrue(change.isEmpty()); + change = ConfigurationContextChangeBuilder.of().newPropertySource(new SystemPropertySource()).build(); + assertFalse(change.isEmpty()); + } + + @Test + public void testToString() throws Exception { + Configuration config = ConfigurationProvider.getConfiguration(); + ConfigurationContextChange change = ConfigurationContextChangeBuilder.of().newPropertySource(new SystemPropertySource()).build(); + String toString = change.toString(); + assertNotNull(toString); + assertTrue(toString.contains(new SystemPropertySource().getName())); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java ---------------------------------------------------------------------- diff --git a/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java b/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java new file mode 100644 index 0000000..0dcdfba --- /dev/null +++ b/events/src/test/java/org/apache/tamaya/events/delta/PropertySourceChangeTest.java @@ -0,0 +1,209 @@ +/* + * 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.delta; + +import org.apache.tamaya.core.propertysource.EnvironmentPropertySource; +import org.apache.tamaya.core.propertysource.SimplePropertySource; +import org.apache.tamaya.core.propertysource.SystemPropertySource; +import org.apache.tamaya.events.ChangeType; +import org.apache.tamaya.events.PropertySourceChange; +import org.apache.tamaya.events.PropertySourceChangeBuilder; +import org.apache.tamaya.spi.PropertySource; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.*; + +/** + * Tests for {@link PropertySourceChange} and its builder. + */ +public class PropertySourceChangeTest { + + private static final PropertySource myPS = new SystemPropertySource(); + + @Test + public void testGetChangeType() throws Exception { + PropertySourceChange change = PropertySourceChangeBuilder.of(myPS, ChangeType.DELETED).build(); + assertEquals(change.getChangeType(), ChangeType.DELETED); + change = PropertySourceChangeBuilder.of(myPS, ChangeType.UPDATED).build(); + assertEquals(change.getChangeType(), ChangeType.UPDATED); + } + + @Test + public void testGetPropertySource() throws Exception { + PropertySourceChange change = PropertySourceChangeBuilder.of(myPS, ChangeType.DELETED).build(); + assertEquals(change.getResource().getName(), myPS.getName()); + } + + @Test + public void testGetVersion() throws Exception { + PropertySourceChange change = PropertySourceChangeBuilder.of(myPS, ChangeType.DELETED) + .setVersion("myVersion1").build(); + assertEquals(change.getVersion(), "myVersion1"); + } + + @Test + public void testGetTimestamp() throws Exception { + PropertySourceChange change = PropertySourceChangeBuilder.of(myPS, ChangeType.DELETED) + .setTimestamp(111L).build(); + assertEquals(change.getTimestamp(), 111L); + } + + @Test + public void testGetEvents() throws Exception { + PropertySourceChange change = PropertySourceChangeBuilder.of(myPS, ChangeType.DELETED) + .addChanges( + new EnvironmentPropertySource() + ).build(); + assertTrue(change.getChanges().size()>0); + } + + @Test + public void testGetRemovedSize() throws Exception { + PropertySourceChange change = PropertySourceChangeBuilder.of(myPS, ChangeType.UPDATED) + .addChanges( + new EnvironmentPropertySource() + ).build(); + assertTrue(change.getRemovedSize()>0); + } + + @Test + public void testGetAddedSize() throws Exception { + PropertySourceChange change = PropertySourceChangeBuilder.of(myPS, ChangeType.DELETED) + .addChanges( + new EnvironmentPropertySource() + ).build(); + assertTrue(change.getAddedSize()>0); + } + + @Test + public void testGetUpdatedSize() throws Exception { + PropertySourceChange change = PropertySourceChangeBuilder.of(myPS, ChangeType.DELETED) + .addChanges( + new EnvironmentPropertySource() + ).build(); + assertTrue(change.getUpdatedSize()==0); + } + + @Test + public void testIsRemoved() throws Exception { + Map<String, String> testData = new HashMap<>(); + testData.put("key1", "value1"); + testData.put("key2", "value2"); + PropertySource ps1 = new SimplePropertySource("test", testData); + testData = new HashMap<>(); + testData.put("key1", "value2"); + testData.put("key3", "value3"); + PropertySource ps2 = new SimplePropertySource("test", testData); + PropertySourceChange change = PropertySourceChangeBuilder.of(ps1, ChangeType.UPDATED) + .addChanges( + ps2 + ).build(); + assertFalse(change.isRemoved("key1")); + assertTrue(change.isRemoved("key2")); + assertFalse(change.isRemoved("key3")); + } + + @Test + public void testIsAdded() throws Exception { + Map<String, String> testData = new HashMap<>(); + testData.put("key1", "value1"); + testData.put("key2", "value2"); + PropertySource ps1 = new SimplePropertySource("test", testData); + testData = new HashMap<>(); + testData.put("key1", "value2"); + testData.put("key3", "value3"); + PropertySource ps2 = new SimplePropertySource("test", testData); + PropertySourceChange change = PropertySourceChangeBuilder.of(ps1, ChangeType.UPDATED) + .addChanges( + ps2 + ).build(); + assertTrue(change.isAdded("key3")); + assertFalse(change.isAdded("key2")); + assertFalse(change.isAdded("key1")); + } + + @Test + public void testIsUpdated() throws Exception { + Map<String, String> testData = new HashMap<>(); + testData.put("key1", "value1"); + testData.put("key2", "value2"); + PropertySource ps1 = new SimplePropertySource("test", testData); + testData = new HashMap<>(); + testData.put("key1", "value2"); + testData.put("key3", "value3"); + PropertySource ps2 = new SimplePropertySource("test", testData); + PropertySourceChange change = PropertySourceChangeBuilder.of(ps1, ChangeType.UPDATED) + .addChanges( + ps2 + ).build(); + assertTrue(change.isUpdated("key1")); + assertFalse(change.isUpdated("key2")); + assertFalse(change.isUpdated("key3")); + } + + @Test + public void testContainsKey() throws Exception { + PropertySourceChange change = PropertySourceChangeBuilder.of(new EnvironmentPropertySource(), ChangeType.DELETED) + .addChanges( + myPS + ).build(); + assertTrue(change.isKeyAffected("java.version")); + } + + @Test + public void testIsEmpty() throws Exception { + PropertySourceChange change = PropertySourceChangeBuilder.of(new EnvironmentPropertySource(), ChangeType.DELETED) + .build(); + assertTrue(change.isEmpty()); + change = PropertySourceChangeBuilder.of(new EnvironmentPropertySource(), ChangeType.DELETED) + .addChanges( + myPS + ).build(); + assertFalse(change.isEmpty()); + } + + @Test + public void testOfAdded() throws Exception { + PropertySourceChange change = PropertySourceChange.ofAdded(myPS); + assertNotNull(change); + assertEquals(change.getChangeType(), ChangeType.NEW); + } + + @Test + public void testOfDeleted() throws Exception { + PropertySourceChange change = PropertySourceChange.ofDeleted(myPS); + assertNotNull(change); + assertEquals(change.getChangeType(), ChangeType.DELETED); + } + + @Test + public void testToString() throws Exception { + PropertySourceChange change = PropertySourceChange.ofAdded(myPS); + String toString = change.toString(); + assertNotNull(toString); + assertTrue(toString.contains(myPS.getName())); + change = PropertySourceChange.ofDeleted(myPS); + toString = change.toString(); + assertNotNull(toString); + assertTrue(toString.contains(myPS.getName())); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpiTest.java ---------------------------------------------------------------------- diff --git a/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpiTest.java b/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpiTest.java new file mode 100644 index 0000000..d54a66e --- /dev/null +++ b/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpiTest.java @@ -0,0 +1,66 @@ +/* + * 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.internal; + +import org.apache.tamaya.events.ConfigEvent; +import org.apache.tamaya.events.ConfigEventListener; +import org.apache.tamaya.events.SimpleEvent; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Tests for {@link DefaultConfigEventManagerSpi}. + */ +public class DefaultConfigEventManagerSpiTest { + + private final DefaultConfigEventManagerSpi spi = new DefaultConfigEventManagerSpi(); + private Object testAddListenerValue; + + @Test + public void testAddListener() throws Exception { + ConfigEventListener testListener = new ConfigEventListener() { + @Override + public void onConfigEvent(ConfigEvent<?> event) { + testAddListenerValue = event.getResource(); + } + }; + spi.addListener(testListener); + spi.fireEvent(new SimpleEvent("Event1")); + assertEquals(testAddListenerValue, "Event1"); + spi.removeListener(testListener); + spi.fireEvent(new SimpleEvent("Event2")); + assertEquals(testAddListenerValue, "Event1"); + + } + + @Test + public void testRemoveListener() throws Exception { + ConfigEventListener testListener = new ConfigEventListener() { + + @Override + public void onConfigEvent(ConfigEvent<?> event) { + testAddListenerValue = event; + } + }; + spi.removeListener(testListener); + spi.removeListener(testListener); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/events/src/test/resources/META-INF/services/org.apache.tamaya.events.ConfigEventListener ---------------------------------------------------------------------- diff --git a/events/src/test/resources/META-INF/services/org.apache.tamaya.events.ConfigEventListener b/events/src/test/resources/META-INF/services/org.apache.tamaya.events.ConfigEventListener new file mode 100644 index 0000000..f675fd6 --- /dev/null +++ b/events/src/test/resources/META-INF/services/org.apache.tamaya.events.ConfigEventListener @@ -0,0 +1,19 @@ +# +# 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 current 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. +# +org.apache.tamaya.events.internal.DefaultConfigurationContextChangeListener \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/events/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource ---------------------------------------------------------------------- diff --git a/events/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/events/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource new file mode 100644 index 0000000..9c2b9f6 --- /dev/null +++ b/events/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource @@ -0,0 +1,19 @@ +# +# 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 current 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. +# +org.apache.tamaya.events.RandomPropertySource http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/events/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider ---------------------------------------------------------------------- diff --git a/events/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/events/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider new file mode 100644 index 0000000..d34b4a2 --- /dev/null +++ b/events/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider @@ -0,0 +1,19 @@ +# +# 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 current 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. +# +org.apache.tamaya.events.TestObservingProvider http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/events/src/test/resources/data/test1.properties ---------------------------------------------------------------------- diff --git a/events/src/test/resources/data/test1.properties b/events/src/test/resources/data/test1.properties new file mode 100644 index 0000000..0df3bd1 --- /dev/null +++ b/events/src/test/resources/data/test1.properties @@ -0,0 +1,20 @@ +# +# 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 current 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. +# +1=val1 +3=val3 http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/events/src/test/resources/data/test1b.properties ---------------------------------------------------------------------- diff --git a/events/src/test/resources/data/test1b.properties b/events/src/test/resources/data/test1b.properties new file mode 100644 index 0000000..ec57163 --- /dev/null +++ b/events/src/test/resources/data/test1b.properties @@ -0,0 +1,20 @@ +# +# 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 current 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. +# +1b=val1 +7=val7 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/events/src/test/resources/data/test2.properties ---------------------------------------------------------------------- diff --git a/events/src/test/resources/data/test2.properties b/events/src/test/resources/data/test2.properties new file mode 100644 index 0000000..0643c1d --- /dev/null +++ b/events/src/test/resources/data/test2.properties @@ -0,0 +1,20 @@ +# +# 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 current 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. +# +4=val4 +6=val6 http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/events/src/test/resources/data/test3.properties ---------------------------------------------------------------------- diff --git a/events/src/test/resources/data/test3.properties b/events/src/test/resources/data/test3.properties new file mode 100644 index 0000000..bb856c7 --- /dev/null +++ b/events/src/test/resources/data/test3.properties @@ -0,0 +1,20 @@ +# +# 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 current 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. +# +2=val2 +5=val5 http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/events/src/test/resources/test.properties ---------------------------------------------------------------------- diff --git a/events/src/test/resources/test.properties b/events/src/test/resources/test.properties new file mode 100644 index 0000000..af06631 --- /dev/null +++ b/events/src/test/resources/test.properties @@ -0,0 +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 current 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. +# +testValue1=value +test=test2 +a=b \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml deleted file mode 100644 index d274633..0000000 --- a/pom.xml +++ /dev/null @@ -1,100 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- -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 current 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. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-extensions</artifactId> - <version>0.3-incubating-SNAPSHOT</version> - </parent> - - <artifactId>tamaya-events</artifactId> - <name>Apache Tamaya Modules - Event and dynamic Update Extensions</name> - <packaging>bundle</packaging> - - <properties> - <jdkVersion>1.7</jdkVersion> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-api</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-functions</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-spisupport</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-core</artifactId> - <version>${project.version}</version> - <scope>runtime</scope> - </dependency> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>java-hamcrest</artifactId> - </dependency> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Export-Package> - org.apache.tamaya.events, - org.apache.tamaya.events.delta, - org.apache.tamaya.events.folderobserver, - org.apache.tamaya.events.spi - </Export-Package> - <Private-Package> - org.apache.tamaya.events.internal - </Private-Package> - </instructions> - </configuration> - </plugin> - </plugins> - </build> - - -</project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/src/main/java/org/apache/tamaya/events/ChangeType.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/tamaya/events/ChangeType.java b/src/main/java/org/apache/tamaya/events/ChangeType.java deleted file mode 100644 index 2059017..0000000 --- a/src/main/java/org/apache/tamaya/events/ChangeType.java +++ /dev/null @@ -1,31 +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.events; - -/** - * Enum describing the type of configuration change. - */ -public enum ChangeType { - /** Configuration hase been added. */ - NEW, - /** Configuration hase been removed. */ - DELETED, - /** Configuration hase been changed. */ - UPDATED, -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/src/main/java/org/apache/tamaya/events/ConfigEvent.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/tamaya/events/ConfigEvent.java b/src/main/java/org/apache/tamaya/events/ConfigEvent.java deleted file mode 100644 index 5a713d7..0000000 --- a/src/main/java/org/apache/tamaya/events/ConfigEvent.java +++ /dev/null @@ -1,55 +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.events; - - -/** - * Event that contains a set current changes that were applied or could be applied. - * @param <T> the resource type. - */ -public interface ConfigEvent<T>{ - - /** - * Access the type of resource. This allows to easily determine the resource an event wants to observe. - * @return the resource type. - */ - Class<T> getResourceType(); - - /** - * Get the underlying property provider/configuration. - * @return the underlying property provider/configuration, never null. - */ - T getResource(); - - /** - * Get the version relative to the observed resource. The version is required to be unique for - * each change emmitted for a resource. There is no further requirement how this uniqueness is - * modelled, so returning a UUID is a completely valid strategy. - * @return the base version. - */ - String getVersion(); - - /** - * Get the timestamp in millis from the current epoch. it is expected that the timestamp and the version are unique to - * identify a changeset. - * @return the timestamp, when this changeset was created. - */ - long getTimestamp(); - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/src/main/java/org/apache/tamaya/events/ConfigEventListener.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/tamaya/events/ConfigEventListener.java b/src/main/java/org/apache/tamaya/events/ConfigEventListener.java deleted file mode 100644 index 7fb32c8..0000000 --- a/src/main/java/org/apache/tamaya/events/ConfigEventListener.java +++ /dev/null @@ -1,31 +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.events; - -/** - * Interface to be implemented for listening on changes on {@link org.apache.tamaya.Configuration} instances. - */ -public interface ConfigEventListener { - /** - * Called if an event occurred. - * @param event the event, not null. - */ - void onConfigEvent(ConfigEvent<?> event); - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/src/main/java/org/apache/tamaya/events/ConfigEventManager.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/tamaya/events/ConfigEventManager.java b/src/main/java/org/apache/tamaya/events/ConfigEventManager.java deleted file mode 100644 index f6bd3da..0000000 --- a/src/main/java/org/apache/tamaya/events/ConfigEventManager.java +++ /dev/null @@ -1,186 +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.events; - -import org.apache.tamaya.ConfigException; -import org.apache.tamaya.events.spi.ConfigEventManagerSpi; -import org.apache.tamaya.spi.ServiceContextManager; - -import java.util.Collection; - -/** - * Singleton accessor for accessing the event support component that distributes change events of - * {@link org.apache.tamaya.spi.PropertySource} and {@link org.apache.tamaya.Configuration}. - */ -public final class ConfigEventManager { - /** - * The backing SPI. - */ - private static final ConfigEventManagerSpi SPI = ServiceContextManager.getServiceContext() - .getService(ConfigEventManagerSpi.class); - - /** - * Private singleton constructor. - */ - private ConfigEventManager() { - } - - /** - * Adds a Config listener that listens to all kind of {@link ConfigEvent}. - * @param l the listener not null. - */ - public static void addListener(ConfigEventListener l) { - if (SPI == null) { - throw new ConfigException("No SPI registered for " + - ConfigEventManager.class.getName()); - } - SPI.addListener(l); - } - - /** - * Adds a Config listener that listens to all kind of {@link ConfigEvent}. - * @param <T> the type of the event. - * @param l the listener not null. - * @param eventType the event type to which this listener listens to. - */ - public static <T extends ConfigEvent> void addListener(ConfigEventListener l, Class<T> eventType) { - if (SPI == null) { - throw new ConfigException("No SPI registered for " + - ConfigEventManager.class.getName()); - } - SPI.addListener(l); - } - - /** - * Removes a listener registered globally. - * - * @param l the listener not null. - */ - public static void removeListener(ConfigEventListener l) { - if (SPI == null) { - throw new ConfigException("No SPI registered for " + - ConfigEventManager.class.getName()); - } - SPI.removeListener(l); - } - - /** - * Removes a listener registered for the given event type. - * - * @param <T> the type of the event. - * @param l the listener, not null. - * @param eventType the event type to which this listener listens to. - */ - public static <T extends ConfigEvent> void removeListener(ConfigEventListener l, Class<T> eventType) { - if (SPI == null) { - throw new ConfigException("No SPI registered for " + - ConfigEventManager.class.getName()); - } - SPI.removeListener(l); - } - - /** - * Access all registered ConfigEventListeners listening to a given event type. - * @param type the event type - * @param <T> type param - * @return a list with the listeners found, never null. - */ - public static <T extends ConfigEvent> - Collection<? extends ConfigEventListener> getListeners(Class<T> type) { - return SPI.getListeners(type); - } - - /** - * Access all registered ConfigEventListeners listening to a all kind of event types globally. - * - * @param <T> the type of the event. - * @return a list with the listeners found, never null. - */ - public static <T extends ConfigEvent> - Collection<? extends ConfigEventListener> getListeners() { - return SPI.getListeners(); - } - - /** - * Publishes a {@link ConfigurationChange} synchronously to all interested listeners. - * - * @param <T> the type of the event. - * @param event the event, not null. - */ - public static <T> void fireEvent(ConfigEvent<?> event) { - SPI.fireEvent(event); - } - - /** - * Publishes a {@link ConfigurationChange} asynchronously/multithreaded to all interested listeners. - * - * @param <T> the type of the event. - * @param event the event, not null. - */ - public static <T> void fireEventAsynch(ConfigEvent<?> event) { - SPI.fireEventAsynch(event); - } - - /** - * Start/Stop the change monitoring service, which will observe/reevaluate the current configuration regularly - * and trigger ConfigurationChange events if something changed. This is quite handy for publishing - * configuration changes to whatever systems are interested in. Hereby the origin of a configuration change - * can be on this machine, or also remotely. For handling corresponding {@link ConfigEventListener} have - * to be registered, e.g. listening on {@link org.apache.tamaya.events.ConfigurationChange} events. - * - * @param enable whether to enable or disable the change monitoring. - * - * @see #isChangeMonitoring() - * @see #getChangeMonitoringPeriod() - */ - public static void enableChangeMonitoring(boolean enable) { - SPI.enableChangeMonitor(enable); - } - - /** - * Check if the observer is running currently. - * - * @return true, if the change monitoring service is currently running. - * @see #enableChangeMonitoring(boolean) - */ - public static boolean isChangeMonitoring() { - return SPI.isChangeMonitorActive(); - } - - /** - * Get the current check period to check for configuration changes. - * - * @return the check period in ms. - */ - public static long getChangeMonitoringPeriod(){ - return SPI.getChangeMonitoringPeriod(); - } - - /** - * Sets the current monitoring period and restarts the monitor. You still have to enable the monitor if - * it is currently not enabled. - * @param millis the monitoring period in ms. - * @see #enableChangeMonitoring(boolean) - * @see #isChangeMonitoring() - */ - public static void setChangeMonitoringPeriod(long millis){ - SPI.setChangeMonitoringPeriod(millis); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/src/main/java/org/apache/tamaya/events/ConfigurationChange.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/tamaya/events/ConfigurationChange.java b/src/main/java/org/apache/tamaya/events/ConfigurationChange.java deleted file mode 100644 index c31cda2..0000000 --- a/src/main/java/org/apache/tamaya/events/ConfigurationChange.java +++ /dev/null @@ -1,218 +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.events; - -import org.apache.tamaya.Configuration; - -import java.beans.PropertyChangeEvent; -import java.io.Serializable; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -/** - * Event that contains a set current changes that were applied or could be applied. - * This class is immutable and thread-safe. To create instances use - * {@link PropertySourceChangeBuilder}. - * - * Created by Anatole on 22.10.2014. - */ -public final class ConfigurationChange implements ConfigEvent<Configuration>, Serializable{ - - private static final long serialVersionUID = 1L; - /** The base property provider/configuration. */ - private final FrozenConfiguration configuration; - /** The base version, usable for optimistic locking. */ - private String version = UUID.randomUUID().toString(); - /** The timestamp of the change set in millis from the epoch. */ - private long timestamp = System.currentTimeMillis(); - /** The recorded changes. */ - private final Map<String,PropertyChangeEvent> changes = new HashMap<>(); - - /** - * Get an empty change set for the given provider. - * @param configuration The configuration changed, not null. - * @return an empty ConfigurationChangeSet instance. - */ - public static ConfigurationChange emptyChangeSet(Configuration configuration){ - return ConfigurationChangeBuilder.of(configuration).build(); - } - - /** - * Constructor used by {@link PropertySourceChangeBuilder}. - * @param builder The builder used, not null. - */ - ConfigurationChange(ConfigurationChangeBuilder builder) { - this.configuration = FrozenConfiguration.of(builder.source); - for(PropertyChangeEvent ev:builder.delta.values()){ - this.changes.put(ev.getPropertyName(), ev); - } - if(builder.version!=null){ - this.version = builder.version; - } - if(builder.timestamp!=null){ - this.timestamp = builder.timestamp; - } - } - - @Override - public Class<Configuration> getResourceType() { - return Configuration.class; - } - - /** - * Get the underlying property provider/configuration. - * @return the underlying property provider/configuration, never null. - */ - @Override - public Configuration getResource(){ - return this.configuration; - } - - /** - * Get the base version, usable for optimistic locking. - * @return the base version. - */ - @Override - public String getVersion(){ - return version; - } - - /** - * Get the timestamp in millis from the current epoch. it is expected that the timestamp and the version are unique to - * identify a changeset. - * @return the timestamp, when this changeset was created. - */ - @Override - public long getTimestamp(){ - return timestamp; - } - - /** - * Get the changes recorded. - * @return the recorded changes, never null. - */ - public Collection<PropertyChangeEvent> getChanges(){ - return Collections.unmodifiableCollection(this.changes.values()); - } - - /** - * Access the number current removed entries. - * @return the number current removed entries. - */ - public int getRemovedSize() { - int removedCount = 0; - for(PropertyChangeEvent ev:this.changes.values()){ - if(ev.getNewValue() == null){ - removedCount++; - } - } - return removedCount; - } - - /** - * Access the number current added entries. - * @return the number current added entries. - */ - public int getAddedSize() { - int addedCount = 0; - for(PropertyChangeEvent ev:this.changes.values()){ - if(ev.getOldValue() == null && - ev.getNewValue() != null){ - addedCount++; - } - } - return addedCount; - } - - /** - * Access the number current updated entries. - * @return the number current updated entries. - */ - public int getUpdatedSize() { - int updatedCount = 0; - for(PropertyChangeEvent ev:this.changes.values()){ - if( ev.getOldValue()!=null && ev.getNewValue()!=null){ - updatedCount++; - } - } - return updatedCount; - } - - - /** - * Checks if the given key was removed. - * @param key the target key, not null. - * @return true, if the given key was removed. - */ - public boolean isRemoved(String key) { - PropertyChangeEvent change = this.changes.get(key); - return change != null && change.getNewValue() == null; - } - - /** - * Checks if the given key was added. - * @param key the target key, not null. - * @return true, if the given key was added. - */ - public boolean isAdded(String key) { - PropertyChangeEvent change = this.changes.get(key); - return change != null && change.getOldValue() == null; - } - - /** - * Checks if the given key was updated. - * @param key the target key, not null. - * @return true, if the given key was updated. - */ - public boolean isUpdated(String key) { - PropertyChangeEvent change = this.changes.get(key); - return change != null && change.getOldValue() != null && change.getNewValue() != null; - } - - /** - * Checks if the given key is added, or updated AND NOT removed. - * @param key the target key, not null. - * @return true, if the given key was added, or updated BUT NOT removed. - */ - public boolean isKeyAffected(String key) { - PropertyChangeEvent change = this.changes.get(key); - return change != null && change.getNewValue() != null; - } - - /** - * CHecks if the current change set does not contain any changes. - * @return tru, if the change set is empty. - */ - public boolean isEmpty(){ - return this.changes.isEmpty(); - } - - - @Override - public String toString() { - return "ConfigurationChange{" + - "configuration=" + configuration + - ", version='" + version + '\'' + - ", timestamp=" + timestamp + - '}'; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/src/main/java/org/apache/tamaya/events/ConfigurationChangeBuilder.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/tamaya/events/ConfigurationChangeBuilder.java b/src/main/java/org/apache/tamaya/events/ConfigurationChangeBuilder.java deleted file mode 100644 index 1fd228a..0000000 --- a/src/main/java/org/apache/tamaya/events/ConfigurationChangeBuilder.java +++ /dev/null @@ -1,274 +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.events; - -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; - -import java.beans.PropertyChangeEvent; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.SortedMap; -import java.util.TreeMap; - -/** - * Models a set current changes applied to a {@link org.apache.tamaya.spi.PropertySource}. Consumers of these events - * can observing changes to property sources and - * <ol> - * <li>Check if their current configuration instance ({@link org.apache.tamaya.spi.ConfigurationContext} - * contains the changed {@link org.apache.tamaya.spi.PropertySource} (Note: the reference tova property source is never affected by a - * change, its only the data of the property source).</li> - * <li>If so corresponding action may be taken, such as reevaluating the configuration values (depending on - * the update policy) or reevaluating the complete {@link org.apache.tamaya.Configuration} to create a change - * event on configuration level. - * </ol> - */ -public final class ConfigurationChangeBuilder { - /** - * The recorded changes. - */ - final SortedMap<String, PropertyChangeEvent> delta = new TreeMap<>(); - /** - * The underlying configuration/provider. - */ - final Configuration source; - /** - * The version configured, or null, for generating a default. - */ - String version; - /** - * The optional timestamp in millis of this epoch. - */ - Long timestamp; - - /** - * Constructor. - * - * @param configuration the underlying configuration, not null. - */ - private ConfigurationChangeBuilder(Configuration configuration) { - this.source = Objects.requireNonNull(configuration); - } - - /** - * Creates a new instance current this builder using the current COnfiguration as root resource. - * - * @return the builder for chaining. - */ - public static ConfigurationChangeBuilder of() { - return new ConfigurationChangeBuilder(ConfigurationProvider.getConfiguration()); - } - - /** - * Creates a new instance current this builder. - * - * @param configuration the configuration changed, not null. - * @return the builder for chaining. - */ - public static ConfigurationChangeBuilder of(Configuration configuration) { - return new ConfigurationChangeBuilder(configuration); - } - - /** - * 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(Configuration map1, Configuration map2) { - List<PropertyChangeEvent> changes = new ArrayList<>(); - for (Map.Entry<String, String> en : map1.getProperties().entrySet()) { - String val = map2.get(en.getKey()); - if (val == null) { - changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue())); - } else if (!val.equals(en.getValue())) { - changes.add(new PropertyChangeEvent(map1, en.getKey(), val, en.getValue())); - } - } - for (Map.Entry<String, String> en : map2.getProperties().entrySet()) { - String val = map1.get(en.getKey()); - if (val == null) { - changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue())); - } else if (!val.equals(en.getValue())) { - changes.add(new PropertyChangeEvent(map1, en.getKey(), val, en.getValue())); - } - } - return changes; - } - - /* - * Apply a version/UUID to the set being built. - * @param version the version to apply, or null, to let the system generate a version for you. - * @return the builder for chaining. - */ - public ConfigurationChangeBuilder setVersion(String version) { - this.version = version; - return this; - } - - /* - * Apply given timestamp to the set being built. - * @param version the version to apply, or null, to let the system generate a version for you. - * @return the builder for chaining. - */ - public ConfigurationChangeBuilder setTimestamp(long timestamp) { - this.timestamp = timestamp; - return this; - } - - /** - * 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 ConfigurationChangeBuilder addChanges(Configuration newState) { - for (PropertyChangeEvent c : compare(newState, this.source)) { - this.delta.put(c.getPropertyName(), c); - } - return this; - } - - /** - * Applies a single key/value change. - * - * @param key the changed key - * @param value the new value. - * @return this instance for chining. - */ - public ConfigurationChangeBuilder addChange(String key, String value) { - this.delta.put(key, new PropertyChangeEvent(this.source, key, this.source.get(key), value)); - 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 ConfigurationChangeBuilder removeKey(String key, String... otherKeys) { - String oldValue = this.source.get(key); - 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); - if (oldValue == null) { - this.delta.remove(addKey); - } - this.delta.put(addKey, new PropertyChangeEvent(this.source, addKey, oldValue, null)); - } - 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 ConfigurationChangeBuilder putAll(Map<String, String> changes) { - for (Map.Entry<String, String> en : changes.entrySet()) { - this.delta.put(en.getKey(), new PropertyChangeEvent(this.source, en.getKey(), null, en.getValue())); - } - 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 ConfigurationChangeBuilder removeAllKeys() { - this.delta.clear(); - for (Map.Entry<String, String> en : this.source.getProperties().entrySet()) { - this.delta.put(en.getKey(), new PropertyChangeEvent(this.source, en.getKey(), en.getValue(), null)); - } -// 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 ConfigurationChange build() { - return new ConfigurationChange(this); - } - - /* - * (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "ConfigurationChangeSetBuilder [config=" + source + ", " + - ", delta=" + delta + "]"; - } - - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/src/main/java/org/apache/tamaya/events/ConfigurationContextChange.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/tamaya/events/ConfigurationContextChange.java b/src/main/java/org/apache/tamaya/events/ConfigurationContextChange.java deleted file mode 100644 index 4e12d42..0000000 --- a/src/main/java/org/apache/tamaya/events/ConfigurationContextChange.java +++ /dev/null @@ -1,210 +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.events; - -import org.apache.tamaya.spi.ConfigurationContext; -import org.apache.tamaya.spi.PropertySource; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.UUID; - -/** - * Event that contains a set of current changes that were applied or can be applied. - * This class is immutable and thread-safe. To create instances use - * {@link PropertySourceChangeBuilder}. - * - * Created by Anatole on 22.10.2014. - */ -public final class ConfigurationContextChange implements ConfigEvent<ConfigurationContext>, Serializable{ - - private static final long serialVersionUID = 1L; - /** The base property provider/configuration. */ - private final List<PropertySourceChange> changedPropertySources = new ArrayList<>(); - /** The base version, usable for optimistic locking. */ - private String version = UUID.randomUUID().toString(); - /** The timestamp of the change set in millis from the epoch. */ - private long timestamp = System.currentTimeMillis(); - /** The configuration context. */ - private final ConfigurationContext configurationContext; - - /** - * Get an empty change set for the given provider. - * - * @param configurationContext context to use for creating changesets. - * @return an empty ConfigurationContextChange instance. - */ - public static ConfigurationContextChange emptyChangeSet(ConfigurationContext configurationContext){ - return ConfigurationContextChangeBuilder.of(configurationContext).build(); - } - - /** - * Constructor used by {@link PropertySourceChangeBuilder}. - * @param builder The builder used, not null. - */ - ConfigurationContextChange(ConfigurationContextChangeBuilder builder) { - this.changedPropertySources.addAll(builder.changedPropertySources); - if(builder.version!=null){ - this.version = builder.version; - } - if(builder.timestamp!=null){ - this.timestamp = builder.timestamp; - } - this.configurationContext = builder.configurationContext; - } - - @Override - public Class<ConfigurationContext> getResourceType() { - return ConfigurationContext.class; - } - - @Override - public ConfigurationContext getResource() { - return configurationContext; - } - - /** - * Get the base version, usable for optimistic locking. - * @return the base version. - */ - @Override - public String getVersion(){ - return version; - } - - /** - * Get the timestamp in millis from the current epoch. it is expected that the timestamp and the version are unique to - * identify a changeset. - * @return the timestamp, when this changeset was created. - */ - @Override - public long getTimestamp(){ - return timestamp; - } - - /** - * Get the changes recorded. - * @return the recorded changes, never null. - */ - public Collection<PropertySourceChange> getPropertySourceChanges(){ - return Collections.unmodifiableCollection(this.changedPropertySources); - } - - /** - * Get the property source updates. - * @return the recorded changes, never null. - */ - public Collection<PropertySourceChange> getPropertySourceUpdates(){ - List<PropertySourceChange> result = new ArrayList<>(); - for (PropertySourceChange pc : this.changedPropertySources) { - if (pc.getChangeType() == ChangeType.UPDATED) { - result.add(pc); - } - } - return result; -// return Collections.unmodifiableCollection(this.changedPropertySources).stream() -// .filter(pc -> pc.getChangeType()==ChangeType.UPDATED).collect(Collectors.toList()); - } - - /** - * Get the property sources to be removed. - * @return the recorded changes, never null. - */ - public Collection<PropertySource> getRemovedPropertySources(){ - List<PropertySource> result = new ArrayList<>(); - for (PropertySourceChange pc : this.changedPropertySources) { - if (pc.getChangeType() == ChangeType.DELETED) { - result.add(pc.getResource()); - } - } - return result; -// return getPropertySourceChanges().stream().filter(pc -> pc.getChangeType()==ChangeType.DELETED). -// map(ps -> ps.getPropertySource()).collect(Collectors.toList()); - } - - /** - * Get the property sources to be added. - * @return the recorded changes, never null. - */ - public Collection<PropertySource> getAddedPropertySources(){ - List<PropertySource> result = new ArrayList<>(); - for (PropertySourceChange pc : this.changedPropertySources) { - if (pc.getChangeType() == ChangeType.NEW) { - result.add(pc.getResource()); - } - } - return result; -// return getPropertySourceChanges().stream().filter(pc -> pc.getChangeType()==ChangeType.NEW). -// map(ps -> ps.getPropertySource()).collect(Collectors.toList()); - } - - /** - * Get the property sources to be updated. - * @return the recorded changes, never null. - */ - public Collection<PropertySource> getUpdatedPropertySources(){ - List<PropertySource> result = new ArrayList<>(); - for (PropertySourceChange pc : this.changedPropertySources) { - if (pc.getChangeType() == ChangeType.UPDATED) { - result.add(pc.getResource()); - } - } - return result; -// return getPropertySourceChanges().stream().filter(pc -> pc.getChangeType()==ChangeType.UPDATED). -// map(ps -> ps.getPropertySource()).collect(Collectors.toList()); - } - - /** - * Checks if the given propertySource is affected (added, changed or removed). - * @param propertySource the propertySource, not null. - * @return true, if the given propertySource ia affected. - */ - public boolean isAffected(PropertySource propertySource) { - for (PropertySourceChange ps : this.changedPropertySources) { - if (ps.getResource() == propertySource || - ps.getResource().getName().equals(propertySource.getName())) { - return true; - } - } - return false; -// return this.changedPropertySources.stream().filter(ps -> ps.getPropertySource()==propertySource || -// ps.getPropertySource().getName().equals(propertySource.getName())).findAny().isPresent(); - } - - /** - * CHecks if the current change set does not contain any changes. - * @return tru, if the change set is empty. - */ - public boolean isEmpty(){ - return this.changedPropertySources.isEmpty(); - } - - - @Override - public String toString() { - return "ConfigurationContextChange{" + - "changedPropertySources=" + changedPropertySources + - ", version='" + version + '\'' + - ", timestamp=" + timestamp + - '}'; - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89223dcd/src/main/java/org/apache/tamaya/events/ConfigurationContextChangeBuilder.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/tamaya/events/ConfigurationContextChangeBuilder.java b/src/main/java/org/apache/tamaya/events/ConfigurationContextChangeBuilder.java deleted file mode 100644 index b586428..0000000 --- a/src/main/java/org/apache/tamaya/events/ConfigurationContextChangeBuilder.java +++ /dev/null @@ -1,174 +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.events; - -import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.spi.ConfigurationContext; -import org.apache.tamaya.spi.PropertySource; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -/** - * Models a set of current changes applied to a {@link org.apache.tamaya.spi.PropertySource}. Consumers of these events - * can observe changes to property sources and - * <ol> - * <li>check if their current configuration instance ({@link org.apache.tamaya.spi.ConfigurationContext} - * contains the changed {@link org.apache.tamaya.spi.PropertySource} (Note: the reference to a property source is never affected by a - * change, it is the data of the property source only).</li> - * <li>if so, a corresponding action may be taken, such as reevaluating the configuration values (depending on - * the update policy) or reevaluating the complete {@link org.apache.tamaya.Configuration} to create a change - * event on configuration level. - * </ol> - */ -public final class ConfigurationContextChangeBuilder { - /** - * The recorded changes. - */ - final List<PropertySourceChange> changedPropertySources = new ArrayList<>(); - /** - * The version configured, or null, for generating a default. - */ - String version; - /** - * The optional timestamp in millis of this epoch. - */ - Long timestamp; - - final ConfigurationContext configurationContext; - - /** - * Constructor. - */ - private ConfigurationContextChangeBuilder(ConfigurationContext configurationContext) { - this.configurationContext = Objects.requireNonNull(configurationContext); - } - - /** - * Just creates a new ConfigurationContextBuilder using the current COnfigurationContext has root resource. - * @return a new ConfigurationContextBuilder, never null. - */ - public static ConfigurationContextChangeBuilder of() { - return of(ConfigurationProvider.getConfigurationContext()); - } - - /** - * Creates a new instance current this builder. - * - * @param context context to use for creating changesets. - * @return the builder for chaining. - */ - public static ConfigurationContextChangeBuilder of(ConfigurationContext context) { - return new ConfigurationContextChangeBuilder(context); - } - - /** - * Apply a version/UUID to the set being built. - * @param version the version to apply, or null, to let the system generate a version for you. - * @return the builder for chaining. - */ - public ConfigurationContextChangeBuilder setVersion(String version) { - this.version = version; - return this; - } - - /** - * Apply given timestamp to the set being built. - * @param timestamp timestamp to set. - * @return the builder for chaining. - */ - public ConfigurationContextChangeBuilder setTimestamp(long timestamp) { - this.timestamp = timestamp; - return this; - } - - /** - * This method records all changes to be applied to the base property provider/configuration to - * achieve the given target state. - * - * @param propertySource the new target state, not null. - * @return the builder for chaining. - */ - public ConfigurationContextChangeBuilder newPropertySource(PropertySource propertySource) { - this.changedPropertySources.add(PropertySourceChange.ofAdded(propertySource)); - return this; - } - - /** - * This method records all changes to be applied to the base property provider/configuration to - * achieve the given target state. - * - * @param propertySource the new target state, not null. - * @return the builder for chaining. - */ - public ConfigurationContextChangeBuilder removedPropertySource(PropertySource propertySource) { - this.changedPropertySources.add(PropertySourceChange.ofDeleted(propertySource)); - return this; - } - - /** - * This method records all changes to be applied to the base property provider/configuration to - * achieve the given target state. - * - * @param propertySourceChange the change state, not null. - * @return the builder for chaining. - */ - public ConfigurationContextChangeBuilder changedPropertySource(PropertySourceChange propertySourceChange) { - this.changedPropertySources.add(Objects.requireNonNull(propertySourceChange)); - 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.changedPropertySources.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.changedPropertySources.clear(); - } - - /** - * Builds the corresponding change set. - * - * @return the new change set, never null. - */ - public ConfigurationContextChange build() { - return new ConfigurationContextChange(this); - } - - /* - * (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "ConfigurationContextChangeBuilder [propertySources=" + changedPropertySources + "]"; - } - - -}