package se.ginkou; import org.joda.time.DateTime; public class Transaction { // Unique id of the transaction. This is generated by the database and thus does only // exist on transactions loaded from the database. 0 represents no SQLid. private int SQLid; private Account account; private DateTime date; private String notice; // private String category; private double amount; public Transaction(int SQLid, Account account, DateTime date, String notice, double amount) { this.account = account; this.date = date; this.notice = notice; this.amount = amount; this.SQLid = SQLid; } public Transaction(Account account, DateTime date, String notice, double amount) { this(0, account, date, notice, amount); } public int getId() { return SQLid; } public Account getAccount() { return account; } public DateTime getDate() { return date; } public String getNotice() { return notice; } // public String getCategory() { // return category; // } public double getAmount() { return amount; } // public long getFlags() { // // TODO determine flags // } /** * Returns a json representation of the transaction. */ public String toJSON() { return "{" + "\"id\"=\"" + SQLid + "\", " + "\"account\"=\"" + account.getNumber() + "\", " + "\"date\"=\"" + date.toString("yyyy-MM-dd") + "\", " + "\"notice\"=\"" + notice + "\", " + "\"amount\"=\"" + amount + "\"" + "}"; } @Override public String toString() { return this.toJSON(); } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((account == null) ? 0 : account.hashCode()); long temp; temp = Double.doubleToLongBits(amount); result = prime * result + (int) (temp ^ (temp >>> 32)); result = prime * result + ((date == null) ? 0 : date.hashCode()); result = prime * result + SQLid; result = prime * result + ((notice == null) ? 0 : notice.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Transaction other = (Transaction) obj; if (account == null) { if (other.account != null) return false; } else if (!account.equals(other.account)) return false; if (Double.doubleToLongBits(amount) != Double .doubleToLongBits(other.amount)) return false; if (date == null) { if (other.date != null) return false; } else if (!date.equals(other.date)) return false; if (notice == null) { if (other.notice != null) return false; } else if (!notice.equals(other.notice)) return false; return true; } }