Change the header to SO
[so.git] / asdc-controller / src / main / java / org / openecomp / mso / asdc / installer / BigDecimalVersion.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.mso.asdc.installer;
22
23
24 import java.math.BigDecimal;
25
26 public class BigDecimalVersion {
27           
28         /**
29      * This method truncates and convert the version String provided in the notification.
30      * 
31      * @param version The version to check
32      * @return A BigDecimal value checked and truncated
33      */
34     public static BigDecimal castAndCheckNotificationVersion(String version) {
35         // Truncate the version if bad type
36         String[] splitVersion = version.split("\\.");
37         StringBuffer newVersion = new StringBuffer();
38         if (splitVersion.length > 1) {
39                 newVersion.append(splitVersion[0]);
40                 newVersion.append(".");
41                 newVersion.append(splitVersion[1]);
42         } else {
43                 return new BigDecimal(splitVersion[0]);
44         }
45         
46         for (int i=2;i<splitVersion.length;i++) {
47                 newVersion.append(splitVersion[i]);
48         }
49         
50         return new BigDecimal(newVersion.toString());
51     }
52     
53     /**
54      * This method truncates and convert the version String provided in the notification.
55      * 
56      * @param version The version to check
57      * @return A String value checked and truncated to Decimal format
58      */
59     public static String castAndCheckNotificationVersionToString (String version) {
60         return castAndCheckNotificationVersion(version).toString();
61     }
62 }