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     * Represents a Split event.
031     */
032    public final class OTSplit implements Comparable<OTSplit>, Serializable {
033    
034            private static final long serialVersionUID = 1917216759776849575L;
035            
036            private int  toFactor;
037        private int  forFactor;
038        private Date declarationDate;
039        private Date executionDate;
040        private Date recordDate;
041        private Date paymentDate;
042    
043        /**
044         * Default constructor.
045         */
046        public OTSplit() { }
047    
048        /**
049         * Constructor.
050         * @param toFactor To factor.
051         * @param forFactor For factor.
052         * @param declaratonDate Declaration date.
053         * @param executionDate Execution date.
054         * @param recordDate        Record date.
055         * @param paymentDate Payment date.
056         */
057        public OTSplit(int toFactor, int forFactor, Date declaratonDate,
058                    Date executionDate, Date recordDate, 
059                    Date paymentDate) {
060            this.toFactor=toFactor;
061            this.forFactor=forFactor;
062            this.declarationDate=declaratonDate;
063            this.executionDate=executionDate;
064            this.recordDate=recordDate;
065            this.paymentDate=paymentDate;
066        }
067    
068        /**
069         *
070         * @return To factor.
071         */
072        public int getToFactor() {
073            return toFactor;
074        }
075    
076        /**
077         * Sets to factor.
078         * @param toFactor  To factor.
079         */
080        public void setToFactor(int toFactor) {
081            this.toFactor = toFactor;
082        }
083    
084        /**
085         * 
086         * @return For factor.
087         */
088        public int getForFactor() {
089            return forFactor;
090        }
091    
092        /**
093         * Sets for factor.
094         * @param forFactor For factor.
095         */
096        public void setForFactor(int forFactor) {
097            this.forFactor = forFactor;
098        }
099    
100        /**
101         * 
102         * @return Declaration date.
103         */
104        public Date getDeclarationDate() {
105            return declarationDate;
106        }
107    
108        /**
109         * Sets declaration date.
110         * @param declarationDate Declaration date.
111         */
112        public void setDeclarationDate(Date declarationDate) {
113            this.declarationDate = declarationDate;
114        }
115    
116        /**
117         *
118         * @return Execution date.
119         */
120        public Date getExecutionDate() {
121            return executionDate;
122        }
123    
124        /**
125         * Sets execution date.
126         * @param executionDate Execution date.
127         */
128        public void setExecutionDate(Date executionDate) {
129            this.executionDate = executionDate;
130        }
131    
132       /**
133         *
134         * @return Record date.
135         */
136        public Date getRecordDate() {
137            return recordDate;
138        }
139    
140        /**
141         * Sets record date.
142         * @param recordDate Record date.
143         */
144        public void setRecordDate(Date recordDate) {
145            this.recordDate = recordDate;
146        }
147    
148        /**
149         *
150         * @return Payment date.
151         */
152        public Date getPaymentDate() {
153            return paymentDate;
154        }
155        
156        /**
157         * Sets payment date.
158         * @param paymentDate Payment date.
159         */
160        public void setPaymentDate(Date paymentDate) {
161            this.paymentDate = paymentDate;
162        }
163    
164        @Override
165            public String toString() {
166            return "OTSplit: toFactor=" + toFactor
167                            + ", forFactor=" + forFactor
168                            + ", decldate=" + declarationDate
169                            + ", execdate=" + executionDate
170                            + ", recdate=" + recordDate
171                            + ", paydate=" + paymentDate;
172        }
173    
174        @Override
175            public int hashCode() {
176            return safeHashCode(toFactor) 
177                    + 3 * safeHashCode(forFactor)
178                    + 5 * safeHashCode(declarationDate)
179                    + 7 * safeHashCode(executionDate)
180                    + 11 * safeHashCode(recordDate)
181                    + 13 * safeHashCode(paymentDate);
182        }
183            
184        @Override
185            public boolean equals(Object o) {
186            return equalsTo(this, o);
187        }
188        
189            public int compareTo(OTSplit other) {
190                    int rc;
191    
192                    if((rc = safeCompare(toFactor, other.toFactor)) != 0) {
193                            return rc;
194                    }
195                    
196                    if((rc = safeCompare(forFactor, other.forFactor)) != 0) {
197                            return rc;
198                    }
199    
200                    if((rc = safeCompare(declarationDate, other.declarationDate)) != 0) {
201                            return rc;
202                    }
203    
204                    if((rc = safeCompare(executionDate, other.executionDate)) != 0) {
205                            return rc;
206                    }
207    
208                    if((rc = safeCompare(recordDate, other.recordDate)) != 0) {
209                            return rc;
210                    }
211    
212                    if((rc = safeCompare(paymentDate, other.paymentDate)) != 0) {
213                            return rc;
214                    }
215    
216                    return 0;
217            }
218    }