package edu.brown.cs.student.term.trade; import edu.brown.cs.student.term.hub.Holder; import java.util.Objects; public class Trade { private int id; private String stock; private int isBuy; private double timestamp; private Holder holder; private int numShares; private double price; public Trade(int id, String stockName, double ts, int buy, int shares, Holder holder, double price){ this.id = id; this.stock = stockName; this.isBuy = buy; this.timestamp = ts; this.holder = holder; this.numShares = shares; this.price = price; } public int getId() { return id; } public boolean isBuy() { if(isBuy == 1){ return true; } else { return false; } } public double getTimestamp() { return timestamp; } public String getStock() { return stock; } public Holder getHolder() { return holder; } public int getNumShares() { return numShares; } public double getPrice() { return price; } /** * This equals method differs from what may be expected, * it considers trades "equal" if they have the same buy value and stock name * because they are the same type of trade of the same stock in that case * @param o - object to compare to * @return true if equal by the considerations above */ @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Trade trade = (Trade) o; return isBuy == trade.isBuy && stock.equals(trade.stock); } @Override public int hashCode() { return Objects.hash(stock, isBuy); } @Override public String toString() { return "Trade{" + "id=" + id + ", stock='" + stock + '\'' + ", isBuy=" + isBuy + ", timestamp=" + timestamp + ", holder='" + holder + '\'' + ", numShares=" + numShares + '}'; } }