public class Trade implements Comparable<Trade>{
private long tradeId;
private String accountNo;
private int version;
private String security;
private long quantity;
private Direction direction;
private Operation operation;
public Trade(long tradeId, String accountNo, int version,
String security, long quantity, Direction direction,
Operation operation) {
this.tradeId = tradeId;
this.accountNo = accountNo;
this.version = version;
this.security = security;
this.quantity = quantity;
this.direction = direction;
this.operation = operation;
}
public boolean isBuy(){
return direction == Direction.BUY;
}
public boolean isSell(){
return direction == Direction.SELL;
}
public String getAccountNo() { return accountNo; }
public Direction getDirection() { return direction; }
public Operation getOperation() { return operation; }
public long getQuantity() { return quantity; }
public String getSecurity() { return security; }
public long getTradeId() { return tradeId; }
public int getVersion() { return version; }
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Trade other = (Trade) obj;
if (this.tradeId != other.tradeId) {
return false;
}
if ((this.accountNo == null) ? (other.accountNo != null)
: !this.accountNo.equals(other.accountNo)) {
return false;
}
if ((this.security == null) ? (other.security != null)
: !this.security.equals(other.security)) {
return false;
}
if (this.quantity != other.quantity) {
return false;
}
if (this.direction != other.direction) {
return false;
}
if (this.operation != other.operation) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 7;
hash = 37 hash + (int) (this.tradeId ^ (this.tradeId >>> 32));
hash = 37 hash + (this.accountNo != null ? this.accountNo.hashCode() : 0);
hash = 37 hash + (this.security != null ? this.security.hashCode() : 0);
hash = 37 hash + (int) (this.quantity ^ (this.quantity >>> 32));
hash = 37 hash + (this.operation != null ? this.operation.hashCode() : 0);
return hash;
}
@Override
public String toString() {
return "Trade{" + "tradeId=" + tradeId
+ ", accountNo=" + accountNo + ", version=" + version
+ ", security=" + security + ", quantity=" + quantity
+ ", direction=" + direction + ", operation=" + operation + '}';
}
@Override
public int compareTo(Trade o) {
if(this.tradeId == o.tradeId){
return this.version > o.version ? 1: (this.version < o.version? -1 : 0);
}else{
return this.tradeId > o.tradeId ? 1 : -1;
}
}
}