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