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

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

Introduction

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

Prototype

public OHLCSeries(Comparable key) 

Source Link

Document

Creates a new empty series.

Usage

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

/**
 * Serialize an instance, restore it, and check for equality.
 *//*from   w  ww  . java2s .  c  o  m*/
@Test
public void testSerialization() {
    OHLCSeries s1 = new OHLCSeries("s1");
    s1.add(new Year(2006), 2.0, 4.0, 1.0, 3.0);
    OHLCSeries s2 = (OHLCSeries) TestUtilities.serialised(s1);
    assertEquals(s1, s2);
}

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

/**
 * A test for bug report 1170825 (originally affected XYSeriesCollection,
 * this test is just copied over)./*from   w ww  . j a  v a 2  s  .co  m*/
 */
@Test
public void test1170825() {
    OHLCSeries s1 = new OHLCSeries("Series1");
    OHLCSeriesCollection dataset = new OHLCSeriesCollection();
    dataset.addSeries(s1);
    try {
        /* XYSeries s = */ dataset.getSeries(1);
    } catch (IllegalArgumentException e) {
        // correct outcome
    } catch (IndexOutOfBoundsException e) {
        assertTrue(false); // wrong outcome
    }
}

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

/**
 * Simple test for the indexOf() method.
 *//* w  w w. ja  v a2  s  .c  o m*/
@Test
public void testIndexOf() {
    OHLCSeries s1 = new OHLCSeries("s1");
    s1.add(new Year(2006), 2.0, 4.0, 1.0, 3.0);
    s1.add(new Year(2011), 2.0, 4.0, 1.0, 3.0);
    s1.add(new Year(2010), 2.0, 4.0, 1.0, 3.0);
    assertEquals(0, s1.indexOf(new Year(2006)));
    assertEquals(1, s1.indexOf(new Year(2010)));
    assertEquals(2, s1.indexOf(new Year(2011)));
}

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

/**
 * Two objects that are equal are required to return the same hashCode.
 *//*from w  w w  . ja  va 2s.c o m*/
@Test
public void testHashcode() {
    OHLCSeriesCollection c1 = new OHLCSeriesCollection();
    OHLCSeries s1 = new OHLCSeries("S");
    s1.add(new Year(2009), 1.0, 4.0, 0.5, 2.0);
    c1.addSeries(s1);
    OHLCSeriesCollection c2 = new OHLCSeriesCollection();
    OHLCSeries s2 = new OHLCSeries("S");
    s2.add(new Year(2009), 1.0, 4.0, 0.5, 2.0);
    c2.addSeries(s2);
    assertTrue(c1.equals(c2));
    int h1 = c1.hashCode();
    int h2 = c2.hashCode();
    assertEquals(h1, h2);
}

From source file:org.optaplanner.examples.cheaptime.swingui.CheapTimePanel.java

