summaryrefslogtreecommitdiffstats
path: root/common-app-api/src/main/java
diff options
context:
space:
mode:
authorPiotr Darosz <piotr.darosz@nokia.com>2019-07-23 08:00:04 +0200
committerPiotr Darosz <piotr.darosz@nokia.com>2019-07-23 08:00:43 +0200
commita73cbca41fbba96855173f39c89c04d50d4d8672 (patch)
tree47792a786c86d9ced825744769927ba38f79ebd3 /common-app-api/src/main/java
parent4d8364e7ac25838c0aeabcd89af2e447c30d9426 (diff)
File name calculation refactoring
FSConfigurationSource file name calculation refactoring and tests Change-Id: Idf1c45f860e12c14cfe88417500f2169b5dc86f7 Issue-ID: SDC-2474 Signed-off-by: Piotr Darosz <piotr.darosz@nokia.com>
Diffstat (limited to 'common-app-api/src/main/java')
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/common/impl/FSConfigurationSource.java43
1 files changed, 14 insertions, 29 deletions
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/common/impl/FSConfigurationSource.java b/common-app-api/src/main/java/org/openecomp/sdc/common/impl/FSConfigurationSource.java
index 3f2f6a7a01..3aa220c5bc 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/common/impl/FSConfigurationSource.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/common/impl/FSConfigurationSource.java
@@ -16,10 +16,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.common.impl;
+import java.util.Arrays;
+import java.util.stream.Collectors;
import org.openecomp.sdc.common.api.ConfigurationListener;
import org.openecomp.sdc.common.api.ConfigurationSource;
import org.openecomp.sdc.common.api.Constants;
@@ -32,10 +36,10 @@ import org.openecomp.sdc.common.util.YamlToObjectConverter;
*/
public class FSConfigurationSource implements ConfigurationSource {
- private YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
+ private final YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
- private ConfigFileChangeListener changeListener = null;
- private String appConfigDir = null;
+ private final ConfigFileChangeListener changeListener;
+ private final String appConfigDir;
public FSConfigurationSource(ConfigFileChangeListener changeListener, String appConfigDir) {
super();
@@ -81,34 +85,15 @@ public class FSConfigurationSource implements ConfigurationSource {
* @param className
* @return file name based on the class name
*/
- private static <T> String calculateFileName(Class<T> className) {
-
+ static <T> String calculateFileName(Class<T> className) {
String[] words = className.getSimpleName().split("(?=\\p{Upper})");
- StringBuilder builder = new StringBuilder();
-
- // There cannot be a null value returned from "split" - words != null is
- // redundant
- // if (words != null) {
- boolean isFirst = true;
- for (int i = 0; i < words.length; i++) {
-
- String word = words[i];
- if (word != null && !word.isEmpty()) {
- if (!isFirst) {
- builder.append("-");
- } else {
- isFirst = false;
- }
- builder.append(words[i].toLowerCase());
- }
- }
- return builder.toString() + Constants.YAML_SUFFIX;
-
- /*
- * } else { return className.getSimpleName().toLowerCase() + Constants.YAML_SUFFIX; }
- */
-
+ return Arrays.stream(words)
+ .map(String::toLowerCase)
+ .collect(Collectors.collectingAndThen(
+ Collectors.joining("-"),
+ str -> str + Constants.YAML_SUFFIX)
+ );
}
}