migrate model-impl from drools-applications
[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
27 public class Resource implements Serializable {
28
29     private static final long serialVersionUID = -913729158733348027L;
30     
31     private UUID    resourceUuid;
32     private UUID    resourceInvariantUuid;
33     private String  resourceName;
34     private String  resourceVersion;
35     private ResourceType    resourceType;
36     
37     public Resource() {
38         //Empty Constructor
39     }
40     
41     /**
42      * Constructor.
43      * 
44      * @param resource copy object
45      */
46     public Resource(Resource resource) {
47         this.resourceUuid = resource.resourceUuid;
48         this.resourceInvariantUuid = resource.resourceInvariantUuid;
49         this.resourceName = resource.resourceName;
50         this.resourceVersion = resource.resourceVersion;
51         this.resourceType = resource.resourceType;
52     }
53     
54     public Resource(UUID uuid) {
55         this.resourceUuid = uuid;
56     }
57     
58     public Resource(String name, ResourceType type) {
59         this.resourceName = name;
60         this.resourceType = type;
61     }
62     
63     /**
64      * Constructor.
65      * 
66      * @param uuid uuid
67      * @param invariantUuid invariant uuid
68      * @param name name
69      * @param version version
70      * @param type type
71      */
72     public Resource(UUID uuid, UUID invariantUuid, String name, String version, ResourceType type) {
73         this.resourceUuid = uuid;
74         this.resourceInvariantUuid = invariantUuid;
75         this.resourceName = name;
76         this.resourceVersion = version;
77         this.resourceType = type;
78     }
79     
80     public UUID getResourceUuid() {
81         return resourceUuid;
82     }
83
84     public void setResourceUuid(UUID resourceUuid) {
85         this.resourceUuid = resourceUuid;
86     }
87
88     public UUID getResourceInvariantUuid() {
89         return resourceInvariantUuid;
90     }
91
92     public void setResourceInvariantUuid(UUID resourceInvariantUuid) {
93         this.resourceInvariantUuid = resourceInvariantUuid;
94     }
95
96     public String getResourceName() {
97         return resourceName;
98     }
99
100     public void setResourceName(String resourceName) {
101         this.resourceName = resourceName;
102     }
103
104     public String getResourceVersion() {
105         return resourceVersion;
106     }
107
108     public void setResourceVersion(String resourceVersion) {
109         this.resourceVersion = resourceVersion;
110     }
111
112     public ResourceType getResourceType() {
113         return resourceType;
114     }
115
116     public void setResourceType(ResourceType resourceType) {
117         this.resourceType = resourceType;
118     }
119
120     @Override
121     public String toString() {
122         return "Resource [resourceUuid=" + resourceUuid + ", resourceInvariantUuid=" + resourceInvariantUuid
123                 + ", resourceName=" + resourceName + ", resourceVersion=" + resourceVersion + ", resourceType="
124                 + resourceType + "]";
125     }
126     
127     @Override
128     public int hashCode() {
129         final int prime = 31;
130         int result = 1;
131         result = prime * result + ((resourceInvariantUuid == null) ? 0 : resourceInvariantUuid.hashCode());
132         result = prime * result + ((resourceName == null) ? 0 : resourceName.hashCode());
133         result = prime * result + ((resourceType == null) ? 0 : resourceType.hashCode());
134         result = prime * result + ((resourceUuid == null) ? 0 : resourceUuid.hashCode());
135         result = prime * result + ((resourceVersion == null) ? 0 : resourceVersion.hashCode());
136         return result;
137     }
138     
139     @Override
140     public boolean equals(Object obj) {
141         if (this == obj) {
142             return true;
143         }
144         if (obj == null) {
145             return false;
146         }
147         if (getClass() != obj.getClass()) {
148             return false;
149         }
150         Resource other = (Resource) obj;
151         if (resourceInvariantUuid == null) {
152             if (other.resourceInvariantUuid != null) {
153                 return false;
154             }
155         } else if (!resourceInvariantUuid.equals(other.resourceInvariantUuid)) {
156             return false;
157         }
158         if (resourceName == null) {
159             if (other.resourceName != null) {
160                 return false;
161             }
162         } else if (!resourceName.equals(other.resourceName)) {
163             return false;
164         }
165         if (resourceType == null) {
166             if (other.resourceType != null) {
167                 return false;
168             }
169         } else if (!resourceType.equals(other.resourceType)) {
170             return false;
171         }
172         if (resourceUuid == null) {
173             if (other.resourceUuid != null) {
174                 return false;
175             }
176         } else if (!resourceUuid.equals(other.resourceUuid)) {
177             return false;
178         }
179         if (resourceVersion == null) {
180             if (other.resourceVersion != null) {
181                 return false;
182             }
183         } else if (!resourceVersion.equals(other.resourceVersion)) {
184             return false;
185         }
186         return true;
187     }
188     
189 }