private XYPlot createTaskAssignmentPlot(TangoColorFactory tangoColorFactory, CheapTimeSolution solution) {
    OHLCSeriesCollection seriesCollection = new OHLCSeriesCollection();
    Map<Machine, OHLCSeries> machineSeriesMap = new LinkedHashMap<Machine, OHLCSeries>(
            solution.getMachineList().size());
    HighLowRenderer renderer = new HighLowRenderer();
    renderer.setTickLength(0.0);/*from w  w  w .  j  a  v a  2  s. co m*/
    int seriesIndex = 0;
    OHLCSeries unassignedProjectSeries = new OHLCSeries("Unassigned");
    seriesCollection.addSeries(unassignedProjectSeries);
    machineSeriesMap.put(null, unassignedProjectSeries);
    renderer.setSeriesStroke(seriesIndex, new BasicStroke(3.0f));
    renderer.setSeriesPaint(seriesIndex, TangoColorFactory.SCARLET_1);
    seriesIndex++;
    for (Machine machine : solution.getMachineList()) {
        OHLCSeries machineSeries = new OHLCSeries(machine.getLabel());
        seriesCollection.addSeries(machineSeries);
        machineSeriesMap.put(machine, machineSeries);
        renderer.setSeriesStroke(seriesIndex, new BasicStroke(3.0f));
        renderer.setSeriesPaint(seriesIndex, tangoColorFactory.pickColor(machine));
        seriesIndex++;
    }
    List<TaskAssignment> taskAssignmentList = new ArrayList<TaskAssignment>(solution.getTaskAssignmentList());
    Collections.sort(taskAssignmentList,
            groupByMachineCheckBox.isSelected() ? groupByMachineTaskAssignmentComparator
                    : stableTaskAssignmentComparator);
    int pixelIndex = 0;
    for (TaskAssignment taskAssignment : taskAssignmentList) {
        Task task = taskAssignment.getTask();
        Integer startPeriod = taskAssignment.getStartPeriod();
        Integer endPeriod = taskAssignment.getEndPeriod();
        if (startPeriod == null) {
            startPeriod = task.getStartPeriodRangeFrom();
            endPeriod = startPeriod + task.getDuration();
        }
        OHLCSeries machineSeries = machineSeriesMap.get(taskAssignment.getMachine());
        machineSeries.add(new FixedMillisecond(pixelIndex), task.getStartPeriodRangeFrom(), startPeriod,
                endPeriod, task.getStartPeriodRangeTo() + task.getDuration());
        pixelIndex++;
    }
    NumberAxis domainAxis = new NumberAxis("Task");
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setRange(-0.5, taskAssignmentList.size() - 0.5);
    domainAxis.setInverted(true);
    return new XYPlot(seriesCollection, domainAxis, null, renderer);
}

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

/**
 * Simple test for the remove() method.//from ww w .j  a va  2  s . 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

/**
 * Some checks for the {@link OHLCSeriesCollection#removeSeries(int)}
 * method.//from  w  w  w  .j  a va 2s .  co  m
 */
@Test
public void testRemoveSeries_int() {
    OHLCSeriesCollection c1 = new OHLCSeriesCollection();
    OHLCSeries s1 = new OHLCSeries("Series 1");
    OHLCSeries s2 = new OHLCSeries("Series 2");
    OHLCSeries s3 = new OHLCSeries("Series 3");
    OHLCSeries s4 = new OHLCSeries("Series 4");
    c1.addSeries(s1);
    c1.addSeries(s2);
    c1.addSeries(s3);
    c1.addSeries(s4);
    c1.removeSeries(2);
    assertTrue(c1.getSeries(2).equals(s4));
    c1.removeSeries(0);
    assertTrue(c1.getSeries(0).equals(s2));
    assertEquals(2, c1.getSeriesCount());
}

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

/**
 * A check for the remove(int) method./*from   w  w w .j  a v a 2 s  .  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.
 *///from www  .  j a  va 2  s  . co  m
@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.OHLCSeriesCollectionTest.java

/**
 * Some checks for the/*  w  w w  . j a va  2  s  .c  o m*/
 * {@link OHLCSeriesCollection#removeSeries(OHLCSeries)} method.
 */
@Test
public void testRemoveSeries() {
    OHLCSeriesCollection c1 = new OHLCSeriesCollection();
    OHLCSeries s1 = new OHLCSeries("Series 1");
    OHLCSeries s2 = new OHLCSeries("Series 2");
    OHLCSeries s3 = new OHLCSeries("Series 3");
    OHLCSeries s4 = new OHLCSeries("Series 4");
    c1.addSeries(s1);
    c1.addSeries(s2);
    c1.addSeries(s3);
    c1.addSeries(s4);
    c1.removeSeries(s3);
    assertTrue(c1.getSeries(2).equals(s4));
    c1.removeSeries(s1);
    assertTrue(c1.getSeries(0).equals(s2));
    assertEquals(2, c1.getSeriesCount());
}