adfd616c38cd967af6ae3015af8845428f43af53
[policy/models.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Models
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.models.tosca.authorative.concepts;
22
23 import com.google.gson.annotations.SerializedName;
24 import lombok.Data;
25 import lombok.NoArgsConstructor;
26 import lombok.NonNull;
27 import org.apache.commons.lang3.ObjectUtils;
28
29 /**
30  * Policy identifier with an optional version; only the "name" is required.
31  */
32 @Data
33 @NoArgsConstructor
34 public class ToscaPolicyIdentifierOptVersion implements Comparable<ToscaPolicyIdentifierOptVersion> {
35
36     @NonNull
37     @SerializedName("policy-id")
38     private String name;
39
40     @SerializedName("policy-version")
41     private String version;
42
43
44     public ToscaPolicyIdentifierOptVersion(@NonNull String name, String version) {
45         this.name = name;
46         this.version = version;
47     }
48
49     public ToscaPolicyIdentifierOptVersion(ToscaPolicyIdentifierOptVersion source) {
50         this.name = source.name;
51         this.version = source.version;
52     }
53
54     public ToscaPolicyIdentifierOptVersion(ToscaPolicyIdentifier source) {
55         this.name = source.getName();
56         this.version = source.getVersion();
57     }
58
59     /**
60      * Determines if the version is null/missing.
61      *
62      * @return {@code true} if the version is null/missing, {@code false}
63      */
64     public boolean isNullVersion() {
65         return (version == null);
66     }
67
68     @Override
69     public int compareTo(ToscaPolicyIdentifierOptVersion other) {
70         if (this == other) {
71             return 0;
72         }
73
74         if (other == null) {
75             return 1;
76         }
77
78         int result = ObjectUtils.compare(getName(), other.getName());
79         if (result != 0) {
80             return result;
81         }
82
83         return ObjectUtils.compare(getVersion(), other.getVersion());
84     }
85 }