Set default and check existance of Policy Type
[policy/models.git] / models-base / src / main / java / org / onap / policy / models / base / PfConcept.java
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.models.base;
22
23 import java.io.Serializable;
24 import java.util.List;
25
26 import lombok.NonNull;
27
28 /**
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.
31  */
32
33 public abstract class PfConcept implements Serializable, Comparable<PfConcept> {
34     private static final long serialVersionUID = -7434939557282697490L;
35
36     /**
37      * Default constructor.
38      */
39     public PfConcept() {}
40
41     /**
42      * Copy constructor.
43      *
44      * @param copyConcept the concept to copy from
45      */
46     public PfConcept(@NonNull final PfConcept copyConcept) {
47         copyConcept.copyTo(this);
48     }
49
50     /**
51      * Gets the key of this concept.
52      *
53      * @return the concept key
54      */
55     public abstract PfKey getKey();
56
57     /**
58      * Gets a list of all keys for this concept and all concepts that are defined or referenced by
59      * this concept and its sub-concepts.
60      *
61      * @return the keys used by this concept and its contained concepts
62      */
63     public abstract List<PfKey> getKeys();
64
65     /**
66      * Validate that this concept is structurally correct.
67      *
68      * @param result the parameter in which the result of the validation will be returned
69      * @return the validation result that was passed in in the @{link result} field with the result
70      *         of this validation added
71      */
72     public abstract PfValidationResult validate(@NonNull final PfValidationResult result);
73
74     /**
75      * Clean this concept, tidy up any superfluous information such as leading and trailing white
76      * space.
77      */
78     public abstract void clean();
79
80     @Override
81     public abstract boolean equals(Object otherObject);
82
83     @Override
84     public abstract String toString();
85
86     @Override
87     public abstract int hashCode();
88
89     /**
90      * Copy this concept to another object. The target object must have the same class as the source
91      * object.
92      *
93      * @param target the target object to which this object is copied
94      * @return the copied object
95      */
96     public abstract PfConcept copyTo(@NonNull PfConcept target);
97
98     /**
99      * Gets the ID string of this concept.
100      *
101      * @return the ID string of this concept
102      */
103     public String getId() {
104         return getKey().getId();
105     }
106
107     /**
108      * Gets the name of this concept.
109      *
110      * @return the name of this concept
111      */
112     public String getName() {
113         return getKey().getName();
114     }
115
116     /**
117      * Gets the version of this concept.
118      *
119      * @return the version of this concept
120      */
121     public String getVersion() {
122         return getKey().getVersion();
123     }
124
125     /**
126      * Checks if this key matches the given key ID.
127      *
128      * @param id the key ID to match against
129      * @return true, if this key matches the ID
130      */
131     public final boolean matchesId(@NonNull final String id) {
132         // Check the ID
133         return getId().equals(id);
134     }
135 }