1 | /** |
2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
3 | * contributor license agreements. See the NOTICE file |
4 | * distributed with this work for additional information |
5 | * regarding copyright ownership. jclouds licenses this file |
6 | * to you under the Apache License, Version 2.0 (the |
7 | * "License"); you may not use this file except in compliance |
8 | * with the License. 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, |
13 | * software distributed under the License is distributed on an |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
15 | * KIND, either express or implied. See the License for the |
16 | * specific language governing permissions and limitations |
17 | * under the License. |
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 | import java.util.Set; |
26 | |
27 | import org.jclouds.compute.domain.ComputeMetadata; |
28 | import org.jclouds.compute.domain.ComputeType; |
29 | import org.jclouds.domain.Location; |
30 | import org.jclouds.domain.internal.ResourceMetadataImpl; |
31 | |
32 | import com.google.common.collect.ImmutableSet; |
33 | |
34 | /** |
35 | * @author Adrian Cole |
36 | * @author Ivan Meredith |
37 | */ |
38 | public class ComputeMetadataImpl extends ResourceMetadataImpl<ComputeType> implements ComputeMetadata { |
39 | /** The serialVersionUID */ |
40 | private static final long serialVersionUID = 7374704415964898694L; |
41 | private final String id; |
42 | private final ComputeType type; |
43 | protected final Set<String> tags; |
44 | |
45 | public ComputeMetadataImpl(ComputeType type, String providerId, String name, String id, Location location, URI uri, |
46 | Map<String, String> userMetadata, Set<String> tags) { |
47 | super(providerId, name, location, uri, userMetadata); |
48 | this.id = checkNotNull(id, "id"); |
49 | this.type = checkNotNull(type, "type"); |
50 | this.tags = ImmutableSet.<String> copyOf(checkNotNull(tags, "tags")); |
51 | } |
52 | |
53 | /** |
54 | * {@inheritDoc} |
55 | */ |
56 | @Override |
57 | public ComputeType getType() { |
58 | return type; |
59 | } |
60 | |
61 | /** |
62 | * {@inheritDoc} |
63 | */ |
64 | @Override |
65 | public String getId() { |
66 | return id; |
67 | } |
68 | |
69 | /** |
70 | * {@inheritDoc} |
71 | */ |
72 | @Override |
73 | public Set<String> getTags() { |
74 | return tags; |
75 | } |
76 | |
77 | @Override |
78 | public int hashCode() { |
79 | final int prime = 31; |
80 | int result = super.hashCode(); |
81 | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
82 | result = prime * result + ((type == null) ? 0 : type.hashCode()); |
83 | return result; |
84 | } |
85 | |
86 | @Override |
87 | public boolean equals(Object obj) { |
88 | if (this == obj) |
89 | return true; |
90 | if (!super.equals(obj)) |
91 | return false; |
92 | if (getClass() != obj.getClass()) |
93 | return false; |
94 | ComputeMetadataImpl other = (ComputeMetadataImpl) obj; |
95 | if (id == null) { |
96 | if (other.id != null) |
97 | return false; |
98 | } else if (!id.equals(other.id)) |
99 | return false; |
100 | if (type != other.type) |
101 | return false; |
102 | return true; |
103 | } |
104 | |
105 | } |