| 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 | /** |
| 22 | * |
| 23 | * @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateVolume.html" |
| 24 | * /> |
| 25 | * @author Adrian Cole |
| 26 | */ |
| 27 | public class ReservedInstancesOffering implements Comparable<ReservedInstancesOffering> { |
| 28 | private final String region; |
| 29 | private final String availabilityZone; |
| 30 | private final long duration; |
| 31 | private final float fixedPrice; |
| 32 | private final String instanceType; |
| 33 | private final String productDescription; |
| 34 | private final String id; |
| 35 | private final float usagePrice; |
| 36 | |
| 37 | public ReservedInstancesOffering(String region, String availabilityZone, long duration, float fixedPrice, String instanceType, |
| 38 | String productDescription, String reservedInstancesOfferingId, float usagePrice) { |
| 39 | this.region=region; |
| 40 | this.availabilityZone = availabilityZone; |
| 41 | this.duration = duration; |
| 42 | this.fixedPrice = fixedPrice; |
| 43 | this.instanceType = instanceType; |
| 44 | this.productDescription = productDescription; |
| 45 | this.id = reservedInstancesOfferingId; |
| 46 | this.usagePrice = usagePrice; |
| 47 | } |
| 48 | |
| 49 | public String getRegion() { |
| 50 | return region; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * @return The Availability Zone in which the Reserved Instance can be used. |
| 55 | */ |
| 56 | public String getAvailabilityZone() { |
| 57 | return availabilityZone; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * |
| 62 | * @return The duration of the Reserved Instance, in seconds |
| 63 | */ |
| 64 | public long getDuration() { |
| 65 | return duration; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * |
| 70 | * @return The purchase price of the Reserved Instance. |
| 71 | */ |
| 72 | public float getFixedPrice() { |
| 73 | return fixedPrice; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * |
| 78 | * @return The instance type on which the Reserved Instance can be used. |
| 79 | */ |
| 80 | public String getInstanceType() { |
| 81 | return instanceType; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * |
| 86 | * @return The Reserved Instance description. |
| 87 | */ |
| 88 | public String getProductDescription() { |
| 89 | return productDescription; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * @return The ID of the Reserved Instance offering. |
| 94 | */ |
| 95 | public String getId() { |
| 96 | return id; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * |
| 101 | * @return The usage price of the Reserved Instance, per hour. |
| 102 | */ |
| 103 | public float getUsagePrice() { |
| 104 | return usagePrice; |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public int compareTo(ReservedInstancesOffering o) { |
| 109 | return id.compareTo(o.id); |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public String toString() { |
| 114 | return "[availabilityZone=" + availabilityZone + ", duration=" + duration |
| 115 | + ", fixedPrice=" + fixedPrice + ", id=" + id + ", instanceType=" + instanceType + ", productDescription=" |
| 116 | + productDescription + ", region=" + region + ", usagePrice=" + usagePrice + "]"; |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public int hashCode() { |
| 121 | final int prime = 31; |
| 122 | int result = 1; |
| 123 | result = prime * result + ((availabilityZone == null) ? 0 : availabilityZone.hashCode()); |
| 124 | result = prime * result + (int) (duration ^ (duration >>> 32)); |
| 125 | result = prime * result + Float.floatToIntBits(fixedPrice); |
| 126 | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
| 127 | result = prime * result + ((instanceType == null) ? 0 : instanceType.hashCode()); |
| 128 | result = prime * result + ((productDescription == null) ? 0 : productDescription.hashCode()); |
| 129 | result = prime * result + ((region == null) ? 0 : region.hashCode()); |
| 130 | result = prime * result + Float.floatToIntBits(usagePrice); |
| 131 | return result; |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public boolean equals(Object obj) { |
| 136 | if (this == obj) |
| 137 | return true; |
| 138 | if (obj == null) |
| 139 | return false; |
| 140 | if (getClass() != obj.getClass()) |
| 141 | return false; |
| 142 | ReservedInstancesOffering other = (ReservedInstancesOffering) obj; |
| 143 | if (availabilityZone == null) { |
| 144 | if (other.availabilityZone != null) |
| 145 | return false; |
| 146 | } else if (!availabilityZone.equals(other.availabilityZone)) |
| 147 | return false; |
| 148 | if (duration != other.duration) |
| 149 | return false; |
| 150 | if (Float.floatToIntBits(fixedPrice) != Float.floatToIntBits(other.fixedPrice)) |
| 151 | return false; |
| 152 | if (id == null) { |
| 153 | if (other.id != null) |
| 154 | return false; |
| 155 | } else if (!id.equals(other.id)) |
| 156 | return false; |
| 157 | if (instanceType == null) { |
| 158 | if (other.instanceType != null) |
| 159 | return false; |
| 160 | } else if (!instanceType.equals(other.instanceType)) |
| 161 | return false; |
| 162 | if (productDescription == null) { |
| 163 | if (other.productDescription != null) |
| 164 | return false; |
| 165 | } else if (!productDescription.equals(other.productDescription)) |
| 166 | return false; |
| 167 | if (region == null) { |
| 168 | if (other.region != null) |
| 169 | return false; |
| 170 | } else if (!region.equals(other.region)) |
| 171 | return false; |
| 172 | if (Float.floatToIntBits(usagePrice) != Float.floatToIntBits(other.usagePrice)) |
| 173 | return false; |
| 174 | return true; |
| 175 | } |
| 176 | |
| 177 | } |