2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.asdc.installer;
24 import java.math.BigDecimal;
26 public class BigDecimalVersion {
29 * This method truncates and convert the version String provided in the notification.
31 * @param version The version to check
32 * @return A BigDecimal value checked and truncated
34 public static BigDecimal castAndCheckNotificationVersion(String version) {
35 // Truncate the version if bad type
36 String[] splitVersion = version.split("\\.");
37 StringBuilder newVersion = new StringBuilder();
38 if (splitVersion.length > 1) {
39 newVersion.append(splitVersion[0]);
40 newVersion.append(".");
41 newVersion.append(splitVersion[1]);
43 return new BigDecimal(splitVersion[0]);
46 for (int i=2;i<splitVersion.length;i++) {
47 newVersion.append(splitVersion[i]);
50 return new BigDecimal(newVersion.toString());
54 * This method truncates and convert the version String provided in the notification.
56 * @param version The version to check
57 * @return A String value checked and truncated to Decimal format
59 public static String castAndCheckNotificationVersionToString (String version) {
60 return castAndCheckNotificationVersion(version).toString();