1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.jclouds.compute.domain;
20
21 import static com.google.common.base.Preconditions.checkNotNull;
22
23 import org.jclouds.javax.annotation.Nullable;
24
25 import com.google.common.annotations.Beta;
26
27
28
29
30
31
32 @Beta
33 public class OperatingSystem {
34
35 public static Builder builder() {
36 return new Builder();
37 }
38
39 public static class Builder {
40 protected OsFamily family;
41 protected String name;
42 protected String arch;
43 protected String version;
44 protected String description;
45 protected boolean is64Bit;
46
47 public Builder family(@Nullable OsFamily family) {
48 this.family = family;
49 return this;
50 }
51
52 public Builder name(@Nullable String name) {
53 this.name = name;
54 return this;
55 }
56
57 public Builder arch(@Nullable String arch) {
58 this.arch = arch;
59 return this;
60 }
61
62 public Builder version(@Nullable String version) {
63 this.version = version;
64 return this;
65 }
66
67 public Builder description(String description) {
68 this.description = checkNotNull(description, "description");
69 return this;
70 }
71
72 public Builder is64Bit(boolean is64Bit) {
73 this.is64Bit = is64Bit;
74 return this;
75 }
76
77 public OperatingSystem build() {
78 return new OperatingSystem(family, name, version, arch, description, is64Bit);
79 }
80
81 public Builder fromOperatingSystem(OperatingSystem in) {
82 return family(in.getFamily()).name(in.getName()).version(in.getVersion()).arch(in.getArch()).description(
83 in.getDescription()).is64Bit(in.is64Bit());
84 }
85 }
86
87 @Nullable
88 protected OsFamily family;
89 @Nullable
90 protected String name;
91 @Nullable
92 protected String arch;
93 @Nullable
94 protected String version;
95 protected String description;
96 protected boolean is64Bit;
97
98
99 protected OperatingSystem() {
100
101 }
102
103 public OperatingSystem(@Nullable OsFamily family, @Nullable String name, @Nullable String version,
104 @Nullable String arch, String description, boolean is64Bit) {
105 this.family = family;
106 this.name = name;
107 this.arch = arch;
108 this.version = version;
109 this.description = checkNotNull(description, "description");
110 this.is64Bit = is64Bit;
111 }
112
113
114
115
116
117
118
119
120 @Nullable
121 public OsFamily getFamily() {
122 return family;
123 }
124
125
126
127
128
129
130
131
132
133
134 @Nullable
135 public String getName() {
136 return name;
137 }
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152 @Nullable
153 public String getArch() {
154 return arch;
155 }
156
157
158
159
160
161
162
163
164
165
166
167
168
169 @Nullable
170 public String getVersion() {
171 return version;
172 }
173
174
175
176
177
178
179
180
181
182
183 public String getDescription() {
184 return description;
185 }
186
187
188
189
190
191 public boolean is64Bit() {
192 return is64Bit;
193 }
194
195 @Override
196 public int hashCode() {
197 final int prime = 31;
198 int result = 1;
199 result = prime * result + ((arch == null) ? 0 : arch.hashCode());
200 result = prime * result + ((description == null) ? 0 : description.hashCode());
201 result = prime * result + ((family == null) ? 0 : family.hashCode());
202 result = prime * result + (is64Bit ? 1231 : 1237);
203 result = prime * result + ((name == null) ? 0 : name.hashCode());
204 result = prime * result + ((version == null) ? 0 : version.hashCode());
205 return result;
206 }
207
208 @Override
209 public boolean equals(Object obj) {
210 if (this == obj)
211 return true;
212 if (obj == null)
213 return false;
214 if (getClass() != obj.getClass())
215 return false;
216 OperatingSystem other = (OperatingSystem) obj;
217 if (arch == null) {
218 if (other.arch != null)
219 return false;
220 } else if (!arch.equals(other.arch))
221 return false;
222 if (description == null) {
223 if (other.description != null)
224 return false;
225 } else if (!description.equals(other.description))
226 return false;
227 if (family == null) {
228 if (other.family != null)
229 return false;
230 } else if (!family.equals(other.family))
231 return false;
232 if (is64Bit != other.is64Bit)
233 return false;
234 if (name == null) {
235 if (other.name != null)
236 return false;
237 } else if (!name.equals(other.name))
238 return false;
239 if (version == null) {
240 if (other.version != null)
241 return false;
242 } else if (!version.equals(other.version))
243 return false;
244 return true;
245 }
246
247 public Builder toBuilder() {
248 return builder().fromOperatingSystem(this);
249 }
250
251 @Override
252 public String toString() {
253 return "[name=" + name + ", family=" + family + ", version=" + version + ", arch=" + arch + ", is64Bit="
254 + is64Bit + ", description=" + description + "]";
255 }
256
257 }