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 org.jclouds.javax.annotation.Nullable; |
24 | |
25 | import org.jclouds.compute.domain.Volume; |
26 | |
27 | /** |
28 | * @author Adrian Cole |
29 | */ |
30 | public class VolumeImpl implements Volume { |
31 | |
32 | private final String id; |
33 | private final Volume.Type type; |
34 | private final @Nullable |
35 | Float size; |
36 | private final @Nullable |
37 | String device; |
38 | private final boolean bootDevice; |
39 | private final boolean durable; |
40 | |
41 | public VolumeImpl(@Nullable String id, Volume.Type type, @Nullable Float size, @Nullable String device, |
42 | boolean bootDevice, boolean durable) { |
43 | this.id = id; |
44 | this.type = checkNotNull(type, "type"); |
45 | this.size = size; |
46 | this.device = device; |
47 | this.bootDevice = bootDevice; |
48 | this.durable = durable; |
49 | } |
50 | |
51 | public VolumeImpl(@Nullable Float size, boolean bootDevice, boolean durable) { |
52 | this(null, Volume.Type.LOCAL, size, null, bootDevice, durable); |
53 | } |
54 | |
55 | public VolumeImpl(@Nullable Float size, @Nullable String device, boolean bootDevice, boolean durable) { |
56 | this(null, Volume.Type.LOCAL, size, device, bootDevice, durable); |
57 | } |
58 | |
59 | /** |
60 | * {@inheritDoc} |
61 | */ |
62 | @Override |
63 | public String getId() { |
64 | return id; |
65 | } |
66 | |
67 | /** |
68 | * {@inheritDoc} |
69 | */ |
70 | @Override |
71 | public Volume.Type getType() { |
72 | return type; |
73 | } |
74 | |
75 | /** |
76 | * {@inheritDoc} |
77 | */ |
78 | @Override |
79 | public Float getSize() { |
80 | return size; |
81 | } |
82 | |
83 | /** |
84 | * {@inheritDoc} |
85 | */ |
86 | @Override |
87 | public String getDevice() { |
88 | return device; |
89 | } |
90 | |
91 | /** |
92 | * {@inheritDoc} |
93 | */ |
94 | @Override |
95 | public boolean isDurable() { |
96 | return durable; |
97 | } |
98 | |
99 | /** |
100 | * {@inheritDoc} |
101 | */ |
102 | @Override |
103 | public boolean isBootDevice() { |
104 | return bootDevice; |
105 | } |
106 | |
107 | /** |
108 | * {@inheritDoc} |
109 | */ |
110 | @Override |
111 | public String toString() { |
112 | return "[id=" + getId() + ", type=" + type + ", size=" + size + ", device=" + device + ", durable=" + durable |
113 | + ", isBootDevice=" + bootDevice + "]"; |
114 | } |
115 | |
116 | @Override |
117 | public int hashCode() { |
118 | final int prime = 31; |
119 | int result = 1; |
120 | result = prime * result + (bootDevice ? 1231 : 1237); |
121 | result = prime * result + ((device == null) ? 0 : device.hashCode()); |
122 | result = prime * result + (durable ? 1231 : 1237); |
123 | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
124 | result = prime * result + ((size == null) ? 0 : size.hashCode()); |
125 | result = prime * result + ((type == null) ? 0 : type.hashCode()); |
126 | return result; |
127 | } |
128 | |
129 | @Override |
130 | public boolean equals(Object obj) { |
131 | if (this == obj) |
132 | return true; |
133 | if (obj == null) |
134 | return false; |
135 | if (getClass() != obj.getClass()) |
136 | return false; |
137 | VolumeImpl other = (VolumeImpl) obj; |
138 | if (bootDevice != other.bootDevice) |
139 | return false; |
140 | if (device == null) { |
141 | if (other.device != null) |
142 | return false; |
143 | } else if (!device.equals(other.device)) |
144 | return false; |
145 | if (durable != other.durable) |
146 | return false; |
147 | if (id == null) { |
148 | if (other.id != null) |
149 | return false; |
150 | } else if (!id.equals(other.id)) |
151 | return false; |
152 | if (size == null) { |
153 | if (other.size != null) |
154 | return false; |
155 | } else if (!size.equals(other.size)) |
156 | return false; |
157 | if (type == null) { |
158 | if (other.type != null) |
159 | return false; |
160 | } else if (!type.equals(other.type)) |
161 | return false; |
162 | return true; |
163 | } |
164 | |
165 | } |