package uk.ac.eeci;

import java.time.Duration;
import java.util.Optional;

public class Environment {

    private final TimeSeries<Double> temperatureTimeSeries;
    private int index = 0;

    public Environment(TimeSeries<Double> temperatureTimeSeries, Duration timeStepSize) {
        this.temperatureTimeSeries = temperatureTimeSeries;
        Optional<Duration> inferredTimeStepSize = this.temperatureTimeSeries.getConstantTimeStepSize();
        if (!inferredTimeStepSize.isPresent() || !inferredTimeStepSize.get().equals(timeStepSize)) {
            String msg = String.format(
                    "The temperature time series must have a constant time step size of size %s.",
                    timeStepSize
            );
            throw new IllegalArgumentException(msg);
        }
    }

    public void step() {
        this.index += 1;
    }

    public double getCurrentTemperature() {
        return temperatureTimeSeries.getValues().get(this.index);
    }
}

@@ -182,12 +182,47 @@
 ndex
- = 0
+;%0A    private double currentTemperature
 ;%0A%0A 
@@ -833,59 +833,264 @@
     
-%7D%0A%0A    public void step() %7B%0A        this.index += 1
+    this.index = 0;%0A        this.currentTemperature = this.temperatureTimeSeries.get(this.index).getValue1();%0A%0A    %7D%0A%0A    public void step() %7B%0A        this.index += 1;%0A        this.currentTemperature = this.temperatureTimeSeries.get(this.index).getValue1()
 ;%0A  
@@ -1158,56 +1158,30 @@
 rn t
-emperatureTimeSeries.getValues().get(this.index)
+his.currentTemperature
 ;%0A  

Refactor temperature retrieval