61b6e3afd4c8d8df88ae0ccc3fde02c99b617688
[policy/models.git] / models-interactions / model-impl / sdc / src / main / java / org / onap / policy / sdc / Resource.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 Resource implements Serializable {
32
33     private static final long serialVersionUID = -913729158733348027L;
34
35     private UUID    resourceUuid;
36     private UUID    resourceInvariantUuid;
37     private String  resourceName;
38     private String  resourceVersion;
39     private String    resourceType;
40
41     public Resource() {
42         //Empty Constructor
43     }
44
45     /**
46      * Constructor.
47      *
48      * @param resource copy object
49      */
50     public Resource(Resource resource) {
51         this.resourceUuid = resource.resourceUuid;
52         this.resourceInvariantUuid = resource.resourceInvariantUuid;
53         this.resourceName = resource.resourceName;
54         this.resourceVersion = resource.resourceVersion;
55         this.resourceType = resource.resourceType;
56     }
57
58     public Resource(UUID uuid) {
59         this.resourceUuid = uuid;
60     }
61
62     public Resource(String name, String type) {
63         this.resourceName = name;
64         this.resourceType = type;
65     }
66
67     /**
68      * Constructor.
69      *
70      * @param uuid uuid
71      * @param invariantUuid invariant uuid
72      * @param name name
73      * @param version version
74      * @param type type
75      */
76     public Resource(UUID uuid, UUID invariantUuid, String name, String version, String type) {
77         this.resourceUuid = uuid;
78         this.resourceInvariantUuid = invariantUuid;
79         this.resourceName = name;
80         this.resourceVersion = version;
81         this.resourceType = type;
82     }
83
84     @Override
85     public String toString() {
86         return "Resource [resourceUuid=" + resourceUuid + ", resourceInvariantUuid=" + resourceInvariantUuid
87                 + ", resourceName=" + resourceName + ", resourceVersion=" + resourceVersion + ", resourceType="
88                 + resourceType + "]";
89     }
90
91     @Override
92     public int hashCode() {
93         final int prime = 31;
94         int result = 1;
95         result = prime * result + ((resourceInvariantUuid == null) ? 0 : resourceInvariantUuid.hashCode());
96         result = prime * result + ((resourceName == null) ? 0 : resourceName.hashCode());
97         result = prime * result + ((resourceType == null) ? 0 : resourceType.hashCode());
98         result = prime * result + ((resourceUuid == null) ? 0 : resourceUuid.hashCode());
99         result = prime * result + ((resourceVersion == null) ? 0 : resourceVersion.hashCode());
100         return result;
101     }
102
103     @Override
104     public boolean equals(Object obj) {
105         if (this == obj) {
106             return true;
107         }
108         if (obj == null) {
109             return false;
110         }
111         if (getClass() != obj.getClass()) {
112             return false;
113         }
114         Resource other = (Resource) obj;
115         if (resourceInvariantUuid == null) {
116             if (other.resourceInvariantUuid != null) {
117                 return false;
118             }
119         } else if (!resourceInvariantUuid.equals(other.resourceInvariantUuid)) {
120             return false;
121         }
122         if (resourceName == null) {
123             if (other.resourceName != null) {
124                 return false;
125             }
126         } else if (!resourceName.equals(other.resourceName)) {
127             return false;
128         }
129         if (resourceType == null) {
130             if (other.resourceType != null) {
131                 return false;
132             }
133         } else if (!resourceType.equals(other.resourceType)) {
134             return false;
135         }
136         if (resourceUuid == null) {
137             if (other.resourceUuid != null) {
138                 return false;
139             }
140         } else if (!resourceUuid.equals(other.resourceUuid)) {
141             return false;
142         }
143         if (resourceVersion == null) {
144             if (other.resourceVersion != null) {
145                 return false;
146             }
147         } else if (!resourceVersion.equals(other.resourceVersion)) {
148             return false;
149         }
150         return true;
151     }
152
153 }