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.trade;
018
019import java.io.Serializable;
020import java.math.BigDecimal;
021
022
023/**
024 * @author Rob Harrop
025 * @author Dave Syer
026 */
027@SuppressWarnings("serial")
028public class Trade implements Serializable {
029    private String isin = "";
030    private long quantity = 0;
031    private BigDecimal price = BigDecimal.ZERO;
032    private String customer = "";
033        private Long id;
034        private long version = 0;
035
036    public Trade() {
037    }
038    
039    public Trade(String isin, long quantity, BigDecimal price, String customer){
040        this.isin = isin;
041        this.quantity = quantity;
042        this.price = price;
043        this.customer = customer;
044    }
045
046    /**
047         * @param id id of the trade
048         */
049        public Trade(long id) {
050                this.id = id;
051        }
052        
053        public long getId() {
054                return id;
055        }
056        
057        public void setId(long id) {
058                this.id = id;
059        }
060
061        public long getVersion() {
062                return version;
063        }
064
065        public void setVersion(long version) {
066                this.version = version;
067        }
068
069        public void setCustomer(String customer) {
070                this.customer = customer;
071        }
072
073        public void setIsin(String isin) {
074                this.isin = isin;
075        }
076
077        public void setPrice(BigDecimal price) {
078                this.price = price;
079        }
080
081        public void setQuantity(long quantity) {
082                this.quantity = quantity;
083        }
084
085        public String getIsin() {
086        return isin;
087    }
088
089    public BigDecimal getPrice() {
090        return price;
091    }
092
093    public long getQuantity() {
094        return quantity;
095    }
096
097    public String getCustomer() {
098        return customer;
099    }
100
101    @Override
102        public String toString() {
103        return "Trade: [isin=" + this.isin + ",quantity=" + this.quantity + ",price="
104            + this.price + ",customer=" + this.customer + "]";
105    }
106
107        @Override
108        public int hashCode() {
109                final int prime = 31;
110                int result = 1;
111                result = prime * result + ((customer == null) ? 0 : customer.hashCode());
112                result = prime * result + ((isin == null) ? 0 : isin.hashCode());
113                result = prime * result + ((price == null) ? 0 : price.hashCode());
114                result = prime * result + (int) (quantity ^ (quantity >>> 32));
115                result = prime * result + (int) (version ^ (version >>> 32));
116                return result;
117        }
118
119        @Override
120        public boolean equals(Object obj) {
121                if (this == obj) {
122                        return true;
123                }
124                if (obj == null) {
125                        return false;
126                }
127                if (getClass() != obj.getClass()) {
128                        return false;
129                }
130                Trade other = (Trade) obj;
131                if (customer == null) {
132                        if (other.customer != null) {
133                                return false;
134                        }
135                }
136                else if (!customer.equals(other.customer)) {
137                        return false;
138                }
139                if (isin == null) {
140                        if (other.isin != null) {
141                                return false;
142                        }
143                }
144                else if (!isin.equals(other.isin)) {
145                        return false;
146                }
147                if (price == null) {
148                        if (other.price != null) {
149                                return false;
150                        }
151                }
152                else if (!price.equals(other.price)) {
153                        return false;
154                }
155                if (quantity != other.quantity) {
156                        return false;
157                }
158                if (version != other.version) {
159                        return false;
160                }
161                return true;
162        }
163 }