Java 17 Upgrade
[policy/models.git] / models-base / src / main / java / org / onap / policy / models / base / PfKeyImpl.java
index 461fd24..105e6f7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Copyright (C) 2019-2020, 2023 Nordix Foundation.
+ *  Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.models.base;
 
+import java.io.Serial;
 import java.util.ArrayList;
 import java.util.List;
 import lombok.Getter;
 import lombok.NonNull;
 import lombok.ToString;
 import org.onap.policy.common.utils.validation.Assertions;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
 
 /**
  * A key, upon which other key subclasses can be built, providing implementations of the methods.
@@ -35,6 +35,7 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult;
 @Getter
 @ToString
 public abstract class PfKeyImpl extends PfKey {
+    @Serial
     private static final long serialVersionUID = 8932717618579392561L;
 
     public static final String NAME_TOKEN = "name";
@@ -43,7 +44,7 @@ public abstract class PfKeyImpl extends PfKey {
     /**
      * The default constructor creates a null concept key.
      */
-    public PfKeyImpl() {
+    protected PfKeyImpl() {
         this(NULL_KEY_NAME, NULL_KEY_VERSION);
     }
 
@@ -52,7 +53,7 @@ public abstract class PfKeyImpl extends PfKey {
      *
      * @param copyConcept the concept to copy from
      */
-    public PfKeyImpl(final PfKeyImpl copyConcept) {
+    protected PfKeyImpl(final PfKeyImpl copyConcept) {
         super(copyConcept);
         setName(copyConcept.getName());
         setVersion(copyConcept.getVersion());
@@ -64,7 +65,7 @@ public abstract class PfKeyImpl extends PfKey {
      * @param name the key name
      * @param version the key version
      */
-    public PfKeyImpl(@NonNull final String name, @NonNull final String version) {
+    protected PfKeyImpl(@NonNull final String name, @NonNull final String version) {
         super();
         setName(name);
         setVersion(version);
@@ -75,7 +76,7 @@ public abstract class PfKeyImpl extends PfKey {
      *
      * @param id the key ID in a format that respects the KEY_ID_REGEXP
      */
-    public PfKeyImpl(@NonNull final String id) {
+    protected PfKeyImpl(@NonNull final String id) {
         // Check the incoming ID is valid
         Assertions.validateStringParameter("id", id, getKeyIdRegEx());
 
@@ -115,6 +116,15 @@ public abstract class PfKeyImpl extends PfKey {
         return (PfKey.NULL_KEY_NAME.equals(getName()) && PfKey.NULL_KEY_VERSION.equals(getVersion()));
     }
 
+    /**
+     * Determines if the name is "null".
+     *
+     * @return {@code true} if the name is null, {@code false} otherwise
+     */
+    public boolean isNullName() {
+        return PfKey.NULL_KEY_NAME.equals(getName());
+    }
+
     /**
      * Determines if the version is "null".
      *
@@ -126,10 +136,9 @@ public abstract class PfKeyImpl extends PfKey {
 
     @Override
     public PfKey.Compatibility getCompatibility(@NonNull final PfKey otherKey) {
-        if (!(otherKey instanceof PfKeyImpl)) {
+        if (!(otherKey instanceof PfKeyImpl otherConceptKey)) {
             return Compatibility.DIFFERENT;
         }
-        final PfKeyImpl otherConceptKey = (PfKeyImpl) otherKey;
 
         if (this.equals(otherConceptKey)) {
             return Compatibility.IDENTICAL;
@@ -147,7 +156,7 @@ public abstract class PfKeyImpl extends PfKey {
         }
 
         if (thisVersionArray.length >= 2 && otherVersionArray.length >= 2
-                        && !thisVersionArray[1].equals(otherVersionArray[1])) {
+            && !thisVersionArray[1].equals(otherVersionArray[1])) {
             return Compatibility.MINOR;
         }
 
@@ -156,12 +165,11 @@ public abstract class PfKeyImpl extends PfKey {
 
     @Override
     public boolean isCompatible(@NonNull final PfKey otherKey) {
-        if (!(otherKey instanceof PfKeyImpl)) {
+        if (!(otherKey instanceof PfKeyImpl otherConceptKey)) {
             return false;
         }
-        final PfKeyImpl otherConceptKey = (PfKeyImpl) otherKey;
 
-        final Compatibility compatibility = this.getCompatibility(otherConceptKey);
+        final var compatibility = this.getCompatibility(otherConceptKey);
 
         return !(compatibility == Compatibility.DIFFERENT || compatibility == Compatibility.MAJOR);
     }
@@ -185,17 +193,17 @@ public abstract class PfKeyImpl extends PfKey {
 
         // There must always be at least one element in each version
         if (!thisVersionArray[0].equals(otherVersionArray[0])) {
-            return Integer.valueOf(thisVersionArray[0]) > Integer.valueOf(otherVersionArray[0]);
+            return Integer.parseInt(thisVersionArray[0]) > Integer.parseInt(otherVersionArray[0]);
         }
 
         if (thisVersionArray.length >= 2 && otherVersionArray.length >= 2
-                        && !thisVersionArray[1].equals(otherVersionArray[1])) {
-            return Integer.valueOf(thisVersionArray[1]) > Integer.valueOf(otherVersionArray[1]);
+            && !thisVersionArray[1].equals(otherVersionArray[1])) {
+            return Integer.parseInt(thisVersionArray[1]) > Integer.parseInt(otherVersionArray[1]);
         }
 
         if (thisVersionArray.length >= 3 && otherVersionArray.length >= 3
-                        && !thisVersionArray[2].equals(otherVersionArray[2])) {
-            return Integer.valueOf(thisVersionArray[2]) > Integer.valueOf(otherVersionArray[2]);
+            && !thisVersionArray[2].equals(otherVersionArray[2])) {
+            return Integer.parseInt(thisVersionArray[2]) > Integer.parseInt(otherVersionArray[2]);
         }
 
         return false;
@@ -215,8 +223,7 @@ public abstract class PfKeyImpl extends PfKey {
 
         if (versionArray.length >= 2) {
             return Integer.parseInt(versionArray[1]);
-        }
-        else {
+        } else {
             return 0;
         }
     }
@@ -227,31 +234,11 @@ public abstract class PfKeyImpl extends PfKey {
 
         if (versionArray.length >= 3) {
             return Integer.parseInt(versionArray[2]);
-        }
-        else {
+        } else {
             return 0;
         }
     }
 
-    @Override
-    public PfValidationResult validate(final PfValidationResult result) {
-        final String nameValidationErrorMessage = Assertions.getStringParameterValidationMessage(NAME_TOKEN, getName(),
-                        getNameRegEx());
-        if (nameValidationErrorMessage != null) {
-            result.addValidationMessage(new PfValidationMessage(this, this.getClass(), ValidationResult.INVALID,
-                            "name invalid-" + nameValidationErrorMessage));
-        }
-
-        final String versionValidationErrorMessage = Assertions.getStringParameterValidationMessage(VERSION_TOKEN,
-                        getVersion(), getVersionRegEx());
-        if (versionValidationErrorMessage != null) {
-            result.addValidationMessage(new PfValidationMessage(this, this.getClass(), ValidationResult.INVALID,
-                            "version invalid-" + versionValidationErrorMessage));
-        }
-
-        return result;
-    }
-
     @Override
     public void clean() {
         setName(getName());