Example usage for org.jfree.data.time.ohlc OHLCItem OHLCItem

List of usage examples for org.jfree.data.time.ohlc OHLCItem OHLCItem

Introduction

In this page you can find the example usage for org.jfree.data.time.ohlc OHLCItem OHLCItem.

Prototype

public OHLCItem(RegularTimePeriod period, double open, double high, double low, double close) 

Source Link

Document

Creates a new instance of OHLCItem.

Usage

From source file:org.jfree.data.time.ohlc.OHLCItemTest.java

/**
 * Some checks for the constructor./*from   w ww  .  ja  v  a2  s.c o m*/
 */
@Test
public void testConstructor1() {
    OHLCItem item1 = new OHLCItem(new Year(2006), 2.0, 4.0, 1.0, 3.0);
    assertEquals(new Year(2006), item1.getPeriod());
    assertEquals(2.0, item1.getOpenValue(), EPSILON);
    assertEquals(4.0, item1.getHighValue(), EPSILON);
    assertEquals(1.0, item1.getLowValue(), EPSILON);
    assertEquals(3.0, item1.getCloseValue(), EPSILON);
}

From source file:org.jfree.data.time.ohlc.OHLCItemTest.java

/**
 * Confirm that the equals method can distinguish all the required fields.
 *///from   ww w.j av a2 s  . c  o m
@Test
public void testEquals() {
    OHLCItem item1 = new OHLCItem(new Year(2006), 2.0, 4.0, 1.0, 3.0);
    OHLCItem item2 = new OHLCItem(new Year(2006), 2.0, 4.0, 1.0, 3.0);
    assertTrue(item1.equals(item2));
    assertTrue(item2.equals(item1));

    // period
    item1 = new OHLCItem(new Year(2007), 2.0, 4.0, 1.0, 3.0);
    assertFalse(item1.equals(item2));
    item2 = new OHLCItem(new Year(2007), 2.0, 4.0, 1.0, 3.0);
    assertTrue(item1.equals(item2));

    // open
    item1 = new OHLCItem(new Year(2007), 2.2, 4.0, 1.0, 3.0);
    assertFalse(item1.equals(item2));
    item2 = new OHLCItem(new Year(2007), 2.2, 4.0, 1.0, 3.0);
    assertTrue(item1.equals(item2));

    // high
    item1 = new OHLCItem(new Year(2007), 2.2, 4.4, 1.0, 3.0);
    assertFalse(item1.equals(item2));
    item2 = new OHLCItem(new Year(2007), 2.2, 4.4, 1.0, 3.0);
    assertTrue(item1.equals(item2));

    // low
    item1 = new OHLCItem(new Year(2007), 2.2, 4.4, 1.1, 3.0);
    assertFalse(item1.equals(item2));
    item2 = new OHLCItem(new Year(2007), 2.2, 4.4, 1.1, 3.0);
    assertTrue(item1.equals(item2));

    // close
    item1 = new OHLCItem(new Year(2007), 2.2, 4.4, 1.1, 3.3);
    assertFalse(item1.equals(item2));
    item2 = new OHLCItem(new Year(2007), 2.2, 4.4, 1.1, 3.3);
    assertTrue(item1.equals(item2));
}

From source file:org.jfree.data.time.ohlc.OHLCSeries.java

/**
 * Adds a data item to the series./* w  w w.j  a v a  2 s  . c  o m*/
 *
 * @param period  the period.
 * @param open  the open-value.
 * @param high  the high-value.
 * @param low  the low-value.
 * @param close  the close-value.
 */
public void add(RegularTimePeriod period, double open, double high, double low, double close) {
    if (getItemCount() > 0) {
        OHLCItem item0 = (OHLCItem) this.getDataItem(0);
        if (!period.getClass().equals(item0.getPeriod().getClass())) {
            throw new IllegalArgumentException("Can't mix RegularTimePeriod class types.");
        }
    }
    super.add(new OHLCItem(period, open, high, low, close), true);
}

From source file:org.jfree.data.time.ohlc.OHLCItemTest.java

/**
 * Some checks for the clone() method./*from ww  w .  java  2  s.c  o  m*/
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    OHLCItem item1 = new OHLCItem(new Year(2006), 2.0, 4.0, 1.0, 3.0);
    OHLCItem item2 = (OHLCItem) item1.clone();
    assertTrue(item1 != item2);
    assertTrue(item1.getClass() == item2.getClass());
    assertTrue(item1.equals(item2));
}

From source file:org.jfree.data.time.ohlc.OHLCItemTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *///w  w  w. ja  v  a 2s  .  co  m
@Test
public void testSerialization() {
    OHLCItem item1 = new OHLCItem(new Year(2006), 2.0, 4.0, 1.0, 3.0);
    OHLCItem item2 = (OHLCItem) TestUtilities.serialised(item1);
    assertEquals(item1, item2);
}

From source file:org.jfree.data.time.ohlc.OHLCItemTest.java

/**
 * Two objects that are equal are required to return the same hashCode.
 */// ww w.ja va2 s .  c o m
@Test
public void testHashcode() {
    OHLCItem i1 = new OHLCItem(new Year(2009), 2.0, 4.0, 1.0, 3.0);
    OHLCItem i2 = new OHLCItem(new Year(2009), 2.0, 4.0, 1.0, 3.0);
    assertTrue(i1.equals(i2));
    int h1 = i1.hashCode();
    int h2 = i2.hashCode();
    assertEquals(h1, h2);
}