001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-present, by David Gilbert 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-present, by David Gilbert.
031 *
032 * Original Author:  David Gilbert;
033 * Contributor(s):   -;
034 *
035 */
036
037package org.jfree.data.time.ohlc;
038
039import java.io.Serializable;
040import org.jfree.chart.HashUtils;
041
042/**
043 * A data record containing open-high-low-close data (immutable).  This class 
044 * is used internally by the {@link OHLCItem} class.
045 */
046public class OHLC implements Serializable {
047
048    /** The open value. */
049    private double open;
050
051    /** The close value. */
052    private double close;
053
054    /** The high value. */
055    private double high;
056
057    /** The low value. */
058    private double low;
059
060    /**
061     * Creates a new instance of {@code OHLC}.
062     *
063     * @param open  the open value.
064     * @param close  the close value.
065     * @param high  the high value.
066     * @param low  the low value.
067     */
068    public OHLC(double open, double high, double low, double close) {
069        this.open = open;
070        this.close = close;
071        this.high = high;
072        this.low = low;
073    }
074
075    /**
076     * Returns the open value.
077     *
078     * @return The open value.
079     */
080    public double getOpen() {
081        return this.open;
082    }
083
084    /**
085     * Returns the close value.
086     *
087     * @return The close value.
088     */
089    public double getClose() {
090        return this.close;
091    }
092
093    /**
094     * Returns the high value.
095     *
096     * @return The high value.
097     */
098    public double getHigh() {
099        return this.high;
100    }
101
102    /**
103     * Returns the low value.
104     *
105     * @return The low value.
106     */
107    public double getLow() {
108        return this.low;
109    }
110
111    /**
112     * Tests this instance for equality with an arbitrary object.
113     *
114     * @param obj  the object ({@code null} permitted).
115     *
116     * @return A boolean.
117     */
118    @Override
119    public boolean equals(Object obj) {
120        if (obj == this) {
121            return true;
122        }
123        if (!(obj instanceof OHLC)) {
124            return false;
125        }
126        OHLC that = (OHLC) obj;
127        if (this.open != that.open) {
128            return false;
129        }
130        if (this.close != that.close) {
131            return false;
132        }
133        if (this.high != that.high) {
134            return false;
135        }
136        if (this.low != that.low) {
137            return false;
138        }
139        return true;
140    }
141
142    /**
143     * Returns a hash code for this instance.
144     *
145     * @return A hash code.
146     */
147    @Override
148    public int hashCode() {
149        int result = 193;
150        result = HashUtils.hashCode(result, this.open);
151        result = HashUtils.hashCode(result, this.high);
152        result = HashUtils.hashCode(result, this.low);
153        result = HashUtils.hashCode(result, this.close);
154        return result;
155    }
156
157}