3f2affb42504a8e4d516ee3bf4a089776f7b44c7
[policy/apex-pdp.git] / model / basic-model / src / main / java / org / onap / policy / apex / model / basicmodel / concepts / AxConcept.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019 Nordix Foundation.
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.apex.model.basicmodel.concepts;
23
24 import java.io.Serializable;
25 import java.util.List;
26
27 import javax.xml.bind.annotation.XmlType;
28
29 import org.onap.policy.common.utils.validation.Assertions;
30
31 /**
32  * This class is the base class for all Apex concept classes. It enforces implementation of abstract methods and
33  * interfaces on all concepts that are sub-classes of this class.
34  *
35  * @author Liam Fallon (liam.fallon@ericsson.com)
36  */
37
38 @XmlType(name = "AxConcept", namespace = "http://www.onap.org/policy/apex-pdp")
39
40 public abstract class AxConcept implements Serializable, Comparable<AxConcept> {
41     private static final long serialVersionUID = -7434939557282697490L;
42
43     /**
44      * Default constructor.
45      */
46     public AxConcept() {
47         // Default constructor
48     }
49
50     /**
51      * Copy constructor.
52      *
53      * @param copyConcept the concept to copy from
54      */
55     public AxConcept(final AxConcept copyConcept) {
56         Assertions.argumentNotNull(copyConcept, "copy concept may not be null");
57         copyConcept.copyTo(this);
58     }
59
60     /**
61      * Gets the key of this concept.
62      *
63      * @return the concept key
64      */
65     public abstract AxKey getKey();
66
67     /**
68      * Gets a list of all keys for this concept and all concepts that are defined or referenced by this concept and its
69      * sub-concepts.
70      *
71      * @return the keys used by this concept and it's contained concepts
72      */
73     public abstract List<AxKey> getKeys();
74
75     /**
76      * Validate that this concept is structurally correct.
77      *
78      * @param result the parameter in which the result of the validation will be returned
79      * @return the validation result that was passed in in the @{link result} field with the result of this validation
80      *         added
81      */
82     public abstract AxValidationResult validate(AxValidationResult result);
83
84     /**
85      * Clean this concept, tidy up any superfluous information such as leading and trailing white space.
86      */
87     public abstract void clean();
88
89     /**
90      * {@inheritDoc}.
91      */
92     @Override
93     public abstract boolean equals(Object otherObject);
94
95     /**
96      * {@inheritDoc}.
97      */
98     @Override
99     public abstract String toString();
100
101     /**
102      * {@inheritDoc}.
103      */
104     @Override
105     public abstract int hashCode();
106
107     /**
108      * Copy this concept to another object. The target object must have the same class as the source object.
109      *
110      * @param target the target object to which this object is copied
111      * @return the copied object
112      */
113     public abstract AxConcept copyTo(AxConcept target);
114
115     /**
116      * Gets the ID string of this concept.
117      *
118      * @return the ID string of this concept
119      */
120     public String getId() {
121         return getKey().getId();
122     }
123
124     /**
125      * Checks if this key matches the given key ID.
126      *
127      * @param id the key ID to match against
128      * @return true, if this key matches the ID
129      */
130     public final boolean matchesId(final String id) {
131         Assertions.argumentNotNull(id, "id may not be null");
132
133         // Check the ID
134         return getId().equals(id);
135     }
136 }