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 */ 017package com.ning.billing.recurly.model; 018 019import com.google.common.base.Objects; 020import org.joda.time.DateTime; 021import java.math.BigDecimal; 022 023import javax.xml.bind.annotation.XmlElement; 024import javax.xml.bind.annotation.XmlRootElement; 025import javax.xml.bind.annotation.XmlTransient; 026 027 028@XmlRootElement(name = "usage") 029public class Usage extends RecurlyObject{ 030 031 @XmlTransient 032 public static final String USAGE_RESOURCE = "/usage"; 033 034 @XmlElement(name = "amount") 035 protected Integer amount; 036 037 @XmlElement(name = "merchant_tag") 038 private String merchantTag; 039 040 @XmlElement(name = "recording_timestamp") 041 private DateTime recordingAt; 042 043 @XmlElement(name = "usage_timestamp") 044 private DateTime usageAt; 045 046 @XmlElement(name = "created_at") 047 private DateTime createdAt; 048 049 @XmlElement(name = "updated_at") 050 private DateTime updatedAt; 051 052 @XmlElement(name = "billed_at") 053 private DateTime billedAt; 054 055 @XmlElement(name = "usage_type") 056 private String usageType; 057 058 @XmlElement(name = "unit_amount_in_cents") 059 protected Integer unitAmountInCents; 060 061 @XmlElement(name = "usage_percentage") 062 private BigDecimal usagePercentage; 063 064 @Override 065 public String toString() { 066 return "Usage{" + 067 "amount=" + amount + 068 ", merchantTag='" + merchantTag + '\'' + 069 ", recordingAt=" + recordingAt + 070 ", usageAt=" + usageAt + 071 ", createdAt=" + createdAt + 072 ", updatedAt=" + updatedAt + 073 ", billedAt=" + billedAt + 074 ", usageType='" + usageType + '\'' + 075 ", unitAmountInCents=" + unitAmountInCents + 076 ", usagePercentage=" + usagePercentage + 077 '}'; 078 } 079 080 @Override 081 public boolean equals(Object o) { 082 if (this == o) return true; 083 if (o == null || getClass() != o.getClass()) return false; 084 085 Usage usage = (Usage) o; 086 087 if (!amount.equals(usage.amount)) return false; 088 if (merchantTag != null ? !merchantTag.equals(usage.merchantTag) : usage.merchantTag != null) return false; 089 if (recordingAt != null ? recordingAt.compareTo(usage.recordingAt) != 0 : usage.recordingAt != null) return false; 090 if (!usageAt.equals(usage.usageAt)) return false; 091 if (createdAt != null ? createdAt.compareTo(usage.createdAt) != 0 : usage.createdAt != null) return false; 092 if (updatedAt != null ? updatedAt.compareTo(usage.updatedAt) != 0 : usage.updatedAt != null) return false; 093 if (billedAt != null ? billedAt.compareTo(usage.billedAt) != 0 : usage.billedAt != null) return false; 094 if (usageType != null ? !usageType.equals(usage.usageType) : usage.usageType != null) return false; 095 if (unitAmountInCents != null ? !unitAmountInCents.equals(usage.unitAmountInCents) : usage.unitAmountInCents != null) 096 return false; 097 return usagePercentage != null ? usagePercentage.equals(usage.usagePercentage) : usage.usagePercentage == null; 098 } 099 100 @Override 101 public int hashCode() { 102 return Objects.hashCode( 103 amount, 104 merchantTag, 105 recordingAt, 106 usageAt, 107 createdAt, 108 updatedAt, 109 billedAt, 110 usageType, 111 unitAmountInCents, 112 usagePercentage 113 ); 114 } 115 116 public Integer getAmount() { 117 return amount; 118 } 119 120 public void setAmount(final Object amount) { 121 this.amount = integerOrNull(amount); 122 } 123 124 public String getMerchantTag() { 125 return merchantTag; 126 } 127 128 public void setMerchantTag(final Object merchantTag) { 129 this.merchantTag = stringOrNull(merchantTag); 130 } 131 132 public DateTime getRecordingAt() { 133 return recordingAt; 134 } 135 136 public void setRecordingAt(final Object recordingAt) { 137 this.recordingAt = dateTimeOrNull(recordingAt); 138 } 139 140 public DateTime getUsageAt() { 141 return usageAt; 142 } 143 144 public void setUsageAt(final Object usageAt) { 145 this.usageAt = dateTimeOrNull(usageAt); 146 } 147 148 public DateTime getCreatedAt() { 149 return createdAt; 150 } 151 152 public void setCreatedAt(final Object createdAt) { 153 this.createdAt = dateTimeOrNull(createdAt); 154 } 155 156 public DateTime getUpdatedAt() { 157 return updatedAt; 158 } 159 160 public void setUpdatedAt(final Object updatedAt) { 161 this.updatedAt = dateTimeOrNull(updatedAt); 162 } 163 164 public DateTime getBilledAt() { 165 return billedAt; 166 } 167 168 public void setBilledAt(final Object billedAt) { 169 this.billedAt = dateTimeOrNull(billedAt); 170 } 171 172 public String getUsageType() { 173 return usageType; 174 } 175 176 public void setUsageType(final Object usageType) { 177 this.usageType = stringOrNull(usageType); 178 } 179 180 public Integer getUnitAmountInCents() { 181 return unitAmountInCents; 182 } 183 184 public void setUnitAmountInCents(final Object unitAmountInCents) { 185 this.unitAmountInCents = integerOrNull(unitAmountInCents); 186 } 187 188 public BigDecimal getUsagePercentage() { 189 return usagePercentage; 190 } 191 192 public void setUsagePercentage(final Object usagePercentage) { 193 this.usagePercentage = bigDecimalOrNull(usagePercentage); 194 } 195}