/**
  * Returns the x-value for the specified series and item.
  *
  * @param series the series (zero-based index).
  * @param item the item (zero-based index).
  * @return The x-value for the specified series and item.
  */
 @Override
 public Number getX(int series, int item) {
   TimePeriodValues ts = (TimePeriodValues) this.data.get(series);
   TimePeriodValue dp = ts.getDataItem(item);
   TimePeriod period = dp.getPeriod();
   return new Long(getX(period));
 }
 /** Recalculates the bounds for the collection of items. */
 private void recalculateBounds() {
   this.minStartIndex = -1;
   this.minMiddleIndex = -1;
   this.minEndIndex = -1;
   this.maxStartIndex = -1;
   this.maxMiddleIndex = -1;
   this.maxEndIndex = -1;
   for (int i = 0; i < this.data.size(); i++) {
     TimePeriodValue tpv = (TimePeriodValue) this.data.get(i);
     updateBounds(tpv.getPeriod(), i);
   }
 }
 /**
  * Adds a data item to the series and sends a {@link SeriesChangeEvent} to all registered
  * listeners.
  *
  * @param item the item (<code>null</code> not permitted).
  */
 public void add(TimePeriodValue item) {
   if (item == null) {
     throw new IllegalArgumentException("Null item not allowed.");
   }
   this.data.add(item);
   updateBounds(item.getPeriod(), this.data.size() - 1);
   fireSeriesChanged();
 }
  /**
   * Creates a new instance by copying a subset of the data in this collection.
   *
   * @param start the index of the first item to copy.
   * @param end the index of the last item to copy.
   * @return A copy of a subset of the items.
   * @throws CloneNotSupportedException if there is a cloning problem.
   */
  public TimePeriodValues createCopy(int start, int end) throws CloneNotSupportedException {

    TimePeriodValues copy = (TimePeriodValues) super.clone();

    copy.data = new ArrayList();
    if (this.data.size() > 0) {
      for (int index = start; index <= end; index++) {
        TimePeriodValue item = (TimePeriodValue) this.data.get(index);
        TimePeriodValue clone = (TimePeriodValue) item.clone();
        try {
          copy.add(clone);
        } catch (SeriesException e) {
          System.err.println("Failed to add cloned item.");
        }
      }
    }
    return copy;
  }
 /**
  * Updates (changes) the value of a data item and sends a {@link SeriesChangeEvent} to all
  * registered listeners.
  *
  * @param index the index of the data item to update.
  * @param value the new value (<code>null</code> not permitted).
  */
 public void update(int index, Number value) {
   TimePeriodValue item = getDataItem(index);
   item.setValue(value);
   fireSeriesChanged();
 }
 /**
  * Returns the y-value for the specified series and item.
  *
  * @param series the series (zero-based index).
  * @param item the item (zero-based index).
  * @return The y-value for the specified series and item.
  */
 @Override
 public Number getY(int series, int item) {
   TimePeriodValues ts = (TimePeriodValues) this.data.get(series);
   TimePeriodValue dp = ts.getDataItem(item);
   return dp.getValue();
 }
 /**
  * Returns the ending X value for the specified series and item.
  *
  * @param series the series (zero-based index).
  * @param item the item (zero-based index).
  * @return The ending X value for the specified series and item.
  */
 @Override
 public Number getEndX(int series, int item) {
   TimePeriodValues ts = (TimePeriodValues) this.data.get(series);
   TimePeriodValue dp = ts.getDataItem(item);
   return new Long(dp.getPeriod().getEnd().getTime());
 }