2 * ============LICENSE_START========================================================================
3 * ONAP : tr-069-adapter
4 * =================================================================================================
5 * Copyright (C) 2020 CommScope Inc Intellectual Property.
6 * =================================================================================================
7 * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
9 * may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14 * either express or implied. See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ===============LICENSE_END=======================================================================
19 package org.commscope.tr069adapter.common.deviceversion;
21 import java.io.Serializable;
22 import java.util.Comparator;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class DeviceVersion implements Serializable, Comparable<DeviceVersion> {
32 private static final Logger LOG = LoggerFactory.getLogger(DeviceVersion.class);
33 private static final long serialVersionUID = -7251276716604249440L;
34 private int svMajorVersion = 0;
35 private int svMinorVersion = 0;
36 private int svPatchVersion = 0;
37 private String swVersion;
38 private boolean isGenericVersion = false;
39 private boolean isHwRegex = false;
40 private boolean isSwRegex = false;
42 public DeviceVersion(String swVersion, String hwVersion) {
44 setSwVersion(swVersion);
45 this.hwVersion = hwVersion;
48 public DeviceVersion(String swVersion, String hwVersion, boolean isSwRegex, boolean isHwRegex) {
50 this.hwVersion = hwVersion;
51 this.swVersion = swVersion;
52 this.isHwRegex = isHwRegex;
53 this.isSwRegex = isSwRegex;
55 setSwVersion(swVersion);
59 public String getSwVersion() {
61 return svMajorVersion + "." + svMinorVersion + "." + svPatchVersion;
63 return this.swVersion;
66 public boolean isHwRegex() {
70 public boolean isSwRegex() {
74 private void setSwVersion(String swVersion) {
75 if (swVersion.indexOf(".") > 0) {
76 String[] verArray = swVersion.split("\\.");
78 for (int i = 0; i < verArray.length; i++) {
80 if (verArray[i].equals("*")) {
85 svMajorVersion = Integer.parseInt(verArray[0]);
86 svMinorVersion = Integer.parseInt(verArray[1]);
87 svPatchVersion = Integer.parseInt(verArray[2]);
88 } catch (Exception e) {
89 LOG.error("Software Version setting has failed. {}", e.toString());
92 } else if (swVersion.indexOf("x") > 0) {
94 } else if (swVersion.equals("*")) {
95 isGenericVersion = true;
100 public String getHwVersion() {
104 private String hwVersion;
106 public int getSvMajorVersion() {
107 return svMajorVersion;
110 public int getSvMinorVersion() {
111 return svMinorVersion;
114 public int getSvPatchVersion() {
115 return svPatchVersion;
118 private long deviceTypeId;
120 public long getDeviceTypeId() {
124 public boolean isGenericVersion() {
125 return isGenericVersion;
128 public static final Comparator<DeviceVersion> softwareComparator =
129 new Comparator<DeviceVersion>() {
131 public int compare(DeviceVersion d1, DeviceVersion d2) {
132 if (d1.getSvMajorVersion() != d2.getSvMajorVersion()) {
133 return (d1.getSvMajorVersion() - d2.getSvMajorVersion());
134 } else if (d1.getSvMinorVersion() != d2.getSvMinorVersion()) {
135 return d1.getSvMinorVersion() - d2.getSvMinorVersion();
137 return d1.getSvPatchVersion() - d2.getSvPatchVersion();
143 public int compareTo(DeviceVersion o) {
144 if (deviceTypeId != o.deviceTypeId)
148 return this.hashCode() - o.hashCode();
150 if (svMajorVersion != o.svMajorVersion) {
151 return (svMajorVersion - o.svMajorVersion);
152 } else if (svMinorVersion != o.svMinorVersion) {
153 return svMinorVersion - o.svMinorVersion;
154 } else if (svPatchVersion != o.svPatchVersion) {
155 return svPatchVersion - o.svPatchVersion;
157 return hwVersion.compareToIgnoreCase(o.hwVersion);
163 public boolean equals(Object obj) {
168 if (getClass() != obj.getClass())
170 DeviceVersion other = (DeviceVersion) obj;
171 if (deviceTypeId != other.deviceTypeId)
173 if (hwVersion == null && other.hwVersion != null) {
176 if (isGenericVersion != other.isGenericVersion)
178 if (isHwRegex != other.isHwRegex)
180 if (isSwRegex != other.isSwRegex)
182 if (svMajorVersion != other.svMajorVersion)
184 if (svMinorVersion != other.svMinorVersion)
186 if (svPatchVersion != other.svPatchVersion)
188 if (swVersion == null) {
189 if (other.swVersion != null)
196 public int hashCode() {
197 final int prime = 31;
199 result = prime * result + (int) (deviceTypeId ^ (deviceTypeId >>> 32));
200 result = prime * result + ((hwVersion == null) ? 0 : hwVersion.hashCode());
201 result = prime * result + (isGenericVersion ? 1231 : 1237);
202 result = prime * result + (isHwRegex ? 1231 : 1237);
203 result = prime * result + (isSwRegex ? 1241 : 1247);
204 result = prime * result + svMajorVersion;
205 result = prime * result + svMinorVersion;
206 result = prime * result + svPatchVersion;