001 /**
002 * Copyright 2007 Mike Kroutikov.
003 *
004 * This program is free software; you can redistribute it and/or modify
005 * it under the terms of the Lesser GNU General Public License as
006 * published by the Free Software Foundation; either version 3 of
007 * the License, or (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012 * Lesser GNU General Public License for more details.
013 *
014 * You should have received a copy of the Lesser GNU General Public License
015 * along with this program. If not, see <http://www.gnu.org/licenses/>.
016 *
017 * Derived from code developed by Opentick Corporation, http://www.opentick.com.
018 */
019
020 package org.otfeed.event;
021
022 import static org.otfeed.event.IdentityUtil.equalsTo;
023 import static org.otfeed.event.IdentityUtil.safeCompare;
024 import static org.otfeed.event.IdentityUtil.safeHashCode;
025
026 import java.io.Serializable;
027 import java.util.Date;
028
029 /**
030 * Look up the order, and change its size.
031 * If the order is not there, create it, setting the symbol price and size.
032 */
033 public final class OTBookReplace implements Comparable<OTBookReplace>, Serializable {
034
035 private static final long serialVersionUID = 6500191194223899665L;
036
037 private Date timestamp;
038 private String reference;
039 private double price;
040 private int size;
041 private TradeSideEnum side;
042
043 /**
044 * Default constructor.
045 */
046 public OTBookReplace() { }
047
048 /**
049 * Constructor.
050 * @param timestamp Time when the event occurred.
051 * @param reference Order reference.
052 * @param price Price.
053 * @param size Number of shares.
054 * @param side Side: B = Buy, S = Sell.
055 */
056 public OTBookReplace(Date timestamp, String reference,
057 double price, int size, TradeSideEnum side) {
058 this.timestamp = timestamp;
059 this.reference = reference;
060 this.price = price;
061 this.size = size;
062 this.side = side;
063 }
064
065 /**
066 *
067 * @return Time when the event occurred.
068 */
069 public Date getTimestamp() {
070 return timestamp;
071 }
072
073 /**
074 * Sets time of the event.
075 * @param timestamp Time when the event occurred.
076 */
077 public void setTimestamp(Date timestamp) {
078 this.timestamp = timestamp;
079 }
080
081 /**
082 *
083 * @return Order reference; identifies the order for subsequent events.
084 */
085 public String getOrderRef() {
086 return reference;
087 }
088
089 /**
090 * Sets Order reference.
091 * @param reference Order reference.
092 */
093 public void setReference(String reference) {
094 this.reference = reference;
095 }
096
097 /**
098 *
099 * @return Price.
100 */
101 public double getPrice() {
102 return price;
103 }
104
105 /**
106 * Sets price.
107 * @param price Price.
108 */
109 public void setPrice(double price) {
110 this.price = price;
111 }
112
113 /**
114 *
115 * @return Number of shares.
116 */
117 public int getSize() {
118 return size;
119 }
120
121 /**
122 * Sets number of shares.
123 * @param size Number of shares.
124 */
125 public void setSize(int size) {
126 this.size = size;
127 }
128
129 /**
130 *
131 * @return Side: B = Buy, S = Sell.
132 */
133 public TradeSideEnum getSide() {
134 return side;
135 }
136
137 /**
138 * Sets side: B = Buy, S = Sell.
139 * @param side Side: B = Buy, S = Sell.
140 */
141 public void setSide(TradeSideEnum side) {
142 this.side = side;
143 }
144
145 @Override
146 public String toString() {
147 return "OTBookReplace: timestamp=" + timestamp + ", orderRef=" + reference + ", size=" + size + ", sideindicator=" + side + ", price=" + price;
148 }
149
150 @Override
151 public int hashCode() {
152 return safeHashCode(timestamp)
153 + 3 * safeHashCode(reference)
154 + 5 * safeHashCode(price)
155 + 7 * safeHashCode(size)
156 + 11 * safeHashCode(side);
157 }
158
159 @Override
160 public boolean equals(Object o) {
161 return equalsTo(this, o);
162 }
163
164 public int compareTo(OTBookReplace other) {
165 int rc;
166
167 if((rc = safeCompare(timestamp, other.timestamp)) != 0) {
168 return rc;
169 }
170
171 if((rc = safeCompare(reference, other.reference)) != 0) {
172 return rc;
173 }
174
175 if((rc = safeCompare(price, other.price)) != 0) {
176 return rc;
177 }
178
179 if((rc = safeCompare(size, other.size)) != 0) {
180 return rc;
181 }
182
183 if((rc = safeCompare(side, other.side)) != 0) {
184 return rc;
185 }
186
187 return 0;
188 }
189 }