001/* 002 * Copyright 2010-2014 Ning, Inc. 003 * Copyright 2014-2015 The Billing Project, LLC 004 * 005 * The Billing Project licenses this file to you under the Apache License, version 2.0 006 * (the "License"); you may not use this file except in compliance with the 007 * License. You may obtain a copy of the License at: 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 014 * License for the specific language governing permissions and limitations 015 * under the License. 016 */ 017 018package com.ning.billing.recurly.model; 019 020import com.google.common.base.Objects; 021import org.joda.time.DateTime; 022 023import javax.xml.bind.annotation.XmlElement; 024import javax.xml.bind.annotation.XmlRootElement; 025 026/** 027 * Class that represents Delivery details in the Recurly API. 028 */ 029@XmlRootElement(name = "delivery") 030public class Delivery extends RecurlyObject { 031 032 @XmlElement(name = "address") 033 private Address address; 034 035 @XmlElement(name = "method") 036 private String method; 037 038 @XmlElement(name = "email_address") 039 private String emailAddress; 040 041 @XmlElement(name = "first_name") 042 private String firstName; 043 044 @XmlElement(name = "last_name") 045 private String lastName; 046 047 @XmlElement(name = "gifter_name") 048 private String gifterName; 049 050 @XmlElement(name = "personal_message") 051 private String personalMessage; 052 053 @XmlElement(name = "deliver_at") 054 private DateTime deliverAt; 055 056 public Address getAddress() { 057 return address; 058 } 059 060 public void setAddress(final Address address) { 061 this.address = address; 062 } 063 064 public String getEmailAddress() { 065 return emailAddress; 066 } 067 068 public void setEmailAddress(final Object emailAddress) { 069 this.emailAddress = stringOrNull(emailAddress); 070 } 071 072 public String getFirstName() { 073 return firstName; 074 } 075 076 public void setFirstName(final Object firstName) { 077 this.firstName = stringOrNull(firstName); 078 } 079 080 public String getLastName() { 081 return lastName; 082 } 083 084 public void setLastName(final Object lastName) { 085 this.lastName = stringOrNull(lastName); 086 } 087 088 public String getGifterName() { 089 return gifterName; 090 } 091 092 public void setGifterName(final Object gifterName) { 093 this.gifterName= stringOrNull(gifterName); 094 } 095 096 public String getPersonalMessage() { return personalMessage; } 097 098 public void setPersonalMessage(final Object personalMessage) { 099 this.personalMessage = stringOrNull(personalMessage); 100 } 101 102 public String getMethod() { 103 return method; 104 } 105 106 public void setMethod(final String method) { 107 this.method = method.toLowerCase(); 108 } 109 110 public DateTime getDeliverAt() { 111 return deliverAt; 112 } 113 114 public void setDeliverAt(final Object deliverAt) { 115 this.deliverAt = dateTimeOrNull(deliverAt); 116 } 117 118 @Override 119 public String toString() { 120 final StringBuilder sb = new StringBuilder(); 121 sb.append("Delivery"); 122 sb.append("{ address='").append(address).append('\''); 123 sb.append(", deliverAt='").append(deliverAt).append('\''); 124 sb.append(", emailAddress='").append(emailAddress).append('\''); 125 sb.append(", firstName='").append(firstName).append('\''); 126 sb.append(", gifterName='").append(gifterName).append('\''); 127 sb.append(", lastName='").append(lastName).append('\''); 128 sb.append(", method='").append(method).append('\''); 129 sb.append(", personalMessage='").append(personalMessage).append('\''); 130 sb.append('}'); 131 return sb.toString(); 132 } 133 134 @Override 135 public boolean equals(final Object o) { 136 if (this == o) return true; 137 if (o == null || getClass() != o.getClass()) return false; 138 139 final Delivery delivery = (Delivery) o; 140 141 if (address != null ? !address.equals(delivery.address) : delivery.address != null) { 142 return false; 143 } 144 if (deliverAt != null ? deliverAt.compareTo(delivery.deliverAt) != 0 : delivery.deliverAt != null) { 145 return false; 146 } 147 if (emailAddress != null ? !emailAddress.equals(delivery.emailAddress) : delivery.emailAddress != null) { 148 return false; 149 } 150 if (firstName != null ? !firstName.equals(delivery.firstName) : delivery.firstName != null) { 151 return false; 152 } 153 if (gifterName != null ? !gifterName.equals(delivery.gifterName) : delivery.gifterName != null) { 154 return false; 155 } 156 if (lastName != null ? !lastName.equals(delivery.lastName) : delivery.lastName != null) { 157 return false; 158 } 159 if (method != null ? !method.equals(delivery.method) : delivery.method != null) { 160 return false; 161 } 162 if (personalMessage != null ? !personalMessage.equals(delivery.personalMessage) : delivery.personalMessage != null) { 163 return false; 164 } 165 166 return true; 167 } 168 169 @Override 170 public int hashCode() { 171 return Objects.hashCode( 172 address, 173 deliverAt, 174 emailAddress, 175 firstName, 176 gifterName, 177 lastName, 178 method, 179 personalMessage 180 ); 181 } 182}