/**
 * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
 * 
 * Please see distribution for license.
 */
package com.opengamma.analytics.financial.timeseries.returns;

import java.util.Iterator;
import java.util.Map.Entry;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opengamma.timeseries.TimeSeriesException;
import com.opengamma.timeseries.fast.integer.FastIntDoubleTimeSeries;
import com.opengamma.timeseries.localdate.LocalDateDoubleTimeSeries;
import com.opengamma.util.CalculationMode;

/**
 * 
 */
public class SimpleNetRelativeTimeSeriesReturnCalculator extends RelativeTimeSeriesReturnCalculator {
  private static final Logger s_logger = LoggerFactory.getLogger(SimpleNetRelativeTimeSeriesReturnCalculator.class);
  private static final double ZERO = 1e-12;

  public SimpleNetRelativeTimeSeriesReturnCalculator(final CalculationMode mode) {
    super(mode);
  }

  @Override
  public LocalDateDoubleTimeSeries evaluate(final LocalDateDoubleTimeSeries... x) {
    testInputData(x);
    if (x.length > 2) {
      s_logger.info("Have more than two time series in array; only using first two");
    }
    final FastIntDoubleTimeSeries ts1 = x[0].toFastIntDoubleTimeSeries();
    final FastIntDoubleTimeSeries ts2 = x[1].toFastIntDoubleTimeSeries();
    final int n = ts1.size();
    final int[] times = new int[n];
    final double[] returns = new double[n];
    final Iterator<Entry<Integer, Double>> iter1 = ts1.iterator();
    Entry<Integer, Double> entry1;
    Double value2;
    int t;
    int i = 0;
    while (iter1.hasNext()) {
      entry1 = iter1.next();
      t = entry1.getKey();
      value2 = ts2.getValue(t);
      if (value2 == null || Math.abs(value2) < ZERO) {
        if (getMode().equals(CalculationMode.STRICT)) {
          throw new TimeSeriesException("No data in second series for time " + t);
        }
      } else {
        times[i] = entry1.getKey();
        returns[i++] = (entry1.getValue() / value2 - 1);
      }
    }
    return getSeries(x[0], times, returns, i);
  }
}

@@ -206,56 +206,25 @@
 ort 
-java.util.Iterator;%0Aimport java.util.Map.Entry;%0A
+org.slf4j.Logger;
 %0Aimp
@@ -235,32 +235,39 @@
 org.slf4j.Logger
+Factory
 ;%0Aimport org.slf
@@ -263,35 +263,37 @@
 ort org.
-slf4j.LoggerFactory
+threeten.bp.LocalDate
 ;%0A%0Aimpor
@@ -376,44 +376,41 @@
 ies.
-fast.integer.FastIntDoubleTimeSeries
+localdate.LocalDateDoubleIterator
 ;%0Aim
@@ -1137,39 +1137,41 @@
     %7D%0A    final 
-FastInt
+LocalDate
 DoubleTimeSeries
@@ -1185,36 +1185,8 @@
 x%5B0%5D
-.toFastIntDoubleTimeSeries()
 ;%0A  
@@ -1193,23 +1193,25 @@
   final 
-FastInt
+LocalDate
 DoubleTi
@@ -1233,36 +1233,8 @@
 x%5B1%5D
-.toFastIntDoubleTimeSeries()
 ;%0A  
@@ -1355,128 +1355,54 @@
 nal 
-Iterator%3CEntry%3CInteger, Double%3E%3E iter1 = ts1.iterator();%0A    Entry%3CInteger, Double%3E entry1;%0A    Double value2;%0A    int t
+LocalDateDoubleIterator iter1 = ts1.iterator()
 ;%0A  
@@ -1450,22 +1450,27 @@
 %7B%0A      
-entry1
+LocalDate t
  = iter1
@@ -1478,35 +1478,17 @@
 next
-();%0A      t = entry1.getKey
+LocalDate
 ();%0A
@@ -1493,16 +1493,23 @@
 ;%0A      
+Double 
 value2 =
@@ -1768,21 +1768,25 @@
 %5D = 
-entry1.getKey
+iter1.currentDate
 ();%0A
@@ -1813,17 +1813,20 @@
  = (
-entry1.ge
+iter1.curren
 tVal
@@ -1910,10 +1910,11 @@
 i);%0A  %7D%0A
+%0A
 %7D%0A

Use direct date-based iterator