Merge "Allow multiple versions of entities to be returned"
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / authorative / concepts / ToscaPolicyIdentifierOptVersion.java
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     @Override
60     public int compareTo(ToscaPolicyIdentifierOptVersion other) {
61         if (this == other) {
62             return 0;
63         }
64
65         if (other == null) {
66             return 1;
67         }
68
69         int result = ObjectUtils.compare(getName(), other.getName());
70         if (result != 0) {
71             return result;
72         }
73
74         return ObjectUtils.compare(getVersion(), other.getVersion());
75     }
76 }