| 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 | |
| 24 | /** |
| 25 | * |
| 26 | * @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-ItemType-TerminateInstancesResponseInfoType.html" |
| 27 | * /> |
| 28 | * @author Adrian Cole |
| 29 | */ |
| 30 | public class InstanceStateChange implements Comparable<InstanceStateChange> { |
| 31 | |
| 32 | private final String region; |
| 33 | private final String instanceId; |
| 34 | private final InstanceState currentState; |
| 35 | private final InstanceState previousState; |
| 36 | |
| 37 | public int compareTo(InstanceStateChange o) { |
| 38 | return (this == o) ? 0 : getInstanceId().compareTo(o.getInstanceId()); |
| 39 | } |
| 40 | |
| 41 | public InstanceStateChange(String region, String instanceId, InstanceState currentState, |
| 42 | InstanceState previousState) { |
| 43 | this.region = checkNotNull(region, "region"); |
| 44 | this.instanceId = instanceId; |
| 45 | this.currentState = currentState; |
| 46 | this.previousState = previousState; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Instances are tied to Availability Zones. However, the instance ID is tied to the Region. |
| 51 | */ |
| 52 | public String getRegion() { |
| 53 | return region; |
| 54 | } |
| 55 | |
| 56 | public String getInstanceId() { |
| 57 | return instanceId; |
| 58 | } |
| 59 | |
| 60 | public InstanceState getCurrentState() { |
| 61 | return currentState; |
| 62 | } |
| 63 | |
| 64 | public InstanceState getPreviousState() { |
| 65 | return previousState; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public int hashCode() { |
| 70 | final int prime = 31; |
| 71 | int result = 1; |
| 72 | result = prime * result + ((instanceId == null) ? 0 : instanceId.hashCode()); |
| 73 | result = prime * result + ((previousState == null) ? 0 : previousState.hashCode()); |
| 74 | result = prime * result + ((region == null) ? 0 : region.hashCode()); |
| 75 | result = prime * result + ((currentState == null) ? 0 : currentState.hashCode()); |
| 76 | return result; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public boolean equals(Object obj) { |
| 81 | if (this == obj) |
| 82 | return true; |
| 83 | if (obj == null) |
| 84 | return false; |
| 85 | if (getClass() != obj.getClass()) |
| 86 | return false; |
| 87 | InstanceStateChange other = (InstanceStateChange) obj; |
| 88 | if (instanceId == null) { |
| 89 | if (other.instanceId != null) |
| 90 | return false; |
| 91 | } else if (!instanceId.equals(other.instanceId)) |
| 92 | return false; |
| 93 | if (previousState == null) { |
| 94 | if (other.previousState != null) |
| 95 | return false; |
| 96 | } else if (!previousState.equals(other.previousState)) |
| 97 | return false; |
| 98 | if (region == null) { |
| 99 | if (other.region != null) |
| 100 | return false; |
| 101 | } else if (!region.equals(other.region)) |
| 102 | return false; |
| 103 | if (currentState == null) { |
| 104 | if (other.currentState != null) |
| 105 | return false; |
| 106 | } else if (!currentState.equals(other.currentState)) |
| 107 | return false; |
| 108 | return true; |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public String toString() { |
| 113 | return "InstanceStateChange [currentState=" + currentState + ", instanceId=" + instanceId |
| 114 | + ", previousState=" + previousState + ", region=" + region + "]"; |
| 115 | } |
| 116 | |
| 117 | } |