| 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 | /** |
| 22 | * |
| 23 | * @author Jason King |
| 24 | * @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Receipt" |
| 25 | * /> |
| 26 | */ |
| 27 | public class ProductOrderReceipt implements Comparable<ProductOrderReceipt> { |
| 28 | public static Builder builder() { |
| 29 | return new Builder(); |
| 30 | } |
| 31 | |
| 32 | public static class Builder { |
| 33 | private int orderId = -1; |
| 34 | private ProductOrder orderDetails; |
| 35 | |
| 36 | public Builder orderId(int orderId) { |
| 37 | this.orderId = orderId; |
| 38 | return this; |
| 39 | } |
| 40 | |
| 41 | public Builder orderDetails(ProductOrder orderDetails) { |
| 42 | this.orderDetails = orderDetails; |
| 43 | return this; |
| 44 | } |
| 45 | |
| 46 | public ProductOrderReceipt build() { |
| 47 | return new ProductOrderReceipt(orderId,orderDetails); |
| 48 | } |
| 49 | |
| 50 | public static Builder fromAddress(ProductOrderReceipt in) { |
| 51 | return ProductOrderReceipt.builder().orderId(in.getOrderId()).orderDetails(in.getOrderDetails()); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | private int orderId = -1; |
| 56 | private ProductOrder orderDetails; |
| 57 | |
| 58 | // for deserializer |
| 59 | ProductOrderReceipt() { |
| 60 | |
| 61 | } |
| 62 | |
| 63 | public ProductOrderReceipt(int orderId,ProductOrder orderDetails) { |
| 64 | this.orderId = orderId; |
| 65 | this.orderDetails = orderDetails; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public int compareTo(ProductOrderReceipt arg0) { |
| 70 | return new Integer(orderId).compareTo(arg0.getOrderId()); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @return unique identifier for the order. |
| 75 | */ |
| 76 | public int getOrderId() { |
| 77 | return orderId; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * This is a copy of the SoftLayer_Container_Product_Order |
| 82 | * which holds all the data related to an order. |
| 83 | * This will only return when an order is processed successfully. |
| 84 | * It will contain all the items in an order as well as the order totals. |
| 85 | */ |
| 86 | public ProductOrder getOrderDetails() { |
| 87 | return orderDetails; |
| 88 | } |
| 89 | |
| 90 | public Builder toBuilder() { |
| 91 | return Builder.fromAddress(this); |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public int hashCode() { |
| 96 | final int prime = 31; |
| 97 | int result = 1; |
| 98 | result = prime * result + (orderId ^ (orderId >>> 32)); |
| 99 | return result; |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public boolean equals(Object obj) { |
| 104 | if (this == obj) |
| 105 | return true; |
| 106 | if (obj == null) |
| 107 | return false; |
| 108 | if (getClass() != obj.getClass()) |
| 109 | return false; |
| 110 | ProductOrderReceipt other = (ProductOrderReceipt) obj; |
| 111 | if (orderId != other.orderId) |
| 112 | return false; |
| 113 | return true; |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public String toString() { |
| 118 | return "[orderId=" + orderId + ", orderDetails="+orderDetails+"]"; |
| 119 | } |
| 120 | |
| 121 | |
| 122 | } |