Add basic model object concepts
[policy/models.git] / models-base / src / main / java / org / onap / policy / models / base / PfKey.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 /**
24  * The key uniquely identifies every entity in the system. This class is an abstract class to give a
25  * common parent for all key types in the system.
26  */
27 public abstract class PfKey extends PfConcept {
28     private static final long serialVersionUID = 6281159885962014041L;
29
30     /** Regular expression to specify the structure of key names. */
31     public static final String NAME_REGEXP = "[A-Za-z0-9\\-_\\.]+";
32
33     /** Regular expression to specify the structure of key versions. */
34     public static final String VERSION_REGEXP = "[A-Za-z0-9.]+";
35
36     /** Regular expression to specify the structure of key IDs. */
37     public static final String KEY_ID_REGEXP = "[A-Za-z0-9\\-_\\.]+:[0-9].[0-9].[0-9]";
38
39     /** Specifies the value for names in NULL keys. */
40     public static final String NULL_KEY_NAME = "NULL";
41
42     /** Specifies the value for versions in NULL keys. */
43     public static final String NULL_KEY_VERSION = "0.0.0";
44
45     /**
46      * This enumeration is returned on key compatibility checks.
47      */
48     public enum Compatibility {
49         /** The keys have different names. */
50         DIFFERENT,
51         /**
52          * The name of the key matches but the Major version number of the keys is different (x in
53          * x.y.z do not match).
54          */
55         MAJOR,
56         /**
57          * The name of the key matches but the Minor version number of the keys is different (y in
58          * x.y.z do not match).
59          */
60         MINOR,
61         /**
62          * The name of the key matches but the Patch version number of the keys is different (z in
63          * x.y.z do not match).
64          */
65         PATCH,
66         /** The keys match completely. */
67         IDENTICAL
68     }
69
70     /**
71      * Default constructor.
72      */
73     public PfKey() {
74         super();
75     }
76
77     /**
78      * Copy constructor.
79      *
80      * @param copyConcept the concept to copy from
81      */
82     public PfKey(final PfKey copyConcept) {
83         super(copyConcept);
84     }
85
86     @Override
87     public abstract String getId();
88
89     /**
90      * Return the result of a compatibility check of two keys.
91      *
92      * @param otherKey the key to check compatibility against
93      * @return the compatibility result of the check
94      */
95     public abstract Compatibility getCompatibility(PfKey otherKey);
96
97     /**
98      * Check if two keys are compatible, that is the keys are IDENTICAL or have only MINOR, PATCH
99      * differences.
100      *
101      * @param otherKey the key to check compatibility against
102      * @return true, if the keys are compatible
103      */
104     public abstract boolean isCompatible(PfKey otherKey);
105 }