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