ApexPDP: Adding support to omit the (context) albums entry in an apex
[policy/apex-pdp.git] / model / basic-model / src / main / java / org / onap / policy / apex / model / basicmodel / concepts / AxArtifactKey.java
index e08c3c6..86c89c3 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ *  Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,7 +23,6 @@ package org.onap.policy.apex.model.basicmodel.concepts;
 
 import java.util.ArrayList;
 import java.util.List;
-
 import javax.persistence.Column;
 import javax.persistence.Embeddable;
 import javax.xml.bind.annotation.XmlAccessType;
@@ -30,23 +30,23 @@ import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
-
 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
-import org.onap.policy.apex.model.utilities.Assertions;
+import org.onap.policy.common.utils.validation.Assertions;
 
 /**
  * An artifact key uniquely identifies every first order entity in the system. Every first order concept in the system
  * must have an {@link AxArtifactKey} to identify it. Concepts that are wholly contained in another concept are
  * identified using a {@link AxReferenceKey} key.
- * <p>
- * Key validation checks that the name and version fields match the {@link NAME_REGEXP} and {@link VERSION_REGEXP}
+ *
+ * <p>Key validation checks that the name and version fields match the NAME_REGEXP and VERSION_REGEXP
  * regular expressions respectively.
  */
 @Embeddable
 @XmlAccessorType(XmlAccessType.FIELD)
 @XmlRootElement(name = "apexArtifactKey", namespace = "http://www.onap.org/policy/apex-pdp")
 
