2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.base;
24 import java.util.List;
25 import lombok.EqualsAndHashCode;
27 import lombok.NonNull;
28 import lombok.ToString;
29 import org.onap.policy.common.parameters.annotations.NotNull;
30 import org.onap.policy.common.utils.validation.Assertions;
31 import org.onap.policy.models.base.validation.annotations.VerifyKey;
34 * This class records a usage of a key in the system. When the list of keys being used by a concept
35 * is built using the getKeys() method of the {@link PfConcept} class, an instance of this class is
36 * created for every key occurrence. The list of keys returned by the getKeys() method is a list of
37 * {@link PfKeyUse} objects.
39 * <p>Validation checks that each key is valid.
41 @EqualsAndHashCode(callSuper = false)
43 public class PfKeyUse extends PfKey {
44 private static final long serialVersionUID = 2007147220109881705L;
49 private PfKey usedKey;
52 * The Default Constructor creates this concept with a null key.
55 this(new PfConceptKey());
59 * This constructor creates an instance of this class, and holds a reference to a used key.
61 * @param usedKey a used key
63 public PfKeyUse(@NonNull final PfKey usedKey) {
64 this.usedKey = usedKey;
70 * @param copyConcept the concept to copy from
72 public PfKeyUse(@NonNull final PfKeyUse copyConcept) {
74 this.usedKey = PfUtils.makeCopy(copyConcept.usedKey);
78 public PfKey getKey() {
83 public List<PfKey> getKeys() {
84 return usedKey.getKeys();
88 public String getId() {
89 return usedKey.getId();
93 public boolean isNullKey() {
94 return usedKey.isNullKey();
102 public void setKey(@NonNull final PfKey key) {
107 public PfKey.Compatibility getCompatibility(@NonNull final PfKey otherKey) {
108 return usedKey.getCompatibility(otherKey);
112 public boolean isCompatible(@NonNull final PfKey otherKey) {
113 return usedKey.isCompatible(otherKey);
117 public boolean isNewerThan(@NonNull final PfKey otherKey) {
118 return usedKey.isCompatible(otherKey);
122 public int getMajorVersion() {
123 return usedKey.getMajorVersion();
127 public int getMinorVersion() {
128 return usedKey.getMinorVersion();
132 public int getPatchVersion() {
133 return usedKey.getPatchVersion();
137 public void clean() {
142 public int compareTo(final PfConcept otherObj) {
143 Assertions.argumentNotNull(otherObj, "comparison object may not be null");
145 if (this == otherObj) {
148 if (getClass() != otherObj.getClass()) {
149 return getClass().getName().compareTo(otherObj.getClass().getName());
152 final PfKeyUse other = (PfKeyUse) otherObj;
154 return usedKey.compareTo(other.usedKey);