List of usage examples for org.jfree.data.time TimeSeries getTimePeriod
public RegularTimePeriod getTimePeriod(int index)
From source file:org.jfree.data.time.TimeSeriesCollection.java
/** * Returns the bounds of the domain values for the specified series. * * @param visibleSeriesKeys a list of keys for the visible series. * @param includeInterval include the x-interval? * * @return A range.//w w w . ja v a 2 s.c om * * @since 1.0.13 */ @Override public Range getDomainBounds(List visibleSeriesKeys, boolean includeInterval) { Range result = null; Iterator iterator = visibleSeriesKeys.iterator(); while (iterator.hasNext()) { Comparable seriesKey = (Comparable) iterator.next(); TimeSeries series = getSeries(seriesKey); int count = series.getItemCount(); if (count > 0) { RegularTimePeriod start = series.getTimePeriod(0); RegularTimePeriod end = series.getTimePeriod(count - 1); Range temp; if (!includeInterval) { temp = new Range(getX(start), getX(end)); } else { temp = new Range(start.getFirstMillisecond(this.workingCalendar), end.getLastMillisecond(this.workingCalendar)); } result = Range.combine(result, temp); } } return result; }
From source file:org.jfree.data.time.TimeSeriesCollection.java
/** * Returns the range of the values in this dataset's domain. * * @param includeInterval a flag that determines whether or not the * x-interval is taken into account. * * @return The range.//from ww w. java 2 s. c o m */ @Override public Range getDomainBounds(boolean includeInterval) { Range result = null; Iterator iterator = this.data.iterator(); while (iterator.hasNext()) { TimeSeries series = (TimeSeries) iterator.next(); int count = series.getItemCount(); if (count > 0) { RegularTimePeriod start = series.getTimePeriod(0); RegularTimePeriod end = series.getTimePeriod(count - 1); Range temp; if (!includeInterval) { temp = new Range(getX(start), getX(end)); } else { temp = new Range(start.getFirstMillisecond(this.workingCalendar), end.getLastMillisecond(this.workingCalendar)); } result = Range.combine(result, temp); } } return result; }
From source file:org.jfree.data.time.junit.TimeSeriesTest.java
/** * Some tests to ensure that the createCopy(int, int) method is * functioning correctly./*from w w w . j a v a2 s. c o m*/ */ public void testCreateCopy2() { TimeSeries series = new TimeSeries("Series"); series.add(new Month(MonthConstants.JANUARY, 2003), 45.0); series.add(new Month(MonthConstants.FEBRUARY, 2003), 55.0); series.add(new Month(MonthConstants.JUNE, 2003), 35.0); series.add(new Month(MonthConstants.NOVEMBER, 2003), 85.0); series.add(new Month(MonthConstants.DECEMBER, 2003), 75.0); try { // copy just the first item... TimeSeries result1 = series.createCopy(0, 0); assertEquals(new Month(1, 2003), result1.getTimePeriod(0)); // copy the first two items... result1 = series.createCopy(0, 1); assertEquals(new Month(2, 2003), result1.getTimePeriod(1)); // copy the middle three items... result1 = series.createCopy(1, 3); assertEquals(new Month(2, 2003), result1.getTimePeriod(0)); assertEquals(new Month(11, 2003), result1.getTimePeriod(2)); // copy the last two items... result1 = series.createCopy(3, 4); assertEquals(new Month(11, 2003), result1.getTimePeriod(0)); assertEquals(new Month(12, 2003), result1.getTimePeriod(1)); // copy the last item... result1 = series.createCopy(4, 4); assertEquals(new Month(12, 2003), result1.getTimePeriod(0)); } catch (CloneNotSupportedException e) { assertTrue(false); } // check negative first argument boolean pass = false; try { /* TimeSeries result = */ series.createCopy(-1, 1); } catch (IllegalArgumentException e) { pass = true; } catch (CloneNotSupportedException e) { pass = false; } assertTrue(pass); // check second argument less than first argument pass = false; try { /* TimeSeries result = */ series.createCopy(1, 0); } catch (IllegalArgumentException e) { pass = true; } catch (CloneNotSupportedException e) { pass = false; } assertTrue(pass); TimeSeries series2 = new TimeSeries("Series 2"); try { TimeSeries series3 = series2.createCopy(99, 999); assertEquals(0, series3.getItemCount()); } catch (CloneNotSupportedException e) { assertTrue(false); } }
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * Some tests to ensure that the createCopy(int, int) method is * functioning correctly.//from w w w . java2 s. co m */ @Test public void testCreateCopy2() { TimeSeries series = new TimeSeries("Series", Month.class); series.add(new Month(MonthConstants.JANUARY, 2003), 45.0); series.add(new Month(MonthConstants.FEBRUARY, 2003), 55.0); series.add(new Month(MonthConstants.JUNE, 2003), 35.0); series.add(new Month(MonthConstants.NOVEMBER, 2003), 85.0); series.add(new Month(MonthConstants.DECEMBER, 2003), 75.0); try { // copy just the first item... TimeSeries result1 = series.createCopy(0, 0); assertEquals(new Month(1, 2003), result1.getTimePeriod(0)); // copy the first two items... result1 = series.createCopy(0, 1); assertEquals(new Month(2, 2003), result1.getTimePeriod(1)); // copy the middle three items... result1 = series.createCopy(1, 3); assertEquals(new Month(2, 2003), result1.getTimePeriod(0)); assertEquals(new Month(11, 2003), result1.getTimePeriod(2)); // copy the last two items... result1 = series.createCopy(3, 4); assertEquals(new Month(11, 2003), result1.getTimePeriod(0)); assertEquals(new Month(12, 2003), result1.getTimePeriod(1)); // copy the last item... result1 = series.createCopy(4, 4); assertEquals(new Month(12, 2003), result1.getTimePeriod(0)); } catch (CloneNotSupportedException e) { assertTrue(false); } // check negative first argument boolean pass = false; try { /* TimeSeries result = */ series.createCopy(-1, 1); } catch (IllegalArgumentException e) { pass = true; } catch (CloneNotSupportedException e) { pass = false; } assertTrue(pass); // check second argument less than first argument pass = false; try { /* TimeSeries result = */ series.createCopy(1, 0); } catch (IllegalArgumentException e) { pass = true; } catch (CloneNotSupportedException e) { pass = false; } assertTrue(pass); TimeSeries series2 = new TimeSeries("Series 2"); try { TimeSeries series3 = series2.createCopy(99, 999); assertEquals(0, series3.getItemCount()); } catch (CloneNotSupportedException e) { assertTrue(false); } }
From source file:org.jfree.data.time.junit.TimeSeriesTest.java
/** * Some checks for the delete(int, int) method. */// w ww . j a v a 2 s . c om public void testDelete3() { TimeSeries s1 = new TimeSeries("S1"); s1.add(new Year(2011), 1.1); s1.add(new Year(2012), 2.2); s1.add(new Year(2013), 3.3); s1.add(new Year(2014), 4.4); s1.add(new Year(2015), 5.5); s1.add(new Year(2016), 6.6); s1.delete(2, 5); assertEquals(2, s1.getItemCount()); assertEquals(new Year(2011), s1.getTimePeriod(0)); assertEquals(new Year(2012), s1.getTimePeriod(1)); assertEquals(1.1, s1.getMinY(), EPSILON); assertEquals(2.2, s1.getMaxY(), EPSILON); }
From source file:org.jfree.data.time.TimeSeriesTest.java
/** * Some checks for the delete(int, int) method. *///from w w w . ja v a 2 s . c om @Test public void testDelete3() { TimeSeries s1 = new TimeSeries("S1"); s1.add(new Year(2011), 1.1); s1.add(new Year(2012), 2.2); s1.add(new Year(2013), 3.3); s1.add(new Year(2014), 4.4); s1.add(new Year(2015), 5.5); s1.add(new Year(2016), 6.6); s1.delete(2, 5); assertEquals(2, s1.getItemCount()); assertEquals(new Year(2011), s1.getTimePeriod(0)); assertEquals(new Year(2012), s1.getTimePeriod(1)); assertEquals(1.1, s1.getMinY(), EPSILON); assertEquals(2.2, s1.getMaxY(), EPSILON); }
From source file:org.jfree.data.time.TimeSeries.java
/** * Returns a collection of time periods in the specified series, but not in * this series, and therefore unique to the specified series. * * @param series the series to check against this one. * * @return The unique time periods.//from ww w . j av a2 s . c o m */ public Collection getTimePeriodsUniqueToOtherSeries(TimeSeries series) { Collection result = new java.util.ArrayList(); for (int i = 0; i < series.getItemCount(); i++) { RegularTimePeriod period = series.getTimePeriod(i); int index = getIndex(period); if (index < 0) { result.add(period); } } return result; }
From source file:info.financialecology.finance.utilities.datastruct.VersatileTimeSeriesCollection.java
/** * Ensure that all time series have identical time stamps. This uses the method {@code compareTo()} of * the class {@link RegularTimePeriod}. {@link RegularTimePeriod} is an abstract class subclassed * by classes {@code Day, FixedMillisecond, Hour, Millisecond, Minute, Month, Quarter, Second, Week, Year}. * // w ww .j a v a 2 s .com * @return true if all time series in the collection have identical time stamps */ public Boolean checkConsistency() { int numTs = this.getSeriesCount(); Assertion.assertOrKill(numTs > 0, "Cannot use method checkConsistency() for empty time series collection"); if (numTs == 1) return true; // just one time series? TimeSeries baseTs = this.getSeries(0); // the base time series with which all others in this collection are compared for (int i = 1; i < this.getSeriesCount(); i++) { TimeSeries ts = this.getSeries(i); if (ts.getItemCount() != baseTs.getItemCount()) return false; // different lengths? for (int t = 0; t < ts.getItemCount(); t++) // check all time stamps if (ts.getTimePeriod(t).compareTo(baseTs.getTimePeriod(t)) != 0) return false; } return true; }