Example usage for org.jfree.data.time.ohlc OHLCSeries add

List of usage examples for org.jfree.data.time.ohlc OHLCSeries add

Introduction

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

Prototype

public void add(RegularTimePeriod period, double open, double high, double low, double close) 

Source Link

Document

Adds a data item to the series.

Usage

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

/**
 * Check that the maximum item count can be applied retrospectively.
 *///from ww w. j  av  a2  s.  com
@Test
public void testSetMaximumItemCount2() {
    OHLCSeries s1 = new OHLCSeries("s1");
    s1.add(new Year(2006), 1.0, 1.1, 1.1, 1.1);
    s1.add(new Year(2007), 2.0, 2.2, 2.2, 2.2);
    s1.add(new Year(2008), 3.0, 3.3, 3.3, 3.3);
    s1.setMaximumItemCount(2);
    assertEquals(new Year(2007), s1.getPeriod(0));
    assertEquals(new Year(2008), s1.getPeriod(1));
}

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

/**
 * A check for the remove(int) method./*from   w w  w .  ja  v  a2s.c  om*/
 */
@Test
public void testRemove_int() {
    OHLCSeries s1 = new OHLCSeries("s1");
    s1.add(new Year(2006), 2.0, 4.0, 1.0, 3.0);
    s1.add(new Year(2011), 2.1, 4.1, 1.1, 3.1);
    s1.add(new Year(2010), 2.2, 4.2, 1.2, 3.2);
    assertEquals(3, s1.getItemCount());

    s1.remove(s1.getItemCount() - 1);
    assertEquals(2, s1.getItemCount());
    assertEquals(new Year(2010), s1.getPeriod(1));
}

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

/**
 * If you add a duplicate period, an exception should be thrown.
 *///  ww w . j av  a2s . c om
