1 | /** |
2 | * |
3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
4 | * |
5 | * ==================================================================== |
6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * you may not use this file except in compliance with the License. |
8 | * You may obtain a copy of the License at |
9 | * |
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * |
12 | * Unless required by applicable law or agreed to in writing, software |
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * See the License for the specific language governing permissions and |
16 | * limitations under the License. |
17 | * ==================================================================== |
18 | */ |
19 | package org.jclouds.compute.domain.internal; |
20 | |
21 | import static com.google.common.base.Preconditions.checkNotNull; |
22 | |
23 | import java.net.URI; |
24 | import java.util.Map; |
25 | |
26 | import org.jclouds.compute.domain.ComputeMetadata; |
27 | import org.jclouds.compute.domain.ComputeType; |
28 | import org.jclouds.domain.Location; |
29 | import org.jclouds.domain.internal.ResourceMetadataImpl; |
30 | |
31 | /** |
32 | * @author Adrian Cole |
33 | * @author Ivan Meredith |
34 | */ |
35 | public class ComputeMetadataImpl extends ResourceMetadataImpl<ComputeType> implements ComputeMetadata { |
36 | /** The serialVersionUID */ |
37 | private static final long serialVersionUID = 7374704415964898694L; |
38 | private final String id; |
39 | private final ComputeType type; |
40 | |
41 | public ComputeMetadataImpl(ComputeType type, String providerId, String name, String id, Location location, URI uri, |
42 | Map<String, String> userMetadata) { |
43 | super(providerId, name, location, uri, userMetadata); |
44 | this.id = checkNotNull(id, "id"); |
45 | this.type = checkNotNull(type, "type"); |
46 | } |
47 | |
48 | /** |
49 | * {@inheritDoc} |
50 | */ |
51 | @Override |
52 | public ComputeType getType() { |
53 | return type; |
54 | } |
55 | |
56 | /** |
57 | * {@inheritDoc} |
58 | */ |
59 | @Override |
60 | public String getId() { |
61 | return id; |
62 | } |
63 | |
64 | @Override |
65 | public int hashCode() { |
66 | final int prime = 31; |
67 | int result = super.hashCode(); |
68 | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
69 | result = prime * result + ((type == null) ? 0 : type.hashCode()); |
70 | return result; |
71 | } |
72 | |
73 | @Override |
74 | public boolean equals(Object obj) { |
75 | if (this == obj) |
76 | return true; |
77 | if (!super.equals(obj)) |
78 | return false; |
79 | if (getClass() != obj.getClass()) |
80 | return false; |
81 | ComputeMetadataImpl other = (ComputeMetadataImpl) obj; |
82 | if (id == null) { |
83 | if (other.id != null) |
84 | return false; |
85 | } else if (!id.equals(other.id)) |
86 | return false; |
87 | if (type != other.type) |
88 | return false; |
89 | return true; |
90 | } |
91 | |
92 | } |