001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2013, 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 data record containing open-high-low-close data (immutable).  This class 
049 * is used internally by the {@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    @Override
126    public boolean equals(Object obj) {
127        if (obj == this) {
128            return true;
129        }
130        if (!(obj instanceof OHLC)) {
131            return false;
132        }
133        OHLC that = (OHLC) obj;
134        if (this.open != that.open) {
135            return false;
136        }
137        if (this.close != that.close) {
138            return false;
139        }
140        if (this.high != that.high) {
141            return false;
142        }
143        if (this.low != that.low) {
144            return false;
145        }
146        return true;
147    }
148
149    /**
150     * Returns a hash code for this instance.
151     *
152     * @return A hash code.
153     */
154    @Override
155    public int hashCode() {
156        int result = 193;
157        result = HashUtilities.hashCode(result, this.open);
158        result = HashUtilities.hashCode(result, this.high);
159        result = HashUtilities.hashCode(result, this.low);
160        result = HashUtilities.hashCode(result, this.close);
161        return result;
162    }
163
164}