/*
* ============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.
@Getter
@ToString
public abstract class PfKeyImpl extends PfKey {
+ @Serial
private static final long serialVersionUID = 8932717618579392561L;
public static final String NAME_TOKEN = "name";
/**
* The default constructor creates a null concept key.
*/
- public PfKeyImpl() {
+ protected PfKeyImpl() {
this(NULL_KEY_NAME, NULL_KEY_VERSION);
}
*
* @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());
* @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);
*
* @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());
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".
*
@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;
}
if (thisVersionArray.length >= 2 && otherVersionArray.length >= 2
- && !thisVersionArray[1].equals(otherVersionArray[1])) {
+ && !thisVersionArray[1].equals(otherVersionArray[1])) {
return Compatibility.MINOR;
}
@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);
}
// 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;
if (versionArray.length >= 2) {
return Integer.parseInt(versionArray[1]);
- }
- else {
+ } else {
return 0;
}
}
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());