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