@Test
public void testAdditionOfDuplicatePeriod() {
    OHLCSeries s1 = new OHLCSeries("s1");
    s1.add(new Year(2006), 1.0, 1.0, 1.0, 1.0);
    boolean pass = false;
    try {
        s1.add(new Year(2006), 1.0, 1.0, 1.0, 1.0);
    } catch (SeriesException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * Two objects that are equal are required to return the same hashCode.
 *//*  w  ww.j  av  a 2s .  c o m*/
@Test
public void testHashcode() {
    OHLCSeries s1 = new OHLCSeries("Test");
    s1.add(new Year(2009), 1.0, 3.0, 2.0, 1.4);
    OHLCSeries s2 = new OHLCSeries("Test");
    s2.add(new Year(2009), 1.0, 3.0, 2.0, 1.4);
    assertTrue(s1.equals(s2));
    int h1 = s1.hashCode();
    int h2 = s2.hashCode();
    assertEquals(h1, h2);
}

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

/**
 * Simple test for the remove() method.//from w w w  .  ja  v a2s .c  om
 */
@Test
public void testRemove() {
    OHLCSeries s1 = new OHLCSeries("s1");
    s1.add(new Year(2006), 2.0, 4.0, 1.0, 3.0);
    s1.add(new Year(2011), 2.1, 4.1, 1.1, 3.1);
    s1.add(new Year(2010), 2.2, 4.2, 1.2, 3.2);
    assertEquals(3, s1.getItemCount());

    s1.remove(new Year(2010));
    assertEquals(new Year(2011), s1.getPeriod(1));

    s1.remove(new Year(2006));
    assertEquals(new Year(2011), s1.getPeriod(0));
}

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

/**
 * Confirm that the equals method can distinguish all the required fields.
 *//*from ww w  . j  a v  a2 s.  c  o  m*/
@Test
public void testEquals() {
    OHLCSeriesCollection c1 = new OHLCSeriesCollection();
    OHLCSeriesCollection c2 = new OHLCSeriesCollection();
    assertEquals(c1, c2);

    // add a series
    OHLCSeries s1 = new OHLCSeries("Series");
    s1.add(new Year(2006), 1.0, 1.1, 1.2, 1.3);
    c1.addSeries(s1);
    assertFalse(c1.equals(c2));
    OHLCSeries s2 = new OHLCSeries("Series");
    s2.add(new Year(2006), 1.0, 1.1, 1.2, 1.3);
    c2.addSeries(s2);
    assertTrue(c1.equals(c2));

    // add an empty series
    c1.addSeries(new OHLCSeries("Empty Series"));
    assertFalse(c1.equals(c2));
    c2.addSeries(new OHLCSeries("Empty Series"));
    assertTrue(c1.equals(c2));

    c1.setXPosition(TimePeriodAnchor.END);
    assertFalse(c1.equals(c2));
    c2.setXPosition(TimePeriodAnchor.END);
    assertTrue(c1.equals(c2));

}

From source file:grafix.graficos.eixos.EixoCandles.java

private OHLCDataset criarOHLCDataset(JanelaGraficos janela) {
    //*debug*/ System.out.println("[CHAMADA] criarOHLCDataset()");
    OHLCSeries serie = new OHLCSeries(janela.getAcao().getCodAcao());
    IntervaloExibicao intervalo = janela.getIntervaloExibicao();
    for (int i = intervalo.getInicio(); i < intervalo.getFim(); i++) {
        RegistroDiario reg = janela.getAcao().getRegistro(i);
        serie.add(reg.getData(Controle.getConfiguracoesUsuario().isExibeSomenteDiasUteis()), reg.getOpen(),
                reg.getHigh(), reg.getLow(), reg.getClose());
    }/*from  w  w w. ja v a  2 s . c  o m*/
    OHLCSeriesCollection dataset = new OHLCSeriesCollection();
    dataset.addSeries(serie);
    return dataset;
}

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

/**
 * Some checks for the clear() method.//  w w w  . ja v  a 2 s. com
 */
@Test
public void testClear() {
    OHLCSeries s1 = new OHLCSeries("S1");
    s1.addChangeListener(this);
    s1.clear();
    assertNull(this.lastEvent);
    assertTrue(s1.isEmpty());
    s1.add(new Year(2006), 1.0, 1.1, 1.1, 1.1);
    assertFalse(s1.isEmpty());
    s1.clear();
    assertNotNull(this.lastEvent);
    assertTrue(s1.isEmpty());
}

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

/**
 * A simple check that the maximumItemCount attribute is working.
 *//* w  w w . j av a  2s. co m*/
@Test
public void testSetMaximumItemCount() {
    OHLCSeries s1 = new OHLCSeries("s1");
    assertEquals(Integer.MAX_VALUE, s1.getMaximumItemCount());
    s1.setMaximumItemCount(2);
    assertEquals(2, s1.getMaximumItemCount());
    s1.add(new Year(2006), 1.0, 1.1, 1.1, 1.1);
    s1.add(new Year(2007), 2.0, 2.2, 2.2, 2.2);
    s1.add(new Year(2008), 3.0, 3.3, 3.3, 3.3);
    assertEquals(new Year(2007), s1.getPeriod(0));
    assertEquals(new Year(2008), s1.getPeriod(1));
}

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

/**
 * Confirm that the equals method can distinguish all the required fields.
 *//* w  w w  . j a  v  a 2  s . c  o  m*/
@Test
public void testEquals() {
    OHLCSeries s1 = new OHLCSeries("s1");
    OHLCSeries s2 = new OHLCSeries("s1");
    assertTrue(s1.equals(s2));

    // seriesKey
    s1 = new OHLCSeries("s2");
    assertFalse(s1.equals(s2));
    s2 = new OHLCSeries("s2");
    assertTrue(s1.equals(s2));

    // add a value
    s1.add(new Year(2006), 2.0, 4.0, 1.0, 3.0);
    assertFalse(s1.equals(s2));
    s2.add(new Year(2006), 2.0, 4.0, 1.0, 3.0);
    assertTrue(s2.equals(s1));

    // add another value
    s1.add(new Year(2008), 2.0, 4.0, 1.0, 3.0);
    assertFalse(s1.equals(s2));
    s2.add(new Year(2008), 2.0, 4.0, 1.0, 3.0);
    assertTrue(s2.equals(s1));

    // remove a value
    s1.remove(new Year(2008));
    assertFalse(s1.equals(s2));
    s2.remove(new Year(2008));
    assertTrue(s2.equals(s1));
}