package info.limpet.impl;

import info.limpet.ICommand;

import java.util.List;

import javax.measure.unit.Unit;

import org.eclipse.january.dataset.DatasetFactory;
import org.eclipse.january.dataset.DoubleDataset;
import org.eclipse.january.dataset.IDataset;

public class NumberDocumentBuilder extends
    CoreDocumentBuilder<Double, NumberDocument>
{
  private final Unit<?> _type;
  private Range _range;

  public NumberDocumentBuilder(final String name, final Unit<?> valueUnits,
      final ICommand predecessor, final Unit<?> indexUnits)
  {
    super(name, predecessor, indexUnits);
    _type = valueUnits;
  }

  @Override
  protected void finishOff(final NumberDocument res)
  {
    super.finishOff(res);

    res.setRange(_range);
  }

  @Override
  protected IDataset getDataset(final List<Double> values)
  {
    final Double[] arr = values.toArray(new Double[]
    {});
    return DatasetFactory.createFromObject(DoubleDataset.class, arr, null);
  }

  @Override
  protected NumberDocument getDocument(final IDataset dataset,
      final ICommand _predecessor2)
  {
    return new NumberDocument((DoubleDataset) dataset, _predecessor2, _type);
  }

  public void setRange(final Range range)
  {
    _range = range;
  }
}

@@ -372,20 +372,21 @@
 nit%3C?%3E _
-type
+units
 ;%0A  priv
@@ -591,20 +591,21 @@
 );%0A    _
-type
+units
  = value
@@ -1057,17 +1057,16 @@
 Command 
-_
 predeces
@@ -1068,17 +1068,16 @@
 decessor
-2
 )%0A  %7B%0A  
@@ -1129,17 +1129,16 @@
 ataset, 
-_
 predeces
@@ -1144,16 +1144,16 @@
 ssor
-2
 , _
-type
+units
 );%0A 

fix member name so it remains consistent with previous xstream data format