2 * ============LICENSE_START========================================================================
\r
3 * ONAP : tr-069-adapter
\r
4 * =================================================================================================
\r
5 * Copyright (C) 2020 CommScope Inc Intellectual Property.
\r
6 * =================================================================================================
\r
7 * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
\r
8 * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
\r
9 * may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
\r
14 * either express or implied. See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
16 * ===============LICENSE_END=======================================================================
\r
19 package org.commscope.tr069adapter.common.deviceversion;
\r
21 import java.io.Serializable;
\r
22 import java.util.Comparator;
\r
24 public class DeviceVersion implements Serializable, Comparable<DeviceVersion> {
\r
29 private static final long serialVersionUID = -7251276716604249440L;
\r
30 private int svMajorVersion = 0;
\r
31 private int svMinorVersion = 0;
\r
32 private int svPatchVersion = 0;
\r
33 private String swVersion;
\r
34 private boolean isGenericVersion = false;
\r
35 private boolean isHwRegex = false;
\r
36 private boolean isSwRegex = false;
\r
38 public DeviceVersion(String swVersion, String hwVersion) {
\r
40 setSwVersion(swVersion);
\r
41 this.hwVersion = hwVersion;
\r
44 public DeviceVersion(String swVersion, String hwVersion, boolean isSwRegex,
\r
45 boolean isHwRegex) {
\r
47 this.hwVersion = hwVersion;
\r
48 this.swVersion = swVersion;
\r
49 this.isHwRegex = isHwRegex;
\r
50 this.isSwRegex = isSwRegex;
\r
52 setSwVersion(swVersion);
\r
56 public String getSwVersion() {
\r
58 return svMajorVersion + "." + svMinorVersion + "." + svPatchVersion;
\r
60 return this.swVersion;
\r
63 public boolean isHwRegex() {
\r
67 public boolean isSwRegex() {
\r
71 private void setSwVersion(String swVersion) {
\r
72 if (swVersion.indexOf(".") > 0) {
\r
73 String[] verArray = swVersion.split("\\.");
\r
75 for (int i = 0; i < verArray.length; i++) {
\r
77 if (verArray[i].equals("*")) {
\r
82 svMajorVersion = Integer.parseInt(verArray[0]);
\r
83 svMinorVersion = Integer.parseInt(verArray[1]);
\r
84 svPatchVersion = Integer.parseInt(verArray[2]);
\r
85 } catch (Exception e) {
\r
86 // TODO: handle exception
\r
89 } else if (swVersion.indexOf("x") > 0) {
\r
91 } else if (swVersion.equals("*")) {
\r
92 isGenericVersion = true;
\r
97 public String getHwVersion() {
\r
101 private String hwVersion;
\r
103 public int getSvMajorVersion() {
\r
104 return svMajorVersion;
\r
107 public int getSvMinorVersion() {
\r
108 return svMinorVersion;
\r
111 public int getSvPatchVersion() {
\r
112 return svPatchVersion;
\r
115 private long deviceTypeId;
\r
117 public long getDeviceTypeId() {
\r
118 return deviceTypeId;
\r
121 public boolean isGenericVersion() {
\r
122 return isGenericVersion;
\r
125 public static Comparator<DeviceVersion> softwareComparator = new Comparator<DeviceVersion>() {
\r
127 public int compare(DeviceVersion d1, DeviceVersion d2) {
\r
128 if (d1.getSvMajorVersion() != d2.getSvMajorVersion()) {
\r
129 return (d1.getSvMajorVersion() - d2.getSvMajorVersion());
\r
130 } else if (d1.getSvMinorVersion() != d2.getSvMinorVersion()) {
\r
131 return d1.getSvMinorVersion() - d2.getSvMinorVersion();
\r
133 return d1.getSvPatchVersion() - d2.getSvPatchVersion();
\r
138 public int compareTo(DeviceVersion o) {
\r
139 if (deviceTypeId != o.deviceTypeId)
\r
143 return this.hashCode() - o.hashCode();
\r
145 if (svMajorVersion != o.svMajorVersion) {
\r
146 return (svMajorVersion - o.svMajorVersion);
\r
147 } else if (svMinorVersion != o.svMinorVersion) {
\r
148 return svMinorVersion - o.svMinorVersion;
\r
149 } else if (svPatchVersion != o.svPatchVersion) {
\r
150 return svPatchVersion - o.svPatchVersion;
\r
152 return hwVersion.compareToIgnoreCase(o.hwVersion);
\r
158 public int hashCode() {
\r
159 final int prime = 31;
\r
161 result = prime * result + (int) (deviceTypeId ^ (deviceTypeId >>> 32));
\r
162 result = prime * result + ((hwVersion == null) ? 0 : hwVersion.hashCode());
\r
163 result = prime * result + (isGenericVersion ? 1231 : 1237);
\r
164 result = prime * result + (isHwRegex ? 1231 : 1237);
\r
165 result = prime * result + (isSwRegex ? 1241 : 1247);
\r
166 result = prime * result + svMajorVersion;
\r
167 result = prime * result + svMinorVersion;
\r
168 result = prime * result + svPatchVersion;
\r