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 static com.google.common.base.Preconditions.checkNotNull; |
22 | |
23 | import java.util.Set; |
24 | |
25 | import com.google.common.collect.Iterables; |
26 | import com.google.common.collect.Sets; |
27 | |
28 | /** |
29 | * |
30 | * @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-ItemType-AvailabilityZoneItemType.html" |
31 | * /> |
32 | * @author Adrian Cole |
33 | */ |
34 | public class AvailabilityZoneInfo implements Comparable<AvailabilityZoneInfo>{ |
35 | |
36 | private final String zone; |
37 | private final String state; |
38 | private final String region; |
39 | private final Set<String> messages = Sets.newHashSet(); |
40 | |
41 | public AvailabilityZoneInfo(String zone, String zoneState, |
42 | String region, Iterable<String> messages) { |
43 | this.zone = checkNotNull(zone, "zone"); |
44 | this.state = checkNotNull(zoneState, "zoneState"); |
45 | this.region = checkNotNull(region, "region"); |
46 | Iterables.addAll(this.messages, checkNotNull(messages, "messages")); |
47 | } |
48 | |
49 | /** |
50 | * the Availability Zone. |
51 | */ |
52 | public String getZone() { |
53 | return zone; |
54 | } |
55 | |
56 | /** |
57 | * State of the Availability Zone. |
58 | */ |
59 | public String getState() { |
60 | return state; |
61 | } |
62 | |
63 | /** |
64 | * Name of the Region. |
65 | */ |
66 | public String getRegion() { |
67 | return region; |
68 | } |
69 | |
70 | /** |
71 | * Messages |
72 | */ |
73 | public Set<String> getMessages() { |
74 | return messages; |
75 | } |
76 | |
77 | @Override |
78 | public int hashCode() { |
79 | final int prime = 31; |
80 | int result = 1; |
81 | result = prime * result + ((messages == null) ? 0 : messages.hashCode()); |
82 | result = prime * result + ((region == null) ? 0 : region.hashCode()); |
83 | result = prime * result + ((state == null) ? 0 : state.hashCode()); |
84 | result = prime * result + ((zone == null) ? 0 : zone.hashCode()); |
85 | return result; |
86 | } |
87 | |
88 | @Override |
89 | public boolean equals(Object obj) { |
90 | if (this == obj) |
91 | return true; |
92 | if (obj == null) |
93 | return false; |
94 | if (getClass() != obj.getClass()) |
95 | return false; |
96 | AvailabilityZoneInfo other = (AvailabilityZoneInfo) obj; |
97 | if (messages == null) { |
98 | if (other.messages != null) |
99 | return false; |
100 | } else if (!messages.equals(other.messages)) |
101 | return false; |
102 | if (region == null) { |
103 | if (other.region != null) |
104 | return false; |
105 | } else if (!region.equals(other.region)) |
106 | return false; |
107 | if (state == null) { |
108 | if (other.state != null) |
109 | return false; |
110 | } else if (!state.equals(other.state)) |
111 | return false; |
112 | if (zone == null) { |
113 | if (other.zone != null) |
114 | return false; |
115 | } else if (!zone.equals(other.zone)) |
116 | return false; |
117 | return true; |
118 | } |
119 | |
120 | @Override |
121 | public String toString() { |
122 | return "AvailabilityZoneInfo [messages=" + messages + ", region=" + region + ", state=" |
123 | + state + ", zone=" + zone + "]"; |
124 | } |
125 | |
126 | @Override |
127 | public int compareTo(AvailabilityZoneInfo that) { |
128 | return zone.compareTo(that.zone); |
129 | } |
130 | |
131 | } |