Add DAO module for Models
[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 org.onap.policy.common.utils.validation.Assertions;
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(final PfConcept copyConcept) {
47         Assertions.argumentNotNull(copyConcept, "copy concept may not be null");
48         copyConcept.copyTo(this);
49     }
50
51     /**
52      * Gets the key of this concept.
53      *
54      * @return the concept key
55      */
56     public abstract PfKey getKey();
57
58     /**
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.
61      *
62      * @return the keys used by this concept and its contained concepts
63      */
64     public abstract List<PfKey> getKeys();
65
66     /**
67      * Validate that this concept is structurally correct.
68      *
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
72      */
73     public abstract PfValidationResult validate(PfValidationResult result);
74
75     /**
76      * Clean this concept, tidy up any superfluous information such as leading and trailing white
77      * space.
78      */
79     public abstract void clean();
80
81     /*
82      * (non-Javadoc)
83      *
84      * @see java.lang.Object#equals(java.lang.Object)
85      */
86     @Override
87     public abstract boolean equals(Object otherObject);
88
89     /*
90      * (non-Javadoc)
91      *
92      * @see java.lang.Object#toString()
93      */
94     @Override
95     public abstract String toString();
96
97     /*
98      * (non-Javadoc)
99      *
100      * @see java.lang.Object#hashCode()
101      */
102     @Override
103     public abstract int hashCode();
104
105     /**
106      * Copy this concept to another object. The target object must have the same class as the source
107      * object.
108      *
109      * @param target the target object to which this object is copied
110      * @return the copied object
111      */
112     public abstract PfConcept copyTo(PfConcept target);
113
114     /**
115      * Gets the ID string of this concept.
116      *
117      * @return the ID string of this concept
118      */
119     public String getId() {
120         return getKey().getId();
121     }
122
123     /**
124      * Checks if this key matches the given key ID.
125      *
126      * @param id the key ID to match against
127      * @return true, if this key matches the ID
128      */
129     public final boolean matchesId(final String id) {
130         Assertions.argumentNotNull(id, "id may not be null");
131
132         // Check the ID
133         return getId().equals(id);
134     }
135 }