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 /**
031 * Class for book cancelation data representation.
032 */
033 public final class OTBookCancel implements Comparable<OTBookCancel>, Serializable {
034
035 private static final long serialVersionUID = -1770059413413742405L;
036
037 private Date timestamp;
038 private String reference;
039 private int size;
040
041 /**
042 * Default constructor.
043 */
044 public OTBookCancel() { }
045
046 /**
047 * Constructor.
048 *
049 * @param timestamp Time of the event.
050 * @param reference Order reference.
051 * @param size Number of shares.
052 */
053 public OTBookCancel(Date timestamp,
054 String reference, int size) {
055 this.timestamp = timestamp;
056 this.reference = reference;
057 this.size = size;
058 }
059
060 /**
061 * @return Time when the event occurred.
062 */
063 public Date getTimestamp() {
064 return timestamp;
065 }
066
067 /**
068 * Sets time of the event.
069 * @param timestamp Time when the event occurred.
070 */
071 public void setTimestamp(Date timestamp) {
072 this.timestamp = timestamp;
073 }
074
075 /**
076 * Sets order reference.
077 * @param reference Order reference.
078 */
079 public void setOrderRef(String reference) {
080 this.reference = reference;
081 }
082
083 /**
084 *
085 * @return Order reference.
086 */
087 public String getOrderRef() {
088 return this.reference;
089 }
090
091 /**
092 *
093 * @return Number of shares.
094 */
095 public int getSize() {
096 return size;
097 }
098
099 /**
100 * Sets number of shares.
101 * @param size Number of shares.
102 */
103 public void setSize(int size) {
104 this.size = size;
105 }
106
107 @Override
108 public String toString() {
109 return "OTBookCancel: timestamp=" + timestamp + ", orderRef=" + reference + ", size=" + size;
110 }
111
112 @Override
113 public int hashCode() {
114 return safeHashCode(timestamp)
115 + 3 * safeHashCode(reference)
116 + 5 * safeHashCode(size);
117 }
118
119 @Override
120 public boolean equals(Object o) {
121 return equalsTo(this, o);
122 }
123
124 public int compareTo(OTBookCancel other) {
125 int rc;
126
127 if((rc = safeCompare(timestamp, other.timestamp)) != 0) {
128 return rc;
129 }
130
131 if((rc = safeCompare(reference, other.reference)) != 0) {
132 return rc;
133 }
134
135 if((rc = safeCompare(size, other.size)) != 0) {
136 return rc;
137 }
138
139 return 0;
140 }
141 }