2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 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====================================================
22 package org.onap.aaf.auth.rserv;
26 * Analyze and hold Version information for Code
31 public class Version {
32 private Object[] parts;
34 public Version(String v) {
35 String sparts[] = v.split("\\.");
36 parts = new Object[sparts.length];
37 System.arraycopy(sparts, 0, parts, 0, sparts.length);
38 if (parts.length>1) { // has at least a minor
40 parts[1]=Integer.decode(sparts[1]); // minor elements need to be converted to Integer for comparison
41 } catch (NumberFormatException e) {
42 // it's ok, leave it as a string
43 parts[1]=sparts[1]; // This useless piece of code forced by Sonar which calls empty Exceptions "Blockers".
48 public boolean equals(Object obj) {
49 if (obj instanceof Version) {
50 Version ver = (Version)obj;
51 int length = Math.min(parts.length, ver.parts.length);
52 for (int i=0;i<length;++i) { // match on declared parts
54 if (parts[1] instanceof Integer && ver.parts[1] instanceof Integer) {
55 // Match on Minor version if this Version is less than Version to be checked
56 if (((Integer)parts[1])<((Integer)ver.parts[1])) {
59 continue; // don't match next line
62 if (!parts[i].equals(ver.parts[i])) {
63 return false; // other spots exact match
73 * @see java.lang.Object#hashCode()
76 public int hashCode() {
77 return super.hashCode();
80 public String toString() {
81 StringBuilder sb = new StringBuilder();
83 for (Object obj : parts) {
89 sb.append(obj.toString());