1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package com.att.cssa.rserv;
\r
27 * Analyze and hold Version information for Code
\r
31 public class Version {
\r
32 private Object[] parts;
\r
34 public Version(String v) {
\r
35 String sparts[] = v.split("\\.");
\r
36 parts = new Object[sparts.length];
\r
37 System.arraycopy(sparts, 0, parts, 0, sparts.length);
\r
38 if(parts.length>1) { // has at least a minor
\r
40 parts[1]=Integer.decode(sparts[1]); // minor elements need to be converted to Integer for comparison
\r
41 } catch (NumberFormatException e) {
\r
42 // it's ok, leave it as a string
\r
43 parts[1]=sparts[1]; // This useless piece of code forced by Sonar which calls empty Exceptions "Blockers".
\r
48 public boolean equals(Object obj) {
\r
49 if(obj instanceof Version) {
\r
50 Version ver = (Version)obj;
\r
51 int length = Math.min(parts.length, ver.parts.length);
\r
52 for(int i=0;i<length;++i) { // match on declared parts
\r
54 if(parts[1] instanceof Integer && ver.parts[1] instanceof Integer) {
\r
55 // Match on Minor version if this Version is less than Version to be checked
\r
56 if(((Integer)parts[1])<((Integer)ver.parts[1])) {
\r
59 continue; // don't match next line
\r
62 if(!parts[i].equals(ver.parts[i])) {
\r
63 return false; // other spots exact match
\r
73 * @see java.lang.Object#hashCode()
\r
76 public int hashCode() {
\r
77 return super.hashCode();
\r
80 public String toString() {
\r
81 StringBuilder sb = new StringBuilder();
\r
82 boolean first = true;
\r
83 for(Object obj : parts) {
\r
89 sb.append(obj.toString());
\r
91 return sb.toString();
\r