| 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.softlayer.domain; |
| 20 | |
| 21 | import com.google.common.collect.ImmutableSet; |
| 22 | import com.google.common.collect.Sets; |
| 23 | import org.jclouds.javax.annotation.Nullable; |
| 24 | |
| 25 | import java.util.Set; |
| 26 | |
| 27 | import static com.google.common.base.Preconditions.checkNotNull; |
| 28 | |
| 29 | /** |
| 30 | * The SoftLayer_Product_Item_Price data type contains general information |
| 31 | * relating to a single SoftLayer product item price. You can find out what |
| 32 | * packages each price is in as well as which category under which this price is |
| 33 | * sold. All prices are returned in Floating point values measured in US Dollars |
| 34 | * ($USD). |
| 35 | * |
| 36 | * @author Adrian Cole |
| 37 | * @see <a href= |
| 38 | * "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Price" |
| 39 | * /> |
| 40 | */ |
| 41 | public class ProductItemPrice implements Comparable<ProductItemPrice> { |
| 42 | // TODO there are more elements than this. |
| 43 | |
| 44 | public static Builder builder() { |
| 45 | return new Builder(); |
| 46 | } |
| 47 | |
| 48 | public static class Builder { |
| 49 | private int id = -1; |
| 50 | private long itemId = -1; |
| 51 | private Float recurringFee; |
| 52 | private Float hourlyRecurringFee; |
| 53 | private ProductItem item; |
| 54 | private Set<ProductItemCategory> categories = Sets.newLinkedHashSet(); |
| 55 | |
| 56 | public Builder id(int id) { |
| 57 | this.id = id; |
| 58 | return this; |
| 59 | } |
| 60 | |
| 61 | public Builder itemId(long itemId) { |
| 62 | this.itemId = itemId; |
| 63 | return this; |
| 64 | } |
| 65 | |
| 66 | public Builder recurringFee(Float recurringFee) { |
| 67 | this.recurringFee = recurringFee; |
| 68 | return this; |
| 69 | } |
| 70 | |
| 71 | public Builder hourlyRecurringFee(Float hourlyRecurringFee) { |
| 72 | this.hourlyRecurringFee = hourlyRecurringFee; |
| 73 | return this; |
| 74 | } |
| 75 | |
| 76 | public Builder item(ProductItem item) { |
| 77 | this.item = item; |
| 78 | return this; |
| 79 | } |
| 80 | |
| 81 | public Builder category(ProductItemCategory categories) { |
| 82 | this.categories.add(checkNotNull(categories, "categories")); |
| 83 | return this; |
| 84 | } |
| 85 | |
| 86 | public Builder categories(Iterable<ProductItemCategory> categories) { |
| 87 | this.categories = ImmutableSet.<ProductItemCategory> copyOf(checkNotNull(categories, "categories")); |
| 88 | return this; |
| 89 | } |
| 90 | |
| 91 | public ProductItemPrice build() { |
| 92 | return new ProductItemPrice(id, itemId, recurringFee, hourlyRecurringFee, item, categories); |
| 93 | } |
| 94 | |
| 95 | public static Builder fromPrice(ProductItemPrice in) { |
| 96 | return ProductItemPrice.builder().id(in.getId()).itemId(in.getItemId()) |
| 97 | .hourlyRecurringFee(in.getHourlyRecurringFee()).recurringFee(in.getRecurringFee()); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | private int id = -1; |
| 102 | private long itemId = -1; |
| 103 | private Float recurringFee; |
| 104 | private Float hourlyRecurringFee; |
| 105 | private ProductItem item; |
| 106 | private Set<ProductItemCategory> categories = Sets.newLinkedHashSet(); |
| 107 | |
| 108 | // for deserializer |
| 109 | ProductItemPrice() { |
| 110 | |
| 111 | } |
| 112 | |
| 113 | public ProductItemPrice(int id, long itemId, Float recurringFee, Float hourlyRecurringFee, ProductItem item, Iterable<ProductItemCategory> categories) { |
| 114 | this.id = id; |
| 115 | this.itemId = itemId; |
| 116 | this.recurringFee = recurringFee; |
| 117 | this.hourlyRecurringFee = hourlyRecurringFee; |
| 118 | this.item = item; |
| 119 | this.categories = ImmutableSet.<ProductItemCategory> copyOf(checkNotNull(categories, "categories")); |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public int compareTo(ProductItemPrice arg0) { |
| 124 | return new Integer(id).compareTo(arg0.getId()); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * @return The unique identifier of a Product Item Price. |
| 129 | */ |
| 130 | public int getId() { |
| 131 | return id; |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * @return The unique identifier for a product Item |
| 136 | */ |
| 137 | public long getItemId() { |
| 138 | return itemId; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * @return A recurring fee is a fee that happens every billing period. This |
| 143 | * fee is represented as a Floating point decimal in US dollars |
| 144 | * ($USD). |
| 145 | */ |
| 146 | @Nullable |
| 147 | public Float getRecurringFee() { |
| 148 | return recurringFee; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * @return The hourly price for this item, should this item be part of an |
| 153 | * hourly pricing package. |
| 154 | */ |
| 155 | @Nullable |
| 156 | public Float getHourlyRecurringFee() { |
| 157 | return hourlyRecurringFee; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * |
| 162 | * @return An item's associated item categories. |
| 163 | */ |
| 164 | public Set<ProductItemCategory> getCategories() { |
| 165 | return categories; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * @return The product item a price is tied to. |
| 170 | */ |
| 171 | public ProductItem getItem() { |
| 172 | return item; |
| 173 | } |
| 174 | |
| 175 | public Builder toBuilder() { |
| 176 | return Builder.fromPrice(this); |
| 177 | } |
| 178 | |
| 179 | @Override |
| 180 | public String toString() { |
| 181 | return "[id=" + id + ", itemId=" + itemId + ", recurringFee=" + recurringFee + ", hourlyRecurringFee=" |
| 182 | + hourlyRecurringFee + ", item="+item+", categories="+categories+"]"; |
| 183 | } |
| 184 | |
| 185 | @Override |
| 186 | public boolean equals(Object o) { |
| 187 | if (this == o) return true; |
| 188 | if (o == null || getClass() != o.getClass()) return false; |
| 189 | |
| 190 | ProductItemPrice that = (ProductItemPrice) o; |
| 191 | |
| 192 | if (id != that.id) return false; |
| 193 | |
| 194 | return true; |
| 195 | } |
| 196 | |
| 197 | @Override |
| 198 | public int hashCode() { |
| 199 | return (id ^ (id >>> 32)); |
| 200 | } |
| 201 | } |