001: package org.springunit.framework.samples.jpetstore.domain;
002:
003: import org.apache.commons.lang.builder.CompareToBuilder;
004: import org.apache.commons.lang.builder.EqualsBuilder;
005: import org.apache.commons.lang.builder.HashCodeBuilder;
006: import org.apache.commons.lang.builder.ToStringBuilder;
007: import org.apache.commons.lang.builder.ToStringStyle;
008:
009: public class LineItem extends Persistable {
010:
011: public LineItem() {
012: }
013:
014: public LineItem(int lineNumber, CartItem cartItem) {
015: this .lineNumber = lineNumber;
016: this .quantity = cartItem.getQuantity();
017: this .unitPrice = cartItem.getItem().getListPrice();
018: this .item = cartItem.getItem();
019: }
020:
021: public Item getItem() {
022: return this .item;
023: }
024:
025: public int getLineNumber() {
026: return this .lineNumber;
027: }
028:
029: public Order getOrder() {
030: return this .order;
031: }
032:
033: public int getQuantity() {
034: return this .quantity;
035: }
036:
037: public double getUnitPrice() {
038: return this .unitPrice;
039: }
040:
041: public void setItem(Item item) {
042: this .item = item;
043: }
044:
045: public void setLineNumber(int lineNumber) {
046: this .lineNumber = lineNumber;
047: }
048:
049: public void setOrder(Order order) {
050: this .order = order;
051: }
052:
053: public void setQuantity(int quantity) {
054: this .quantity = quantity;
055: }
056:
057: public void setUnitPrice(double unitPrice) {
058: this .unitPrice = unitPrice;
059: }
060:
061: public double getTotalPrice() {
062: return this .unitPrice * this .quantity;
063: }
064:
065: public int compareTo(Object that) {
066: LineItem other = (LineItem) that;
067: return new CompareToBuilder().append(getLineNumber(),
068: other.getLineNumber()).append(getOrder().getId(),
069: other.getOrder().getId()).toComparison();
070: }
071:
072: public boolean equals(Object that) {
073: if (this == that) {
074: return true;
075: }
076: if (!(that instanceof LineItem)) {
077: return false;
078: }
079: LineItem other = (LineItem) that;
080: return new EqualsBuilder().append(getLineNumber(),
081: other.getLineNumber()).append(getOrder().getId(),
082: other.getOrder().getId()).isEquals();
083: }
084:
085: public int hashCode() {
086: return new HashCodeBuilder(PRIME, MULTIPLIER).append(
087: getLineNumber()).append(getOrder().getId())
088: .toHashCode();
089: }
090:
091: public String toString() {
092: return new ToStringBuilder(this , ToStringStyle.MULTI_LINE_STYLE)
093: .appendSuper(super .toString()).append("unitPrice",
094: getUnitPrice()).append("lineNumber",
095: getLineNumber()).append("quantity",
096: getQuantity()).toString();
097: }
098:
099: private static final long serialVersionUID = 5L;
100:
101: private Order order;
102: private int lineNumber;
103: private int quantity;
104: private double unitPrice;
105: private Item item;
106:
107: }
|