7ab2f93223e41560612a11a569ec60f45bdb88f3
[policy/models.git] / models-interactions / model-impl / sdc / src / main / java / org / onap / policy / sdc / Service.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * sdc
4  * ================================================================================
5  * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 Nordix Foundation.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.sdc;
23
24 import java.io.Serializable;
25 import java.util.UUID;
26 import lombok.Getter;
27 import lombok.Setter;
28
29 @Getter
30 @Setter
31 public class Service implements Serializable {
32
33     private static final long serialVersionUID = -1249276698549996806L;
34
35     private UUID serviceUUID;
36     private UUID serviceInvariantUUID;
37     private String serviceName;
38     private String serviceVersion;
39
40     public Service() {
41         //Empty Constructor
42     }
43
44     public Service(UUID uuid) {
45         this.serviceUUID = uuid;
46     }
47
48     public Service(String name) {
49         this.serviceName = name;
50     }
51
52     /**
53      * Constructor.
54      *
55      * @param uuid service id
56      * @param invariantUUID service invariant id
57      * @param name name
58      * @param version version
59      */
60     public Service(UUID uuid, UUID invariantUUID, String name, String version) {
61         this.serviceUUID = uuid;
62         this.serviceInvariantUUID = invariantUUID;
63         this.serviceName = name;
64         this.serviceVersion = version;
65     }
66
67     /**
68      * Constructor.
69      *
70      * @param service copy object
71      */
72     public Service(Service service) {
73         this.serviceUUID = service.serviceUUID;
74         this.serviceInvariantUUID = service.serviceInvariantUUID;
75         this.serviceName = service.serviceName;
76         this.serviceVersion = service.serviceVersion;
77     }
78
79     @Override
80     public String toString() {
81         return "Service [serviceUUID=" + serviceUUID + ", serviceInvariantUUID=" + serviceInvariantUUID
82             + ", serviceName=" + serviceName + ", serviceVersion=" + serviceVersion + "]";
83     }
84
85     @Override
86     public int hashCode() {
87         final int prime = 31;
88         int result = 1;
89         result = prime * result + ((serviceInvariantUUID == null) ? 0 : serviceInvariantUUID.hashCode());
90         result = prime * result + ((serviceName == null) ? 0 : serviceName.hashCode());
91         result = prime * result + ((serviceUUID == null) ? 0 : serviceUUID.hashCode());
92         result = prime * result + ((serviceVersion == null) ? 0 : serviceVersion.hashCode());
93         return result;
94     }
95
96     @Override
97     public boolean equals(Object obj) {
98         if (this == obj) {
99             return true;
100         }
101         if (obj == null) {
102             return false;
103         }
104         if (getClass() != obj.getClass()) {
105             return false;
106         }
107         Service other = (Service) obj;
108         if (serviceInvariantUUID == null) {
109             if (other.serviceInvariantUUID != null) {
110                 return false;
111             }
112         } else if (!serviceInvariantUUID.equals(other.serviceInvariantUUID)) {
113             return false;
114         }
115         if (serviceName == null) {
116             if (other.serviceName != null) {
117                 return false;
118             }
119         } else if (!serviceName.equals(other.serviceName)) {
120             return false;
121         }
122         if (serviceUUID == null) {
123             if (other.serviceUUID != null) {
124                 return false;
125             }
126         } else if (!serviceUUID.equals(other.serviceUUID)) {
127             return false;
128         }
129         if (serviceVersion == null) {
130             return other.serviceVersion == null;
131         } else {
132             return serviceVersion.equals(other.serviceVersion);
133         }
134     }
135 }