View Javadoc

1   /*
2    * Copyright 2006-2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.batch.sample.domain.trade;
18  
19  import java.math.BigDecimal;
20  
21  import javax.persistence.Entity;
22  import javax.persistence.Id;
23  import javax.persistence.Table;
24  
25  @Entity
26  @Table(name = "CUSTOMER")
27  public class CustomerCredit {
28  
29  	@Id
30  	private int id;
31  
32  	private String name;
33  
34  	private BigDecimal credit;
35  
36  	public CustomerCredit() {
37  	}
38  
39  	public CustomerCredit(int id, String name, BigDecimal credit) {
40  		this.id = id;
41  		this.name = name;
42  		this.credit = credit;
43  	}
44  
45  	public String toString() {
46  		return "CustomerCredit [id=" + id + ",name=" + name + ", credit=" + credit + "]";
47  	}
48  
49  	public BigDecimal getCredit() {
50  		return credit;
51  	}
52  
53  	public int getId() {
54  		return id;
55  	}
56  
57  	public void setId(int id) {
58  		this.id = id;
59  	}
60  
61  	public void setCredit(BigDecimal credit) {
62  		this.credit = credit;
63  	}
64  
65  	public String getName() {
66  		return name;
67  	}
68  
69  	public void setName(String name) {
70  		this.name = name;
71  	}
72  
73  	public CustomerCredit increaseCreditBy(BigDecimal sum) {
74  		CustomerCredit newCredit = new CustomerCredit();
75  		newCredit.credit = this.credit.add(sum);
76  		newCredit.name = this.name;
77  		newCredit.id = this.id;
78  		return newCredit;
79  	}
80  
81  	public boolean equals(Object o) {
82  		return (o instanceof CustomerCredit) && ((CustomerCredit) o).id == id;
83  	}
84  
85  	public int hashCode() {
86  		return id;
87  	}
88  
89  }