001/*
002 * Copyright 2006-2014 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://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,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.batch.sample.domain.order;
018
019import java.math.BigDecimal;
020import java.util.Date;
021import java.util.List;
022
023public class Order {
024        public static final String LINE_ID_HEADER = "HEA";
025
026        public static final String LINE_ID_FOOTER = "FOT";
027
028        // header
029        private long orderId;
030
031        private Date orderDate;
032
033        // footer
034        private int totalLines;
035
036        private int totalItems;
037
038        private BigDecimal totalPrice;
039
040        private Customer customer;
041
042        private Address billingAddress;
043
044        private Address shippingAddress;
045
046        private BillingInfo billing;
047
048        private ShippingInfo shipping;
049
050        // order items
051        private List<LineItem> lineItems;
052
053        public BillingInfo getBilling() {
054                return billing;
055        }
056
057        public void setBilling(BillingInfo billing) {
058                this.billing = billing;
059        }
060
061        public Address getBillingAddress() {
062                return billingAddress;
063        }
064
065        public void setBillingAddress(Address billingAddress) {
066                this.billingAddress = billingAddress;
067        }
068
069        public Customer getCustomer() {
070                return customer;
071        }
072
073        public void setCustomer(Customer customer) {
074                this.customer = customer;
075        }
076
077        public List<LineItem> getLineItems() {
078                return lineItems;
079        }
080
081        public void setLineItems(List<LineItem> lineItems) {
082                this.lineItems = lineItems;
083        }
084
085        public Date getOrderDate() {
086                return orderDate;
087        }
088
089        public void setOrderDate(Date orderDate) {
090                this.orderDate = orderDate;
091        }
092
093        public long getOrderId() {
094                return orderId;
095        }
096
097        public void setOrderId(long orderId) {
098                this.orderId = orderId;
099        }
100
101        public ShippingInfo getShipping() {
102                return shipping;
103        }
104
105        public void setShipping(ShippingInfo shipping) {
106                this.shipping = shipping;
107        }
108
109        public Address getShippingAddress() {
110                return shippingAddress;
111        }
112
113        public void setShippingAddress(Address shippingAddress) {
114                this.shippingAddress = shippingAddress;
115        }
116
117        public BigDecimal getTotalPrice() {
118                return totalPrice;
119        }
120
121        public void setTotalPrice(BigDecimal totalPrice) {
122                this.totalPrice = totalPrice;
123        }
124
125        public int getTotalItems() {
126                return totalItems;
127        }
128
129        public void setTotalItems(int totalItems) {
130                this.totalItems = totalItems;
131        }
132
133        public int getTotalLines() {
134                return totalLines;
135        }
136
137        public void setTotalLines(int totalLines) {
138                this.totalLines = totalLines;
139        }
140
141        @Override
142        public String toString() {
143                return "Order [customer=" + customer + ", orderId=" + orderId + ", totalItems=" + totalItems + ", totalPrice="
144                                + totalPrice + "]";
145        }
146
147        @Override
148        public int hashCode() {
149                final int prime = 31;
150                int result = 1;
151                result = prime * result + ((billing == null) ? 0 : billing.hashCode());
152                result = prime * result + ((billingAddress == null) ? 0 : billingAddress.hashCode());
153                result = prime * result + ((customer == null) ? 0 : customer.hashCode());
154                result = prime * result + ((lineItems == null) ? 0 : lineItems.hashCode());
155                result = prime * result + ((orderDate == null) ? 0 : orderDate.hashCode());
156                result = prime * result + (int) (orderId ^ (orderId >>> 32));
157                result = prime * result + ((shipping == null) ? 0 : shipping.hashCode());
158                result = prime * result + ((shippingAddress == null) ? 0 : shippingAddress.hashCode());
159                result = prime * result + totalItems;
160                result = prime * result + totalLines;
161                result = prime * result + ((totalPrice == null) ? 0 : totalPrice.hashCode());
162                return result;
163        }
164
165        @Override
166        public boolean equals(Object obj) {
167                if (this == obj) {
168                        return true;
169                }
170                if (obj == null) {
171                        return false;
172                }
173                if (getClass() != obj.getClass()) {
174                        return false;
175                }
176                Order other = (Order) obj;
177                if (billing == null) {
178                        if (other.billing != null) {
179                                return false;
180                        }
181                }
182                else if (!billing.equals(other.billing)) {
183                        return false;
184                }
185                if (billingAddress == null) {
186                        if (other.billingAddress != null) {
187                                return false;
188                        }
189                }
190                else if (!billingAddress.equals(other.billingAddress)) {
191                        return false;
192                }
193                if (customer == null) {
194                        if (other.customer != null) {
195                                return false;
196                        }
197                }
198                else if (!customer.equals(other.customer)) {
199                        return false;
200                }
201                if (lineItems == null) {
202                        if (other.lineItems != null) {
203                                return false;
204                        }
205                }
206                else if (!lineItems.equals(other.lineItems)) {
207                        return false;
208                }
209                if (orderDate == null) {
210                        if (other.orderDate != null) {
211                                return false;
212                        }
213                }
214                else if (!orderDate.equals(other.orderDate)) {
215                        return false;
216                }
217                if (orderId != other.orderId) {
218                        return false;
219                }
220                if (shipping == null) {
221                        if (other.shipping != null) {
222                                return false;
223                        }
224                }
225                else if (!shipping.equals(other.shipping)) {
226                        return false;
227                }
228                if (shippingAddress == null) {
229                        if (other.shippingAddress != null) {
230                                return false;
231                        }
232                }
233                else if (!shippingAddress.equals(other.shippingAddress)) {
234                        return false;
235                }
236                if (totalItems != other.totalItems) {
237                        return false;
238                }
239                if (totalLines != other.totalLines) {
240                        return false;
241                }
242                if (totalPrice == null) {
243                        if (other.totalPrice != null) {
244                                return false;
245                        }
246                }
247                else if (!totalPrice.equals(other.totalPrice)) {
248                        return false;
249                }
250
251                return true;
252        }
253}