| 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 | |
| 24 | import java.util.Set; |
| 25 | |
| 26 | import static com.google.common.base.Preconditions.checkNotNull; |
| 27 | |
| 28 | /** |
| 29 | * The SoftLayer_Product_Package data type contains information about packages |
| 30 | * from which orders can be generated. Packages contain general information |
| 31 | * regarding what is in them, where they are currently sold, availability, and |
| 32 | * pricing. |
| 33 | * |
| 34 | * @author Adrian Cole |
| 35 | * @see <a href= |
| 36 | * "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Package" |
| 37 | * /> |
| 38 | */ |
| 39 | public class ProductPackage implements Comparable<ProductPackage> { |
| 40 | |
| 41 | // TODO there are more elements than this. |
| 42 | |
| 43 | public static Builder builder() { |
| 44 | return new Builder(); |
| 45 | } |
| 46 | |
| 47 | public static class Builder { |
| 48 | private int id = -1; |
| 49 | private String name; |
| 50 | private String description; |
| 51 | private Set<ProductItem> items = Sets.newLinkedHashSet(); |
| 52 | private Set<Datacenter> datacenters = Sets.newLinkedHashSet(); |
| 53 | |
| 54 | public Builder id(int id) { |
| 55 | this.id = id; |
| 56 | return this; |
| 57 | } |
| 58 | |
| 59 | public Builder name(String name) { |
| 60 | this.name = name; |
| 61 | return this; |
| 62 | } |
| 63 | |
| 64 | public Builder description(String description) { |
| 65 | this.description = description; |
| 66 | return this; |
| 67 | } |
| 68 | |
| 69 | public Builder items(Iterable<ProductItem> items) { |
| 70 | this.items = ImmutableSet.<ProductItem> copyOf(checkNotNull(items, "items")); |
| 71 | return this; |
| 72 | } |
| 73 | |
| 74 | public Builder datacenters(Iterable<Datacenter> datacenters) { |
| 75 | this.datacenters = ImmutableSet.<Datacenter> copyOf(checkNotNull(datacenters, "datacenters")); |
| 76 | return this; |
| 77 | } |
| 78 | |
| 79 | public ProductPackage build() { |
| 80 | return new ProductPackage(id, name, description, items, datacenters); |
| 81 | } |
| 82 | |
| 83 | public static Builder fromProductPackage(ProductPackage in) { |
| 84 | return ProductPackage.builder().id(in.getId()) |
| 85 | .name(in.getName()) |
| 86 | .description(in.getDescription()) |
| 87 | .items(in.getItems()) |
| 88 | .datacenters(in.getDatacenters()); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | private int id = -1; |
| 93 | private String name; |
| 94 | private String description; |
| 95 | private Set<ProductItem> items = Sets.newLinkedHashSet(); |
| 96 | private Set<Datacenter> locations = Sets.newLinkedHashSet(); |
| 97 | |
| 98 | // for deserializer |
| 99 | ProductPackage() { |
| 100 | |
| 101 | } |
| 102 | |
| 103 | public ProductPackage(int id, String name, String description, Iterable<ProductItem> items, Iterable<Datacenter> datacenters) { |
| 104 | this.id = id; |
| 105 | this.name = name; |
| 106 | this.description = description; |
| 107 | this.items = ImmutableSet.<ProductItem> copyOf(checkNotNull(items, "items")); |
| 108 | this.locations = ImmutableSet.<Datacenter> copyOf(checkNotNull(datacenters, "datacenters")); |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public int compareTo(ProductPackage arg0) { |
| 113 | return new Integer(id).compareTo(arg0.getId()); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * @return A package's internal identifier. Everything regarding a |
| 118 | * SoftLayer_Product_Package is tied back to this id. |
| 119 | */ |
| 120 | public int getId() { |
| 121 | return id; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * @return The description of the package. For server packages, this is |
| 126 | * usually a detailed description of processor type and count. |
| 127 | */ |
| 128 | public String getName() { |
| 129 | return name; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * @return A generic description of the processor type and count. This |
| 134 | * includes HTML, so you may want to strip these tags if you plan to |
| 135 | * use it. |
| 136 | */ |
| 137 | public String getDescription() { |
| 138 | return description; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * |
| 143 | * @return A collection of valid items available for purchase in this |
| 144 | * package. |
| 145 | */ |
| 146 | public Set<ProductItem> getItems() { |
| 147 | return items; |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * |
| 152 | * @return A collection of valid locations for this package. |
| 153 | */ |
| 154 | public Set<Datacenter> getDatacenters() { |
| 155 | return locations; |
| 156 | } |
| 157 | |
| 158 | public Builder toBuilder() { |
| 159 | return Builder.fromProductPackage(this); |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public int hashCode() { |
| 164 | final int prime = 31; |
| 165 | int result = 1; |
| 166 | result = prime * result + (id ^ (id >>> 32)); |
| 167 | return result; |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public boolean equals(Object obj) { |
| 172 | if (this == obj) |
| 173 | return true; |
| 174 | if (obj == null) |
| 175 | return false; |
| 176 | if (getClass() != obj.getClass()) |
| 177 | return false; |
| 178 | ProductPackage other = (ProductPackage) obj; |
| 179 | if (id != other.id) |
| 180 | return false; |
| 181 | return true; |
| 182 | } |
| 183 | |
| 184 | @Override |
| 185 | public String toString() { |
| 186 | return "ProductPackage [id=" + id + ", name=" + name + ", description=" + description + ", items=" + items + ", datacenters=" + locations + "]"; |
| 187 | } |
| 188 | } |