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 javax.annotation.Nullable; |
27 | |
28 | import org.jclouds.compute.domain.ComputeType; |
29 | import org.jclouds.compute.domain.Image; |
30 | import org.jclouds.compute.domain.OperatingSystem; |
31 | import org.jclouds.domain.Credentials; |
32 | import org.jclouds.domain.Location; |
33 | |
34 | /** |
35 | * @author Adrian Cole |
36 | */ |
37 | public class ImageImpl extends ComputeMetadataImpl implements Image { |
38 | |
39 | /** The serialVersionUID */ |
40 | private static final long serialVersionUID = 7856744554191025307L; |
41 | |
42 | private final OperatingSystem operatingSystem; |
43 | private final String version; |
44 | private final String description; |
45 | @Nullable |
46 | private final String adminPassword; |
47 | private final Credentials defaultCredentials; |
48 | |
49 | public ImageImpl(String providerId, String name, String id, Location location, URI uri, |
50 | Map<String, String> userMetadata, OperatingSystem operatingSystem, String description, |
51 | @Nullable String version, @Nullable String adminPassword, @Nullable Credentials defaultCredentials) { |
52 | super(ComputeType.IMAGE, providerId, name, id, location, uri, userMetadata); |
53 | this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem"); |
54 | this.version = version; |
55 | this.description = checkNotNull(description, "description"); |
56 | this.adminPassword = adminPassword; |
57 | this.defaultCredentials = defaultCredentials; |
58 | } |
59 | |
60 | /** |
61 | * {@inheritDoc} |
62 | */ |
63 | @Override |
64 | public OperatingSystem getOperatingSystem() { |
65 | return operatingSystem; |
66 | } |
67 | |
68 | /** |
69 | * {@inheritDoc} |
70 | */ |
71 | @Override |
72 | public String getVersion() { |
73 | return version; |
74 | } |
75 | |
76 | /** |
77 | * {@inheritDoc} |
78 | */ |
79 | @Override |
80 | public String getDescription() { |
81 | return description; |
82 | } |
83 | |
84 | /** |
85 | * {@inheritDoc} |
86 | */ |
87 | @Override |
88 | public Credentials getDefaultCredentials() { |
89 | return defaultCredentials; |
90 | } |
91 | |
92 | /** |
93 | * {@inheritDoc} |
94 | */ |
95 | @Override |
96 | public String getAdminPassword() { |
97 | return adminPassword; |
98 | } |
99 | |
100 | @Override |
101 | public String toString() { |
102 | return "[id=" + getId() + ", name=" + getName() + ", operatingSystem=" + operatingSystem + ", description=" |
103 | + description + ", version=" + version + ", location=" + getLocation() + ", loginUser=" |
104 | + ((defaultCredentials != null) ? defaultCredentials.identity : null) + ", userMetadata=" |
105 | + getUserMetadata() + "]"; |
106 | } |
107 | |
108 | @Override |
109 | public int hashCode() { |
110 | final int prime = 31; |
111 | int result = super.hashCode(); |
112 | result = prime * result + ((adminPassword == null) ? 0 : adminPassword.hashCode()); |
113 | result = prime * result + ((defaultCredentials == null) ? 0 : defaultCredentials.hashCode()); |
114 | result = prime * result + ((description == null) ? 0 : description.hashCode()); |
115 | result = prime * result + ((operatingSystem == null) ? 0 : operatingSystem.hashCode()); |
116 | result = prime * result + ((version == null) ? 0 : version.hashCode()); |
117 | return result; |
118 | } |
119 | |
120 | @Override |
121 | public boolean equals(Object obj) { |
122 | if (this == obj) |
123 | return true; |
124 | if (!super.equals(obj)) |
125 | return false; |
126 | if (getClass() != obj.getClass()) |
127 | return false; |
128 | ImageImpl other = (ImageImpl) obj; |
129 | if (adminPassword == null) { |
130 | if (other.adminPassword != null) |
131 | return false; |
132 | } else if (!adminPassword.equals(other.adminPassword)) |
133 | return false; |
134 | if (defaultCredentials == null) { |
135 | if (other.defaultCredentials != null) |
136 | return false; |
137 | } else if (!defaultCredentials.equals(other.defaultCredentials)) |
138 | return false; |
139 | if (description == null) { |
140 | if (other.description != null) |
141 | return false; |
142 | } else if (!description.equals(other.description)) |
143 | return false; |
144 | if (operatingSystem == null) { |
145 | if (other.operatingSystem != null) |
146 | return false; |
147 | } else if (!operatingSystem.equals(other.operatingSystem)) |
148 | return false; |
149 | if (version == null) { |
150 | if (other.version != null) |
151 | return false; |
152 | } else if (!version.equals(other.version)) |
153 | return false; |
154 | return true; |
155 | } |
156 | |
157 | } |