dda4cdc03a5de04b8696edc5c586f2e55b891e27
[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 common parent for
25  * 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 x.y.z do not match).
53          */
54         MAJOR,
55         /**
56          * The name of the key matches but the Minor version number of the keys is different (y in x.y.z do not match).
57          */
58         MINOR,
59         /**
60          * The name of the key matches but the Patch version number of the keys is different (z in x.y.z do not match).
61          */
62         PATCH,
63         /** The keys match completely. */
64         IDENTICAL
65     }
66
67     /**
68      * Default constructor.
69      */
70     public PfKey() {
71         super();
72     }
73
74     /**
75      * Copy constructor.
76      *
77      * @param copyConcept the concept to copy from
78      */
79     public PfKey(final PfKey copyConcept) {
80         super(copyConcept);
81     }
82
83     @Override
84     public abstract String getId();
85
86     /**
87      * Return the result of a compatibility check of two keys.
88      *
89      * @param otherKey the key to check compatibility against
90      * @return the compatibility result of the check
91      */
92     public abstract Compatibility getCompatibility(PfKey otherKey);
93
94     /**
95      * Check if two keys are compatible, that is the keys are IDENTICAL or have only MINOR, PATCH differences.
96      *
97      * @param otherKey the key to check compatibility against
98      * @return true, if the keys are compatible
99      */
100     public abstract boolean isCompatible(PfKey otherKey);
101 }