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.ec2.domain; |
20 | |
21 | import java.util.Date; |
22 | |
23 | import org.jclouds.ec2.domain.Attachment.Status; |
24 | |
25 | /** |
26 | * |
27 | * @see <a href= |
28 | * "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-ItemType-RunningInstancesItemType.html" |
29 | * /> |
30 | * @author Adrian Cole |
31 | */ |
32 | public class BlockDevice { |
33 | private final String volumeId; |
34 | private final Attachment.Status attachmentStatus; |
35 | private final Date attachTime; |
36 | private final boolean deleteOnTermination; |
37 | |
38 | public BlockDevice(String volumeId, Status attachmentStatus, Date attachTime, boolean deleteOnTermination) { |
39 | this.volumeId = volumeId; |
40 | this.attachmentStatus = attachmentStatus; |
41 | this.attachTime = attachTime; |
42 | this.deleteOnTermination = deleteOnTermination; |
43 | } |
44 | |
45 | public BlockDevice(String volumeId, boolean deleteOnTermination) { |
46 | this(volumeId, null, null, deleteOnTermination); |
47 | } |
48 | |
49 | @Override |
50 | public int hashCode() { |
51 | final int prime = 31; |
52 | int result = 1; |
53 | result = prime * result + ((attachTime == null) ? 0 : attachTime.hashCode()); |
54 | result = prime * result + ((attachmentStatus == null) ? 0 : attachmentStatus.hashCode()); |
55 | result = prime * result + (deleteOnTermination ? 1231 : 1237); |
56 | result = prime * result + ((volumeId == null) ? 0 : volumeId.hashCode()); |
57 | return result; |
58 | } |
59 | |
60 | @Override |
61 | public boolean equals(Object obj) { |
62 | if (this == obj) |
63 | return true; |
64 | if (obj == null) |
65 | return false; |
66 | if (getClass() != obj.getClass()) |
67 | return false; |
68 | BlockDevice other = (BlockDevice) obj; |
69 | if (attachTime == null) { |
70 | if (other.attachTime != null) |
71 | return false; |
72 | } else if (!attachTime.equals(other.attachTime)) |
73 | return false; |
74 | if (attachmentStatus == null) { |
75 | if (other.attachmentStatus != null) |
76 | return false; |
77 | } else if (!attachmentStatus.equals(other.attachmentStatus)) |
78 | return false; |
79 | if (deleteOnTermination != other.deleteOnTermination) |
80 | return false; |
81 | if (volumeId == null) { |
82 | if (other.volumeId != null) |
83 | return false; |
84 | } else if (!volumeId.equals(other.volumeId)) |
85 | return false; |
86 | return true; |
87 | } |
88 | |
89 | public String getVolumeId() { |
90 | return volumeId; |
91 | } |
92 | |
93 | public Attachment.Status getAttachmentStatus() { |
94 | return attachmentStatus; |
95 | } |
96 | |
97 | public Date getAttachTime() { |
98 | return attachTime; |
99 | } |
100 | |
101 | public boolean isDeleteOnTermination() { |
102 | return deleteOnTermination; |
103 | } |
104 | |
105 | @Override |
106 | public String toString() { |
107 | return "[volumeId=" + volumeId + ", attachmentStatus=" + attachmentStatus + ", attachTime=" |
108 | + attachTime + ", deleteOnTermination=" + deleteOnTermination + "]"; |
109 | } |
110 | |
111 | } |