diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java')
-rw-r--r-- | openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java | 97 |
1 files changed, 46 insertions, 51 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java index 5fe48ff7ca..4e9f460f04 100644 --- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java +++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java @@ -19,6 +19,8 @@ */ package org.openecomp.sdc.versioning.impl; +import java.util.HashSet; +import java.util.Set; import org.openecomp.core.utilities.CommonMethods; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; @@ -27,62 +29,55 @@ import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.dao.types.VersionStatus; import org.openecomp.sdc.versioning.types.VersionCreationMethod; -import java.util.HashSet; -import java.util.Set; - public class VersionCalculatorImpl implements VersionCalculator { - private static final Logger LOGGER = LoggerFactory.getLogger(VersionCalculatorImpl.class); - - private static final String INITIAL_VERSION = "1.0"; - private static final String VERSION_STRING_VIOLATION_MSG = - "Version string must be in the format of: {integer}.{integer}"; - private static final String INVALID_CREATION_METHOD_MSG = "Invalid creation method"; - @Override - public String calculate(String baseVersion, VersionCreationMethod creationMethod) { + private static final Logger LOGGER = LoggerFactory.getLogger(VersionCalculatorImpl.class); + private static final String INITIAL_VERSION = "1.0"; + private static final String VERSION_STRING_VIOLATION_MSG = "Version string must be in the format of: {integer}.{integer}"; + private static final String INVALID_CREATION_METHOD_MSG = "Invalid creation method"; - if (baseVersion == null) { - return INITIAL_VERSION; - } - - String[] versionLevels = baseVersion.split("\\."); - if (versionLevels.length != 2) { - throw new IllegalArgumentException(VERSION_STRING_VIOLATION_MSG); - } - - int index; - switch (creationMethod) { - case major: - index = Integer.parseInt(versionLevels[0]); - index++; - versionLevels[0] = Integer.toString(index); - versionLevels[1] = "0"; - break; - case minor: - index = Integer.parseInt(versionLevels[1]); - index++; - versionLevels[1] = Integer.toString(index); - break; + @Override + public String calculate(String baseVersion, VersionCreationMethod creationMethod) { + if (baseVersion == null) { + return INITIAL_VERSION; + } + String[] versionLevels = baseVersion.split("\\."); + if (versionLevels.length != 2) { + throw new IllegalArgumentException(VERSION_STRING_VIOLATION_MSG); + } + int index; + switch (creationMethod) { + case major: + index = Integer.parseInt(versionLevels[0]); + index++; + versionLevels[0] = Integer.toString(index); + versionLevels[1] = "0"; + break; + case minor: + index = Integer.parseInt(versionLevels[1]); + index++; + versionLevels[1] = Integer.toString(index); + break; + } + return CommonMethods.arrayToSeparatedString(versionLevels, '.'); } - return CommonMethods.arrayToSeparatedString(versionLevels, '.'); - } - @Override - public void injectAdditionalInfo(Version version, Set<String> existingVersions) { - String optionalVersion; - Set<VersionCreationMethod> optionalCreationMethods = new HashSet<>(); - if(version.getStatus().equals(VersionStatus.Certified)) { - for (VersionCreationMethod versionCreationMethod : VersionCreationMethod.values()) { - try { - optionalVersion = calculate(version.getName(), versionCreationMethod); - if (!existingVersions.contains(optionalVersion)) { - optionalCreationMethods.add(versionCreationMethod); - } - } catch (IllegalArgumentException iae) { - LOGGER.error("{}:{}", INVALID_CREATION_METHOD_MSG, versionCreationMethod.name(), iae); + @Override + public void injectAdditionalInfo(Version version, Set<String> existingVersions) { + String optionalVersion; + Set<VersionCreationMethod> optionalCreationMethods = new HashSet<>(); + if (version.getStatus().equals(VersionStatus.Certified)) { + for (VersionCreationMethod versionCreationMethod : VersionCreationMethod.values()) { + try { + optionalVersion = calculate(version.getName(), versionCreationMethod); + if (!existingVersions.contains(optionalVersion)) { + optionalCreationMethods.add(versionCreationMethod); + } + } catch (IllegalArgumentException iae) { + LOGGER.error("{}:{}", INVALID_CREATION_METHOD_MSG, versionCreationMethod.name(), iae); + } + } } - } + version.getAdditionalInfo().put("OptionalCreationMethods", optionalCreationMethods); } - version.getAdditionalInfo().put("OptionalCreationMethods", optionalCreationMethods); - } } |