001: package auction.model;
002:
003: import java.io.Serializable;
004: import java.math.BigDecimal;
005: import java.text.DateFormat;
006: import java.util.Date;
007: import java.util.Locale;
008:
009: public class Bid implements Serializable, Comparable {
010: private Long id = null;
011: private long amount;
012: private Book book;
013: private User bidder;
014: private Date created = new Date();
015: private boolean successful = false;
016:
017: private DateFormat dateFormat = DateFormat.getDateInstance(
018: DateFormat.LONG, Locale.ENGLISH);
019:
020: /**
021: * No-arg constructor for JavaBean tools
022: */
023: public Bid() {
024: }
025:
026: /**
027: * Full constructor
028: *
029: * @param amount
030: * @param item
031: * @param bidder
032: */
033:
034: public Bid(long amount, Book book, User bidder) {
035: this .amount = amount;
036: this .book = book;
037: this .bidder = bidder;
038: }
039:
040: // ********************** Accessor Methods ********************** //
041:
042: public Long getId() {
043: return id;
044: }
045:
046: public long getAmount() {
047: return amount;
048: }
049:
050: public String getAmountString() {
051: if (amount > 0)
052: return (String.valueOf(amount) + " eur");
053: else
054: return "";
055: }
056:
057: public Book getBook() {
058: return book;
059: }
060:
061: public User getBidder() {
062: return bidder;
063: }
064:
065: public Date getCreated() {
066: return created;
067: }
068:
069: public String getCreatedString() {
070: return dateFormat.format(created);
071: }
072:
073: public boolean isSuccessful() {
074: return successful;
075: }
076:
077: public void setSuccessful(boolean successful) {
078: this .successful = successful;
079: }
080:
081: // ********************** Common Methods ********************** //
082: public boolean equals(Object o) {
083: if (this == o)
084: return true;
085:
086: if (!(o instanceof Bid))
087: return false;
088: Bid bid = (Bid) o;
089: if (!getBook().getId().equals(bid.getBook().getId()))
090: return false;
091: if (!(created.getTime() == bid.created.getTime()))
092: return false;
093: if (amount != bid.amount)
094: return false;
095: return true;
096: }
097:
098: public int hashCode() {
099: int result;
100: result = (int) amount;
101: result = 29 * result + created.hashCode();
102: return result;
103: }
104:
105: public String toString() {
106: return "Bid ('" + getId() + "'), " + "Created: '"
107: + getCreated() + "' " + "Amount: '" + getAmount() + "'";
108: }
109:
110: public int compareTo(Object o) {
111: if (o instanceof Bid) {
112: return Long.valueOf(this .getCreated().getTime()).compareTo(
113: Long.valueOf((((Bid) o).getCreated().getTime())));
114: }
115: return 0;
116: }
117:
118: // ********************** Business Methods ********************** //
119:
120: }
|