List of usage examples for org.jfree.data.time TimeSeriesDataItem setValue
public void setValue(Number value)
From source file:org.jfree.data.time.TimeSeriesDataItemTest.java
/** * Test the equals() method./*from w ww . j ava2s . c o m*/ */ @Test public void testEquals() { TimeSeriesDataItem item1 = new TimeSeriesDataItem(new Day(23, 9, 2001), 99.7); TimeSeriesDataItem item2 = new TimeSeriesDataItem(new Day(23, 9, 2001), 99.7); assertTrue(item1.equals(item2)); assertTrue(item2.equals(item1)); item1.setValue(new Integer(5)); assertFalse(item1.equals(item2)); item2.setValue(new Integer(5)); assertTrue(item1.equals(item2)); }
From source file:org.jfree.data.time.junit.TimeSeriesTest.java
/** * Create a TimeSeriesDataItem, add it to a TimeSeries. Now, modifying * the original TimeSeriesDataItem should NOT affect the TimeSeries. *///from w w w . ja v a 2 s . c o m public void testAdd_TimeSeriesDataItem() { TimeSeriesDataItem item = new TimeSeriesDataItem(new Year(2009), 1.0); TimeSeries series = new TimeSeries("S1"); series.add(item); assertTrue(item.equals(series.getDataItem(0))); item.setValue(new Double(99.9)); assertFalse(item.equals(series.getDataItem(0))); }
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * Create a TimeSeriesDataItem, add it to a TimeSeries. Now, modifying * the original TimeSeriesDataItem should NOT affect the TimeSeries. *//*from w w w.ja v a 2s . c o m*/ @Test public void testAdd_TimeSeriesDataItem() { TimeSeriesDataItem item = new TimeSeriesDataItem(new Year(2009), 1.0); TimeSeries series = new TimeSeries("S1"); series.add(item); assertTrue(item.equals(series.getDataItem(0))); item.setValue(new Double(99.9)); assertFalse(item.equals(series.getDataItem(0))); }
From source file:org.jfree.data.time.junit.TimeSeriesTest.java
/** * Some more checks for the addOrUpdate() method. *//*from ww w. ja va 2 s . co m*/ public void testAddOrUpdate4() { TimeSeries ts = new TimeSeries("S"); TimeSeriesDataItem overwritten = ts.addOrUpdate(new Year(2009), 20.09); assertNull(overwritten); overwritten = ts.addOrUpdate(new Year(2009), 1.0); assertEquals(new Double(20.09), overwritten.getValue()); assertEquals(new Double(1.0), ts.getValue(new Year(2009))); // changing the overwritten record shouldn't affect the series overwritten.setValue(null); assertEquals(new Double(1.0), ts.getValue(new Year(2009))); TimeSeriesDataItem item = new TimeSeriesDataItem(new Year(2010), 20.10); overwritten = ts.addOrUpdate(item); assertNull(overwritten); assertEquals(new Double(20.10), ts.getValue(new Year(2010))); // changing the item that was added should not change the series item.setValue(null); assertEquals(new Double(20.10), ts.getValue(new Year(2010))); }
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * Some more checks for the addOrUpdate() method. *///from ww w.ja va 2 s.c o m @Test public void testAddOrUpdate4() { TimeSeries ts = new TimeSeries("S"); TimeSeriesDataItem overwritten = ts.addOrUpdate(new Year(2009), 20.09); assertNull(overwritten); overwritten = ts.addOrUpdate(new Year(2009), 1.0); assertEquals(new Double(20.09), overwritten.getValue()); assertEquals(new Double(1.0), ts.getValue(new Year(2009))); // changing the overwritten record shouldn't affect the series overwritten.setValue(null); assertEquals(new Double(1.0), ts.getValue(new Year(2009))); TimeSeriesDataItem item = new TimeSeriesDataItem(new Year(2010), 20.10); overwritten = ts.addOrUpdate(item); assertNull(overwritten); assertEquals(new Double(20.10), ts.getValue(new Year(2010))); // changing the item that was added should not change the series item.setValue(null); assertEquals(new Double(20.10), ts.getValue(new Year(2010))); }
From source file:org.jfree.data.time.TimeSeries.java
/** * Updates (changes) the value of a data item. * * @param index the index of the data item. * @param value the new value (<code>null</code> permitted). *///from www . ja v a 2 s . c o m public void update(int index, Number value) { TimeSeriesDataItem item = (TimeSeriesDataItem) this.data.get(index); boolean iterate = false; Number oldYN = item.getValue(); if (oldYN != null) { double oldY = oldYN.doubleValue(); if (!Double.isNaN(oldY)) { iterate = oldY <= this.minY || oldY >= this.maxY; } } item.setValue(value); if (iterate) { updateMinMaxYByIteration(); } else if (value != null) { double yy = value.doubleValue(); this.minY = minIgnoreNaN(this.minY, yy); this.maxY = maxIgnoreNaN(this.maxY, yy); } fireSeriesChanged(); }
From source file:org.jfree.data.time.TimeSeries.java
/** * Adds or updates an item in the times series and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param item the data item (<code>null</code> not permitted). * * @return A copy of the overwritten data item, or <code>null</code> if no * item was overwritten.//from ww w . j a v a2 s .c o m * * @since 1.0.14 */ public TimeSeriesDataItem addOrUpdate(TimeSeriesDataItem item) { ParamChecks.nullNotPermitted(item, "item"); Class periodClass = item.getPeriod().getClass(); if (this.timePeriodClass == null) { this.timePeriodClass = periodClass; } else if (!this.timePeriodClass.equals(periodClass)) { String msg = "You are trying to add data where the time " + "period class is " + periodClass.getName() + ", but the TimeSeries is expecting an instance of " + this.timePeriodClass.getName() + "."; throw new SeriesException(msg); } TimeSeriesDataItem overwritten = null; int index = Collections.binarySearch(this.data, item); if (index >= 0) { TimeSeriesDataItem existing = (TimeSeriesDataItem) this.data.get(index); overwritten = (TimeSeriesDataItem) existing.clone(); // figure out if we need to iterate through all the y-values // to find the revised minY / maxY boolean iterate = false; Number oldYN = existing.getValue(); double oldY = oldYN != null ? oldYN.doubleValue() : Double.NaN; if (!Double.isNaN(oldY)) { iterate = oldY <= this.minY || oldY >= this.maxY; } existing.setValue(item.getValue()); if (iterate) { updateMinMaxYByIteration(); } else if (item.getValue() != null) { double yy = item.getValue().doubleValue(); this.minY = minIgnoreNaN(this.minY, yy); this.maxY = maxIgnoreNaN(this.maxY, yy); } } else { item = (TimeSeriesDataItem) item.clone(); this.data.add(-index - 1, item); updateBoundsForAddedItem(item); // check if this addition will exceed the maximum item count... if (getItemCount() > this.maximumItemCount) { TimeSeriesDataItem d = (TimeSeriesDataItem) this.data.remove(0); updateBoundsForRemovedItem(d); } } removeAgedItems(false); // remove old items if necessary, but // don't notify anyone, because that // happens next anyway... fireSeriesChanged(); return overwritten; }