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