001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors.
006 *
007 * Project Info:  http://www.jfree.org/jfreechart/index.html
008 *
009 * This library is free software; you can redistribute it and/or modify it
010 * under the terms of the GNU Lesser General Public License as published by
011 * the Free Software Foundation; either version 2.1 of the License, or
012 * (at your option) any later version.
013 *
014 * This library is distributed in the hope that it will be useful, but
015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017 * License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this library; if not, write to the Free Software
021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
022 * USA.
023 *
024 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 
025 * Other names may be trademarks of their respective owners.]
026 *
027 * ---------
028 * OHLC.java
029 * ---------
030 * (C) Copyright 2006, 2009, by Object Refinery Limited.
031 *
032 * Original Author:  David Gilbert (for Object Refinery Limited);
033 * Contributor(s):   -;
034 *
035 * Changes
036 * -------
037 * 04-Dec-2006 : Version 1 (DG);
038 * 23-May-2009 : Implemented hashCode() (DG);
039 *
040 */
041
042package org.jfree.data.time.ohlc;
043
044import java.io.Serializable;
045import org.jfree.chart.HashUtilities;
046
047/**
048 * A high low data record (immutable).  This class is used internally by the
049 * {@link OHLCItem} class.
050 *
051 * @since 1.0.4
052 */
053public class OHLC implements Serializable {
054
055    /** The open value. */
056    private double open;
057
058    /** The close value. */
059    private double close;
060
061    /** The high value. */
062    private double high;
063
064    /** The low value. */
065    private double low;
066
067    /**
068     * Creates a new instance of <code>OHLC</code>.
069     *
070     * @param open  the open value.
071     * @param close  the close value.
072     * @param high  the high value.
073     * @param low  the low value.
074     */
075    public OHLC(double open, double high, double low, double close) {
076        this.open = open;
077        this.close = close;
078        this.high = high;
079        this.low = low;
080    }
081
082    /**
083     * Returns the open value.
084     *
085     * @return The open value.
086     */
087    public double getOpen() {
088        return this.open;
089    }
090
091    /**
092     * Returns the close value.
093     *
094     * @return The close value.
095     */
096    public double getClose() {
097        return this.close;
098    }
099
100    /**
101     * Returns the high value.
102     *
103     * @return The high value.
104     */
105    public double getHigh() {
106        return this.high;
107    }
108
109    /**
110     * Returns the low value.
111     *
112     * @return The low value.
113     */
114    public double getLow() {
115        return this.low;
116    }
117
118    /**
119     * Tests this instance for equality with an arbitrary object.
120     *
121     * @param obj  the object (<code>null</code> permitted).
122     *
123     * @return A boolean.
124     */
125    public boolean equals(Object obj) {
126        if (obj == this) {
127            return true;
128        }
129        if (!(obj instanceof OHLC)) {
130            return false;
131        }
132        OHLC that = (OHLC) obj;
133        if (this.open != that.open) {
134            return false;
135        }
136        if (this.close != that.close) {
137            return false;
138        }
139        if (this.high != that.high) {
140            return false;
141        }
142        if (this.low != that.low) {
143            return false;
144        }
145        return true;
146    }
147
148    /**
149     * Returns a hash code for this instance.
150     *
151     * @return A hash code.
152     */
153    public int hashCode() {
154        int result = 193;
155        result = HashUtilities.hashCode(result, this.open);
156        result = HashUtilities.hashCode(result, this.high);
157        result = HashUtilities.hashCode(result, this.low);
158        result = HashUtilities.hashCode(result, this.close);
159        return result;
160    }
161
162}