-@XmlType(name = "AxArtifactKey", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = { "name", "version" })
+@XmlType(name = "AxArtifactKey", namespace = "http://www.onap.org/policy/apex-pdp", propOrder =
+    { "name", "version" })
 
 public class AxArtifactKey extends AxKey {
     private static final long serialVersionUID = 8932717618579392561L;
@@ -70,10 +70,9 @@ public class AxArtifactKey extends AxKey {
     }
 
     /**
-     * Copy constructor
+     * Copy constructor.
      *
-     * @param copyConcept
-     *        the concept to copy from
+     * @param copyConcept the concept to copy from
      */
     public AxArtifactKey(final AxArtifactKey copyConcept) {
         super(copyConcept);
@@ -82,10 +81,8 @@ public class AxArtifactKey extends AxKey {
     /**
      * Constructor to create a key with the specified name and version.
      *
-     * @param name
-     *        the key name
-     * @param version
-     *        the key version
+     * @param name the key name
+     * @param version the key version
      */
     public AxArtifactKey(final String name, final String version) {
         super();
@@ -96,8 +93,7 @@ public class AxArtifactKey extends AxKey {
     /**
      * Constructor to create a key using the key and version from the specified key ID.
      *
-     * @param id
-     *        the key ID in a format that respects the {@link KEY_ID_REGEXP}
+     * @param id the key ID in a format that respects the KEY_ID_REGEXP
      */
     public AxArtifactKey(final String id) {
         Assertions.argumentNotNull(id, "id may not be null");
@@ -124,20 +120,16 @@ public class AxArtifactKey extends AxKey {
         return new AxArtifactKey(AxKey.NULL_KEY_NAME, AxKey.NULL_KEY_VERSION);
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
+    /**
+     * {@inheritDoc}.
      */
     @Override
     public AxArtifactKey getKey() {
         return this;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
+    /**
+     * {@inheritDoc}.
      */
     @Override
     public List<AxKey> getKeys() {
@@ -146,13 +138,11 @@ public class AxArtifactKey extends AxKey {
         return keyList;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.onap.policy.apex.model.basicmodel.concepts.AxKey#getID()
+    /**
+     * {@inheritDoc}.
      */
     @Override
-    public String getID() {
+    public String getId() {
         return name + ':' + version;
     }
 
@@ -168,8 +158,7 @@ public class AxArtifactKey extends AxKey {
     /**
      * Sets the key name.
      *
-     * @param name
-     *        the key name
+     * @param name the key name
      */
     public void setName(final String name) {
         this.name = Assertions.validateStringParameter(NAME_TOKEN, name, NAME_REGEXP);
@@ -187,18 +176,24 @@ public class AxArtifactKey extends AxKey {
     /**
      * Sets the key version.
      *
-     * @param version
-     *        the key version
+     * @param version the key version
      */
     public void setVersion(final String version) {
         this.version = Assertions.validateStringParameter(VERSION_TOKEN, version, VERSION_REGEXP);
     }
 
-    /*
-     * (non-Javadoc)
+    /**
+     * Check if the key is IDENTICAL to a null key.
      *
-     * @see org.onap.policy.apex.model.basicmodel.concepts.AxKey#getCompatibility(org.onap.policy.apex.model.basicmodel.
-     * concepts.AxKey)
+     * @return true, if the key is IDENTICAL to a null key
+     */
+    public boolean isNullKey() {
+        return this.getCompatibility(AxArtifactKey.getNullKey()).equals(AxKey.Compatibility.IDENTICAL);
+    }
+
+
+    /**
+     * {@inheritDoc}.
      */
     @Override
     public AxKey.Compatibility getCompatibility(final AxKey otherKey) {
@@ -230,12 +225,8 @@ public class AxArtifactKey extends AxKey {
         return Compatibility.PATCH;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.onap.policy.apex.model.basicmodel.concepts.AxKey#isCompatible(org.onap.policy.apex.model.basicmodel.concepts.
-     * AxKey)
+    /**
+     * {@inheritDoc}.
      */
     @Override
     public boolean isCompatible(final AxKey otherKey) {
@@ -249,12 +240,8 @@ public class AxArtifactKey extends AxKey {
         return !(compatibility == Compatibility.DIFFERENT || compatibility == Compatibility.MAJOR);
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.basicmodel.concepts.
-     * AxValidationResult)
+    /**
+     * {@inheritDoc}.
      */
     @Override
     public AxValidationResult validate(final AxValidationResult result) {
@@ -265,8 +252,8 @@ public class AxArtifactKey extends AxKey {
                             "name invalid-" + nameValidationErrorMessage));
         }
 
-        final String versionValidationErrorMessage = Assertions.getStringParameterValidationMessage(VERSION_TOKEN, version,
-                        VERSION_REGEXP);
+        final String versionValidationErrorMessage = Assertions.getStringParameterValidationMessage(VERSION_TOKEN,
+                        version, VERSION_REGEXP);
         if (versionValidationErrorMessage != null) {
             result.addValidationMessage(new AxValidationMessage(this, this.getClass(), ValidationResult.INVALID,
                             "version invalid-" + versionValidationErrorMessage));
@@ -275,10 +262,8 @@ public class AxArtifactKey extends AxKey {
         return result;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
+    /**
+     * {@inheritDoc}.
      */
     @Override
     public void clean() {
@@ -286,10 +271,8 @@ public class AxArtifactKey extends AxKey {
         version = Assertions.validateStringParameter(VERSION_TOKEN, version, VERSION_REGEXP);
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
+    /**
+     * {@inheritDoc}.
      */
     @Override
     public String toString() {
@@ -304,12 +287,8 @@ public class AxArtifactKey extends AxKey {
         return builder.toString();
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.basicmodel.concepts.
-     * AxConcept)
+    /**
+     * {@inheritDoc}.
      */
     @Override
     public AxConcept copyTo(final AxConcept target) {
@@ -325,10 +304,8 @@ public class AxArtifactKey extends AxKey {
         return copyObject;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
+    /**
+     * {@inheritDoc}.
      */
     @Override
     public int hashCode() {
@@ -339,10 +316,8 @@ public class AxArtifactKey extends AxKey {
         return result;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang. Object)
+    /**
+     * {@inheritDoc}.
      */
     @Override
     public boolean equals(final Object obj) {
@@ -364,10 +339,8 @@ public class AxArtifactKey extends AxKey {
         return version.equals(other.version);
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see java.lang.Comparable#compareTo(java.lang.Object)
+    /**
+     * {@inheritDoc}.
      */
     @Override
     public int compareTo(final AxConcept otherObj) {
@@ -387,4 +360,4 @@ public class AxArtifactKey extends AxKey {
         }
         return version.compareTo(other.version);
     }
-}
+}
\ No newline at end of file