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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.base;
23 import lombok.NonNull;
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.
29 public abstract class PfKey extends PfConcept {
30 private static final long serialVersionUID = 6281159885962014041L;
32 /** Regular expression to specify the structure of key names. */
33 public static final String NAME_REGEXP = "[A-Za-z0-9\\-_\\.]+";
35 /** Regular expression to specify the structure of key versions. */
36 public static final String VERSION_REGEXP = "[A-Za-z0-9.]+";
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]";
41 /** Specifies the value for names in NULL keys. */
42 public static final String NULL_KEY_NAME = "NULL";
44 /** Specifies the value for versions in NULL keys. */
45 public static final String NULL_KEY_VERSION = "0.0.0";
48 * This enumeration is returned on key compatibility checks.
50 public enum Compatibility {
51 /** The keys have different names. */
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).
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).
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).
65 /** The keys match completely. */
70 * Default constructor.
79 * @param copyConcept the concept to copy from
81 public PfKey(final PfKey copyConcept) {
86 public abstract String getId();
89 * Return the result of a compatibility check of two keys.
91 * @param otherKey the key to check compatibility against
92 * @return the compatibility result of the check
94 public abstract Compatibility getCompatibility(@NonNull PfKey otherKey);
97 * Check if two keys are compatible, that is the keys are IDENTICAL or have only MINOR, PATCH differences.
99 * @param otherKey the key to check compatibility against
100 * @return true, if the keys are compatible
102 public abstract boolean isCompatible(@NonNull PfKey otherKey);
105 * Check if a key equals its null key.
107 * @return true, if the key is a null key
109 public abstract boolean isNullKey();