Repository: apex-core Updated Branches: refs/heads/master d6f17f23a -> 491e2e332
APEXCORE-674 Change access specifier of DTConfiguration.ValueEntry to private Project: http://git-wip-us.apache.org/repos/asf/apex-core/repo Commit: http://git-wip-us.apache.org/repos/asf/apex-core/commit/491e2e33 Tree: http://git-wip-us.apache.org/repos/asf/apex-core/tree/491e2e33 Diff: http://git-wip-us.apache.org/repos/asf/apex-core/diff/491e2e33 Branch: refs/heads/master Commit: 491e2e332a223304209b7835a8ac762b112b7318 Parents: d6f17f2 Author: ajaygit158 <[email protected]> Authored: Sun Mar 19 15:48:50 2017 +0530 Committer: ajaygit158 <[email protected]> Committed: Mon Mar 20 22:38:07 2017 +0530 ---------------------------------------------------------------------- .../stram/client/DTConfiguration.java | 21 +++++------- .../stram/client/DTConfigurationTest.java | 35 ++++++++++++++++++++ 2 files changed, 44 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/apex-core/blob/491e2e33/engine/src/main/java/com/datatorrent/stram/client/DTConfiguration.java ---------------------------------------------------------------------- diff --git a/engine/src/main/java/com/datatorrent/stram/client/DTConfiguration.java b/engine/src/main/java/com/datatorrent/stram/client/DTConfiguration.java index 1f19d71..45e7826 100644 --- a/engine/src/main/java/com/datatorrent/stram/client/DTConfiguration.java +++ b/engine/src/main/java/com/datatorrent/stram/client/DTConfiguration.java @@ -70,7 +70,7 @@ public class DTConfiguration implements Iterable<Map.Entry<String, String>> private final Map<String, ValueEntry> map = new LinkedHashMap<>(); private static final Logger LOG = LoggerFactory.getLogger(DTConfiguration.class); - public static class ValueEntry + private static class ValueEntry { public String value; public boolean isFinal = false; @@ -275,36 +275,33 @@ public class DTConfiguration implements Iterable<Map.Entry<String, String>> map.remove(key); } - public ValueEntry setInternal(String key, String value) + public void setInternal(String key, String value) { - ValueEntry valueEntry; - if (map.containsKey(key)) { - valueEntry = map.get(key); + ValueEntry valueEntry = map.get(key); + if (valueEntry != null) { valueEntry.value = value; } else { valueEntry = new ValueEntry(); valueEntry.scope = isLocalKey(key) ? Scope.LOCAL : Scope.TRANSIENT; + valueEntry.value = value; map.put(key, valueEntry); } - return valueEntry; } - public ValueEntry set(String key, String value, Scope scope, String description) throws ConfigException + public void set(String key, String value, Scope scope, String description) throws ConfigException { - ValueEntry valueEntry; - if (map.containsKey(key)) { - valueEntry = map.get(key); + ValueEntry valueEntry = map.get(key); + if (valueEntry != null) { if (valueEntry.isFinal) { throw new ConfigException("Cannot set final property " + key); } } else { valueEntry = new ValueEntry(); + map.put(key, valueEntry); } valueEntry.value = value; valueEntry.description = description; valueEntry.scope = isLocalKey(key) ? Scope.LOCAL : scope; - map.put(key, valueEntry); - return valueEntry; } public static boolean isLocalKey(String key) http://git-wip-us.apache.org/repos/asf/apex-core/blob/491e2e33/engine/src/test/java/com/datatorrent/stram/client/DTConfigurationTest.java ---------------------------------------------------------------------- diff --git a/engine/src/test/java/com/datatorrent/stram/client/DTConfigurationTest.java b/engine/src/test/java/com/datatorrent/stram/client/DTConfigurationTest.java new file mode 100644 index 0000000..c43c1f9 --- /dev/null +++ b/engine/src/test/java/com/datatorrent/stram/client/DTConfigurationTest.java @@ -0,0 +1,35 @@ +/** + * 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 com.datatorrent.stram.client; + +import org.junit.Assert; +import org.junit.Test; + +public class DTConfigurationTest +{ + @Test + public void testSetInternal() + { + DTConfiguration config = new DTConfiguration(); + config.setInternal("test-key", "test-value"); + Assert.assertEquals("test-value", config.get("test-key")); + config.setInternal("test-key", "test-value-2"); + Assert.assertEquals("test-value-2", config.get("test-key")); + } +}
