Development of NETCONF RPCs for tr-069 adapter to
[oam/tr069-adapter.git] / common / src / main / java / org / commscope / tr069adapter / common / deviceversion / DeviceVersion.java
index df4d068..b7b057b 100644 (file)
-/*\r
- * ============LICENSE_START========================================================================\r
- * ONAP : tr-069-adapter\r
- * =================================================================================================\r
- * Copyright (C) 2020 CommScope Inc Intellectual Property.\r
- * =================================================================================================\r
- * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,\r
- * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You\r
- * may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,\r
- * either express or implied. See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ===============LICENSE_END=======================================================================\r
- */\r
-\r
-package org.commscope.tr069adapter.common.deviceversion;\r
-\r
-import java.io.Serializable;\r
-import java.util.Comparator;\r
-\r
-public class DeviceVersion implements Serializable, Comparable<DeviceVersion> {\r
-\r
-  /**\r
-   * \r
-   */\r
-  private static final long serialVersionUID = -7251276716604249440L;\r
-  private int svMajorVersion = 0;\r
-  private int svMinorVersion = 0;\r
-  private int svPatchVersion = 0;\r
-  private String swVersion;\r
-  private boolean isGenericVersion = false;\r
-  private boolean isHwRegex = false;\r
-  private boolean isSwRegex = false;\r
-\r
-  public DeviceVersion(String swVersion, String hwVersion) {\r
-    super();\r
-    setSwVersion(swVersion);\r
-    this.hwVersion = hwVersion;\r
-  }\r
-\r
-  public DeviceVersion(String swVersion, String hwVersion, boolean isSwRegex,\r
-      boolean isHwRegex) {\r
-    super();\r
-    this.hwVersion = hwVersion;\r
-    this.swVersion = swVersion;\r
-    this.isHwRegex = isHwRegex;\r
-    this.isSwRegex = isSwRegex;\r
-    if (!isSwRegex) {\r
-      setSwVersion(swVersion);\r
-    }\r
-  }\r
-\r
-  public String getSwVersion() {\r
-    if (!isSwRegex)\r
-      return svMajorVersion + "." + svMinorVersion + "." + svPatchVersion;\r
-    else\r
-      return this.swVersion;\r
-  }\r
-\r
-  public boolean isHwRegex() {\r
-    return isHwRegex;\r
-  }\r
-\r
-  public boolean isSwRegex() {\r
-    return isSwRegex;\r
-  }\r
-\r
-  private void setSwVersion(String swVersion) {\r
-    if (swVersion.indexOf(".") > 0) {\r
-      String[] verArray = swVersion.split("\\.");\r
-\r
-      for (int i = 0; i < verArray.length; i++) {\r
-\r
-        if (verArray[i].equals("*")) {\r
-          verArray[i] = "0";\r
-        }\r
-      }\r
-      try {\r
-        svMajorVersion = Integer.parseInt(verArray[0]);\r
-        svMinorVersion = Integer.parseInt(verArray[1]);\r
-        svPatchVersion = Integer.parseInt(verArray[2]);\r
-      } catch (Exception e) {\r
-        // TODO: handle exception\r
-      }\r
-\r
-    } else if (swVersion.indexOf("x") > 0) {\r
-      swVersion = "*";\r
-    } else if (swVersion.equals("*")) {\r
-      isGenericVersion = true;\r
-    }\r
-\r
-  }\r
-\r
-  public String getHwVersion() {\r
-    return hwVersion;\r
-  }\r
-\r
-  private String hwVersion;\r
-\r
-  public int getSvMajorVersion() {\r
-    return svMajorVersion;\r
-  }\r
-\r
-  public int getSvMinorVersion() {\r
-    return svMinorVersion;\r
-  }\r
-\r
-  public int getSvPatchVersion() {\r
-    return svPatchVersion;\r
-  }\r
-\r
-  private long deviceTypeId;\r
-\r
-  public long getDeviceTypeId() {\r
-    return deviceTypeId;\r
-  }\r
-\r
-  public boolean isGenericVersion() {\r
-    return isGenericVersion;\r
-  }\r
-\r
-  public static Comparator<DeviceVersion> softwareComparator = new Comparator<DeviceVersion>() {\r
-    @Override\r
-    public int compare(DeviceVersion d1, DeviceVersion d2) {\r
-      if (d1.getSvMajorVersion() != d2.getSvMajorVersion()) {\r
-        return (d1.getSvMajorVersion() - d2.getSvMajorVersion());\r
-      } else if (d1.getSvMinorVersion() != d2.getSvMinorVersion()) {\r
-        return d1.getSvMinorVersion() - d2.getSvMinorVersion();\r
-      } else\r
-        return d1.getSvPatchVersion() - d2.getSvPatchVersion();\r
-    }\r
-  };\r
-\r
-  @Override\r
-  public int compareTo(DeviceVersion o) {\r
-    if (deviceTypeId != o.deviceTypeId)\r
-      return -1;\r
-\r
-    if (isSwRegex) {\r
-      return this.hashCode() - o.hashCode();\r
-    } else {\r
-      if (svMajorVersion != o.svMajorVersion) {\r
-        return (svMajorVersion - o.svMajorVersion);\r
-      } else if (svMinorVersion != o.svMinorVersion) {\r
-        return svMinorVersion - o.svMinorVersion;\r
-      } else if (svPatchVersion != o.svPatchVersion) {\r
-        return svPatchVersion - o.svPatchVersion;\r
-      } else {\r
-        return hwVersion.compareToIgnoreCase(o.hwVersion);\r
-      }\r
-    }\r
-  }\r
-\r
-  @Override\r
-  public int hashCode() {\r
-    final int prime = 31;\r
-    int result = 1;\r
-    result = prime * result + (int) (deviceTypeId ^ (deviceTypeId >>> 32));\r
-    result = prime * result + ((hwVersion == null) ? 0 : hwVersion.hashCode());\r
-    result = prime * result + (isGenericVersion ? 1231 : 1237);\r
-    result = prime * result + (isHwRegex ? 1231 : 1237);\r
-    result = prime * result + (isSwRegex ? 1241 : 1247);\r
-    result = prime * result + svMajorVersion;\r
-    result = prime * result + svMinorVersion;\r
-    result = prime * result + svPatchVersion;\r
-    return result;\r
-  }\r
-}\r
+/*
+ * ============LICENSE_START========================================================================
+ * ONAP : tr-069-adapter
+ * =================================================================================================
+ * Copyright (C) 2020 CommScope Inc Intellectual Property.
+ * =================================================================================================
+ * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
+ * may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ===============LICENSE_END=======================================================================
+ */
+
+package org.commscope.tr069adapter.common.deviceversion;
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DeviceVersion implements Serializable, Comparable<DeviceVersion> {
+
+  /**
+   * 
+   */
+  private static final Logger LOG = LoggerFactory.getLogger(DeviceVersion.class);
+  private static final long serialVersionUID = -7251276716604249440L;
+  private int svMajorVersion = 0;
+  private int svMinorVersion = 0;
+  private int svPatchVersion = 0;
+  private String swVersion;
+  private boolean isGenericVersion = false;
+  private boolean isHwRegex = false;
+  private boolean isSwRegex = false;
+
+  public DeviceVersion(String swVersion, String hwVersion) {
+    super();
+    setSwVersion(swVersion);
+    this.hwVersion = hwVersion;
+  }
+
+  public DeviceVersion(String swVersion, String hwVersion, boolean isSwRegex, boolean isHwRegex) {
+    super();
+    this.hwVersion = hwVersion;
+    this.swVersion = swVersion;
+    this.isHwRegex = isHwRegex;
+    this.isSwRegex = isSwRegex;
+    if (!isSwRegex) {
+      setSwVersion(swVersion);
+    }
+  }
+
+  public String getSwVersion() {
+    if (!isSwRegex)
+      return svMajorVersion + "." + svMinorVersion + "." + svPatchVersion;
+    else
+      return this.swVersion;
+  }
+
+  public boolean isHwRegex() {
+    return isHwRegex;
+  }
+
+  public boolean isSwRegex() {
+    return isSwRegex;
+  }
+
+  private void setSwVersion(String swVersion) {
+    if (swVersion.indexOf(".") > 0) {
+      String[] verArray = swVersion.split("\\.");
+
+      for (int i = 0; i < verArray.length; i++) {
+
+        if (verArray[i].equals("*")) {
+          verArray[i] = "0";
+        }
+      }
+      try {
+        svMajorVersion = Integer.parseInt(verArray[0]);
+        svMinorVersion = Integer.parseInt(verArray[1]);
+        svPatchVersion = Integer.parseInt(verArray[2]);
+      } catch (Exception e) {
+        LOG.error("Software Version setting has failed. {}", e.toString());
+      }
+
+    } else if (swVersion.indexOf("x") > 0) {
+      swVersion = "*";
+    } else if (swVersion.equals("*")) {
+      isGenericVersion = true;
+    }
+
+  }
+
+  public String getHwVersion() {
+    return hwVersion;
+  }
+
+  private String hwVersion;
+
+  public int getSvMajorVersion() {
+    return svMajorVersion;
+  }
+
+  public int getSvMinorVersion() {
+    return svMinorVersion;
+  }
+
+  public int getSvPatchVersion() {
+    return svPatchVersion;
+  }
+
+  private long deviceTypeId;
+
+  public long getDeviceTypeId() {
+    return deviceTypeId;
+  }
+
+  public boolean isGenericVersion() {
+    return isGenericVersion;
+  }
+
+  public static final Comparator<DeviceVersion> softwareComparator =
+      new Comparator<DeviceVersion>() {
+        @Override
+        public int compare(DeviceVersion d1, DeviceVersion d2) {
+          if (d1.getSvMajorVersion() != d2.getSvMajorVersion()) {
+            return (d1.getSvMajorVersion() - d2.getSvMajorVersion());
+          } else if (d1.getSvMinorVersion() != d2.getSvMinorVersion()) {
+            return d1.getSvMinorVersion() - d2.getSvMinorVersion();
+          } else {
+            return d1.getSvPatchVersion() - d2.getSvPatchVersion();
+          }
+        }
+      };
+
+  @Override
+  public int compareTo(DeviceVersion o) {
+    if (deviceTypeId != o.deviceTypeId)
+      return -1;
+
+    if (isSwRegex) {
+      return this.hashCode() - o.hashCode();
+    } else {
+      if (svMajorVersion != o.svMajorVersion) {
+        return (svMajorVersion - o.svMajorVersion);
+      } else if (svMinorVersion != o.svMinorVersion) {
+        return svMinorVersion - o.svMinorVersion;
+      } else if (svPatchVersion != o.svPatchVersion) {
+        return svPatchVersion - o.svPatchVersion;
+      } else {
+        return hwVersion.compareToIgnoreCase(o.hwVersion);
+      }
+    }
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    DeviceVersion other = (DeviceVersion) obj;
+    if (deviceTypeId != other.deviceTypeId)
+      return false;
+    if (hwVersion == null && other.hwVersion != null) {
+      return false;
+    }
+    if (isGenericVersion != other.isGenericVersion)
+      return false;
+    if (isHwRegex != other.isHwRegex)
+      return false;
+    if (isSwRegex != other.isSwRegex)
+      return false;
+    if (svMajorVersion != other.svMajorVersion)
+      return false;
+    if (svMinorVersion != other.svMinorVersion)
+      return false;
+    if (svPatchVersion != other.svPatchVersion)
+      return false;
+    if (swVersion == null) {
+      if (other.swVersion != null)
+        return false;
+    }
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + (int) (deviceTypeId ^ (deviceTypeId >>> 32));
+    result = prime * result + ((hwVersion == null) ? 0 : hwVersion.hashCode());
+    result = prime * result + (isGenericVersion ? 1231 : 1237);
+    result = prime * result + (isHwRegex ? 1231 : 1237);
+    result = prime * result + (isSwRegex ? 1241 : 1247);
+    result = prime * result + svMajorVersion;
+    result = prime * result + svMinorVersion;
+    result = prime * result + svPatchVersion;
+    return result;
+  }
+}