2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.base;
23 import java.io.Serializable;
24 import java.util.List;
26 import org.onap.policy.common.utils.validation.Assertions;
29 * This class is the base class for all Policy Framework concept classes. It enforces implementation
30 * of abstract methods and interfaces on all concepts that are sub-classes of this class.
33 public abstract class PfConcept implements Serializable, Comparable<PfConcept> {
34 private static final long serialVersionUID = -7434939557282697490L;
37 * Default constructor.
44 * @param copyConcept the concept to copy from
46 public PfConcept(final PfConcept copyConcept) {
47 Assertions.argumentNotNull(copyConcept, "copy concept may not be null");
48 copyConcept.copyTo(this);
52 * Gets the key of this concept.
54 * @return the concept key
56 public abstract PfKey getKey();
59 * Gets a list of all keys for this concept and all concepts that are defined or referenced by
60 * this concept and its sub-concepts.
62 * @return the keys used by this concept and its contained concepts
64 public abstract List<PfKey> getKeys();
67 * Validate that this concept is structurally correct.
69 * @param result the parameter in which the result of the validation will be returned
70 * @return the validation result that was passed in in the @{link result} field with the result
71 * of this validation added
73 public abstract PfValidationResult validate(PfValidationResult result);
76 * Clean this concept, tidy up any superfluous information such as leading and trailing white
79 public abstract void clean();
84 * @see java.lang.Object#equals(java.lang.Object)
87 public abstract boolean equals(Object otherObject);
92 * @see java.lang.Object#toString()
95 public abstract String toString();
100 * @see java.lang.Object#hashCode()
103 public abstract int hashCode();
106 * Copy this concept to another object. The target object must have the same class as the source
109 * @param target the target object to which this object is copied
110 * @return the copied object
112 public abstract PfConcept copyTo(PfConcept target);
115 * Gets the ID string of this concept.
117 * @return the ID string of this concept
119 public String getId() {
120 return getKey().getId();
124 * Checks if this key matches the given key ID.
126 * @param id the key ID to match against
127 * @return true, if this key matches the ID
129 public final boolean matchesId(final String id) {
130 Assertions.argumentNotNull(id, "id may not be null");
133 return getId().equals(id);