Merge "migrate model-impl from drools-applications"
[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 import lombok.NonNull;
24
25 /**
26  * The key uniquely identifies every entity in the system. This class is an abstract class to give a common parent for
27  * all key types in the system.
28  */
29 public abstract class PfKey extends PfConcept {
30     private static final long serialVersionUID = 6281159885962014041L;
31
32     /** Regular expression to specify the structure of key names. */
33     public static final String NAME_REGEXP = "[A-Za-z0-9\\-_\\.]+";
34
35     /** Regular expression to specify the structure of key versions. */
36     public static final String VERSION_REGEXP = "[A-Za-z0-9.]+";
37
38     /** Regular expression to specify the structure of key IDs. */
39     public static final String KEY_ID_REGEXP = "[A-Za-z0-9\\-_\\.]+:[0-9].[0-9].[0-9]";
40
41     /** Specifies the value for names in NULL keys. */
42     public static final String NULL_KEY_NAME = "NULL";
43
44     /** Specifies the value for versions in NULL keys. */
45     public static final String NULL_KEY_VERSION = "0.0.0";
46
47     /**
48      * This enumeration is returned on key compatibility checks.
49      */
50     public enum Compatibility {
51         /** The keys have different names. */
52         DIFFERENT,
53         /**
54          * The name of the key matches but the Major version number of the keys is different (x in x.y.z do not match).
55          */
56         MAJOR,
57         /**
58          * The name of the key matches but the Minor version number of the keys is different (y in 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 x.y.z do not match).
63          */
64         PATCH,
65         /** The keys match completely. */
66         IDENTICAL
67     }
68
69     /**
70      * Default constructor.
71      */
72     public PfKey() {
73         super();
74     }
75
76     /**
77      * Copy constructor.
78      *
79      * @param copyConcept the concept to copy from
80      */
81     public PfKey(final PfKey copyConcept) {
82         super(copyConcept);
83     }
84
85     @Override
86     public abstract String getId();
87
88     /**
89      * Return the result of a compatibility check of two keys.
90      *
91      * @param otherKey the key to check compatibility against
92      * @return the compatibility result of the check
93      */
94     public abstract Compatibility getCompatibility(@NonNull PfKey otherKey);
95
96     /**
97      * Check if two keys are compatible, that is the keys are IDENTICAL or have only MINOR, PATCH differences.
98      *
99      * @param otherKey the key to check compatibility against
100      * @return true, if the keys are compatible
101      */
102     public abstract boolean isCompatible(@NonNull PfKey otherKey);
103
104     /**
105      * Check if this key is a newer version than the other key.
106      *
107      * @param otherKey the key to check against
108      * @return true, if this key is newer than the other key
109      */
110     public abstract boolean isNewerThan(@NonNull PfKey otherKey);
111
112     /**
113      * Check if a key equals its null key.
114      *
115      * @return true, if the key is a null key
116      */
117     public abstract boolean isNullKey();
118
119     /**
120      * Get the major version of a key.
121      *
122      * @return the major version of a key
123      */
124     public abstract int getMajorVersion();
125
126     /**
127      * Get the minor version of a key.
128      *
129      * @return the minor version of a key
130      */
131     public abstract int getMinorVersion();
132
133     /**
134      * Get the patch version of a key.
135      *
136      * @return the patch version of a key
137      */
138     public abstract int getPatchVersion();
139 }