001/*
002 * Copyright 2010-2013 Ning, Inc.
003 *
004 * Ning licenses this file to you under the Apache License, version 2.0
005 * (the "License"); you may not use this file except in compliance with the
006 * License.  You may obtain a copy of the License at:
007 *
008 *    http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
013 * License for the specific language governing permissions and limitations
014 * under the License.
015 */
016
017package com.ning.billing.recurly.model;
018
019import javax.xml.bind.annotation.XmlElement;
020import javax.xml.bind.annotation.XmlElementWrapper;
021import javax.xml.bind.annotation.XmlRootElement;
022
023@XmlRootElement(name = "subscription")
024public class AbstractSubscription extends RecurlyObject {
025
026    public static final String SUBSCRIPTION_RESOURCE = "/subscriptions";
027
028    @XmlElement(name = "unit_amount_in_cents")
029    protected Integer unitAmountInCents;
030
031    @XmlElement(name = "quantity")
032    protected Integer quantity;
033
034    @XmlElementWrapper(name = "subscription_add_ons")
035    @XmlElement(name = "subscription_add_on")
036    protected SubscriptionAddOns addOns;
037
038    @XmlElement(name = "plan_code")
039    private String planCode;
040
041    public String getPlanCode() {
042        return planCode;
043    }
044
045    public void setPlanCode(final String planCode) {
046        this.planCode = stringOrNull(planCode);
047    }
048
049    public Integer getUnitAmountInCents() {
050        return unitAmountInCents;
051    }
052
053    public void setUnitAmountInCents(final Object unitAmountInCents) {
054        this.unitAmountInCents = integerOrNull(unitAmountInCents);
055    }
056
057    public Integer getQuantity() {
058        return quantity;
059    }
060
061    public void setQuantity(final Object quantity) {
062        this.quantity = integerOrNull(quantity);
063    }
064
065    public SubscriptionAddOns getAddOns() {
066        return addOns;
067    }
068
069    public void setAddOns(final SubscriptionAddOns addOns) {
070        this.addOns = addOns;
071    }
072
073    @Override
074    public boolean equals(final Object o) {
075        if (this == o) {
076            return true;
077        }
078        if (!(o instanceof AbstractSubscription)) {
079            return false;
080        }
081
082        final AbstractSubscription that = (AbstractSubscription) o;
083
084        if (addOns != null ? !addOns.equals(that.addOns) : that.addOns != null) {
085            return false;
086        }
087        if (planCode != null ? !planCode.equals(that.planCode) : that.planCode != null) {
088            return false;
089        }
090        if (quantity != null ? !quantity.equals(that.quantity) : that.quantity != null) {
091            return false;
092        }
093        if (unitAmountInCents != null ? !unitAmountInCents.equals(that.unitAmountInCents) : that.unitAmountInCents != null) {
094            return false;
095        }
096
097        return true;
098    }
099
100    @Override
101    public int hashCode() {
102        int result = unitAmountInCents != null ? unitAmountInCents.hashCode() : 0;
103        result = 31 * result + (quantity != null ? quantity.hashCode() : 0);
104        result = 31 * result + (addOns != null ? addOns.hashCode() : 0);
105        result = 31 * result + (planCode != null ? planCode.hashCode() : 0);
106        return result;
107    }
108}