c77c68fd532826bf867ef33f18867a1eca7f51fd
[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  *  Modifications Copyright (C) 2019 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.Serializable;
25 import java.util.List;
26
27 import lombok.NonNull;
28
29 /**
30  * This class is the base class for all Policy Framework concept classes. It enforces implementation of abstract methods
31  * and interfaces on all concepts that are sub-classes of this class.
32  */
33
34 public abstract class PfConcept implements Serializable, Comparable<PfConcept> {
35     private static final long serialVersionUID = -7434939557282697490L;
36
37     /**
38      * Default constructor.
39      */
40     public PfConcept() {
41         // Default Constructor
42     }
43
44     /**
45      * Copy constructor.
46      *
47      * @param copyConcept the concept to copy from
48      */
49     public PfConcept(@NonNull final PfConcept copyConcept) {
50         // nothing else to do (other than @NonNull check)
51     }
52
53     /**
54      * Gets the key of this concept.
55      *
56      * @return the concept key
57      */
58     public abstract PfKey getKey();
59
60     /**
61      * Gets a list of all keys for this concept and all concepts that are defined or referenced by this concept and its
62      * sub-concepts.
63      *
64      * @return the keys used by this concept and its contained concepts
65      */
66     public abstract List<PfKey> getKeys();
67
68     /**
69      * Validate that this concept is structurally correct.
70      *
71      * @param result the parameter in which the result of the validation will be returned
72      * @return the validation result that was passed in in the @{link result} field with the result of this validation
73      *         added
74      */
75     public abstract PfValidationResult validate(@NonNull final PfValidationResult result);
76
77     /**
78      * Clean this concept, tidy up any superfluous information such as leading and trailing white space.
79      */
80     public abstract void clean();
81
82     @Override
83     public abstract boolean equals(Object otherObject);
84
85     @Override
86     public abstract String toString();
87
88     @Override
89     public abstract int hashCode();
90
91     /**
92      * Gets the ID string of this concept.
93      *
94      * @return the ID string of this concept
95      */
96     public String getId() {
97         return getKey().getId();
98     }
99
100     /**
101      * Gets the name of this concept.
102      *
103      * @return the name of this concept
104      */
105     public String getName() {
106         return getKey().getName();
107     }
108
109     /**
110      * Gets the version of this concept.
111      *
112      * @return the version of this concept
113      */
114     public String getVersion() {
115         return getKey().getVersion();
116     }
117
118     /**
119      * Checks if this key matches the given key ID.
120      *
121      * @param id the key ID to match against
122      * @return true, if this key matches the ID
123      */
124     public final boolean matchesId(@NonNull final String id) {
125         // Check the ID
126         return getId().equals(id);
127     }
128 }