Java 17 Upgrade
[policy/models.git] / models-base / src / main / java / org / onap / policy / models / base / PfConcept.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019, 2023 Nordix Foundation.
4  *  Modifications Copyright (C) 2019-2021 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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.models.base;
23
24 import java.io.Serial;
25 import java.io.Serializable;
26 import java.util.List;
27 import lombok.AccessLevel;
28 import lombok.NoArgsConstructor;
29 import lombok.NonNull;
30
31 /**
32  * This class is the base class for all Policy Framework concept classes. It enforces implementation of abstract methods
33  * and interfaces on all concepts that are subclasses of this class.
34  */
35
36 @NoArgsConstructor(access = AccessLevel.PROTECTED)
37 public abstract class PfConcept extends Validated implements Serializable, Comparable<PfConcept> {
38     @Serial
39     private static final long serialVersionUID = -7434939557282697490L;
40
41     /**
42      * Copy constructor.
43      *
44      * @param copyConcept the concept to copy from
45      */
46     protected PfConcept(@NonNull final PfConcept copyConcept) {
47         // nothing else to do (other than @NonNull check)
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 this concept and its
59      * 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      * Clean this concept, tidy up any superfluous information such as leading and trailing white space.
67      */
68     public abstract void clean();
69
70     @Override
71     public abstract boolean equals(Object otherObject);
72
73     @Override
74     public abstract String toString();
75
76     @Override
77     public abstract int hashCode();
78
79     /**
80      * Gets the ID string of this concept.
81      *
82      * @return the ID string of this concept
83      */
84     public String getId() {
85         return getKey().getId();
86     }
87
88     /**
89      * Gets the name of this concept.
90      *
91      * @return the name of this concept
92      */
93     public String getName() {
94         return getKey().getName();
95     }
96
97     /**
98      * Gets the version of this concept.
99      *
100      * @return the version of this concept
101      */
102     public String getVersion() {
103         return getKey().getVersion();
104     }
105
106     /**
107      * Checks if this key matches the given key ID.
108      *
109      * @param id the key ID to match against
110      * @return true, if this key matches the ID
111      */
112     public final boolean matchesId(@NonNull final String id) {
113         // Check the ID
114         return getId().equals(id);
115     }
116 }