Remove boxed types in MavenLikeVersioning 07/5307/2
authorGary Wu <gary.i.wu@huawei.com>
Mon, 10 Apr 2017 20:28:02 +0000 (13:28 -0700)
committerGary Wu <gary.i.wu@huawei.com>
Thu, 13 Apr 2017 15:57:44 +0000 (15:57 +0000)
Remove the unnecessary use of boxed types
in MavenLikeVersioning.

Change-Id: I8b96db9e753f80860b95b84473bb8d2b61e2328e
Signed-off-by: Gary Wu <gary.i.wu@huawei.com>
mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/utils/MavenLikeVersioning.java

index 73a9f8e..df1a1cb 100644 (file)
@@ -50,40 +50,30 @@ public class MavenLikeVersioning implements Serializable {
         * @return True if the current object is more recent than the specified version, False otherwise
         *
         */
-       public Boolean isMoreRecentThan (String versionToCompare) {
+       public boolean isMoreRecentThan (String versionToCompare) {
                if (versionToCompare == null || this.version == null) {
-                       return Boolean.FALSE;
+                       return false;
                }
                String [] currentVersionArray = this.version.split("\\.");
                String [] specifiedVersionArray = versionToCompare.split("\\.");
 
-               int smalestStringLength = 0;
-
-               if (currentVersionArray.length > specifiedVersionArray.length) {
-                       smalestStringLength = specifiedVersionArray.length;
-               } else {
-                       smalestStringLength = currentVersionArray.length;
-               }
+        int smalestStringLength = Math.min(currentVersionArray.length, specifiedVersionArray.length);
 
                for (int currentVersionIndex=0;currentVersionIndex < smalestStringLength;++currentVersionIndex) {
 
-                       if (Integer.valueOf(currentVersionArray[currentVersionIndex]) < Integer.valueOf(specifiedVersionArray[currentVersionIndex])) {
-                               return Boolean.FALSE;
-                       } else if (Integer.valueOf(currentVersionArray[currentVersionIndex]) > Integer.valueOf(specifiedVersionArray[currentVersionIndex])) {
-                               return Boolean.TRUE;
+                       if (Integer.parseInt(currentVersionArray[currentVersionIndex]) < Integer.parseInt(specifiedVersionArray[currentVersionIndex])) {
+                               return false;
+                       } else if (Integer.parseInt(currentVersionArray[currentVersionIndex]) > Integer.parseInt(specifiedVersionArray[currentVersionIndex])) {
+                               return true;
                        }
                }
 
                // Even if versionToCompare has more digits, it means versionToCompare is more recent
-               if (Integer.valueOf(currentVersionArray[smalestStringLength-1]).intValue () == Integer.valueOf(specifiedVersionArray[smalestStringLength-1]).intValue ()) {
-                       if (currentVersionArray.length > specifiedVersionArray.length) {
-                               return Boolean.TRUE;
-                       } else {
-                               return Boolean.FALSE;
-                       }
+               if (Integer.parseInt(currentVersionArray[smalestStringLength-1]) == Integer.parseInt(specifiedVersionArray[smalestStringLength-1])) {
+                   return currentVersionArray.length > specifiedVersionArray.length;
                }
 
-               return Boolean.TRUE;
+               return true;
        }
 
        /**
@@ -94,26 +84,26 @@ public class MavenLikeVersioning implements Serializable {
         * @return True if the current object is equal to the specified version, False otherwise
         *
         */
-       public Boolean isTheSameVersion (String versionToCompare) {
+       public boolean isTheSameVersion (String versionToCompare) {
                if (versionToCompare == null && this.version == null) {
-                       return Boolean.TRUE;
+                       return true;
                } else if (versionToCompare == null || this.version == null) {
-                       return Boolean.FALSE;
+                       return false;
                }
                String [] currentVersionArray = this.version.split("\\.");
                String [] specifiedVersionArray = versionToCompare.split("\\.");
 
                if (currentVersionArray.length != specifiedVersionArray.length) {
-                       return Boolean.FALSE;
+                       return false;
                }
 
                for (int currentVersionIndex=0;currentVersionIndex < currentVersionArray.length;++currentVersionIndex) {
 
-                       if (Integer.valueOf(currentVersionArray[currentVersionIndex]).intValue () != Integer.valueOf(specifiedVersionArray[currentVersionIndex]).intValue ()) {
-                               return Boolean.FALSE;
+                       if (Integer.parseInt(currentVersionArray[currentVersionIndex]) != Integer.parseInt(specifiedVersionArray[currentVersionIndex])) {
+                               return false;
                        }
                }
 
-               return Boolean.TRUE;
+               return true;
        }
 }