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
028 /**
029 * Provides OHL (Open/High/Low) information.
030 */
031 public final class OTTodaysOHL implements Comparable<OTTodaysOHL>, Serializable {
032
033 private static final long serialVersionUID = -193738134747913662L;
034
035 private double openPrice;
036 private double highPrice;
037 private double lowPrice;
038
039 /**
040 * Default constructor.
041 */
042 public OTTodaysOHL() { }
043
044 /**
045 * Constructor.
046 * @param openPrice Open price.
047 * @param highPrice High price.
048 * @param lowPrice Low price.
049 */
050 public OTTodaysOHL(double openPrice,
051 double highPrice, double lowPrice) {
052 this.openPrice = openPrice;
053 this.highPrice = highPrice;
054 this.lowPrice = lowPrice;
055 }
056
057 /**
058 *
059 * @return Open price.
060 */
061 public double getOpenPrice() {
062 return openPrice;
063 }
064
065 /**
066 * Sets Open price.
067 * @param openPrice Open price.
068 */
069 public void setOpenPrice(double openPrice) {
070 this.openPrice = openPrice;
071 }
072
073 /**
074 *
075 * @return High price.
076 */
077 public double getHighPrice() {
078 return highPrice;
079 }
080
081 /**
082 * Sets High Price.
083 * @param highPrice High price.
084 */
085 public void setHighPrice(double highPrice) {
086 this.highPrice = highPrice;
087 }
088
089 /**
090 *
091 * @return Low price.
092 */
093 public double getLowPrice() {
094 return lowPrice;
095 }
096
097 /**
098 * Sets Low price.
099 * @param lowPrice Low price.
100 */
101 public void setLowPrice(double lowPrice) {
102 this.lowPrice = lowPrice;
103 }
104
105 @Override
106 public String toString() {
107 return "OTTodaysOHL: openprice=" + openPrice + ", highprice=" + highPrice + ", lowprice=" + lowPrice;
108 }
109
110
111 @Override
112 public int hashCode() {
113 return safeHashCode(openPrice)
114 + 3 * safeHashCode(highPrice)
115 + 5 * safeHashCode(lowPrice);
116 }
117
118 @Override
119 public boolean equals(Object o) {
120 return equalsTo(this, o);
121 }
122
123 public int compareTo(OTTodaysOHL other) {
124 int rc;
125
126 if((rc = safeCompare(openPrice, other.openPrice)) != 0) {
127 return rc;
128 }
129
130 if((rc = safeCompare(highPrice, other.highPrice)) != 0) {
131 return rc;
132 }
133
134 if((rc = safeCompare(lowPrice, other.lowPrice)) != 0) {
135 return rc;
136 }
137
138 return 0;
139 }
140 }