package weatherhandler.data;

import java.util.List;
import java.util.LinkedList;
import java.util.Map;
import java.util.HashMap;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;

import weatherhandler.database.Database;

public class MeasurementsCache {
    private static Map<Integer, List<Measurement>> cache = new HashMap<>();

    public static void init() throws SQLException {
        Statement st = Database.getConnection().createStatement();
        ResultSet rs = st.executeQuery("SELECT id FROM stations");
        while (rs.next()) {
            int station = rs.getInt(1);
            // TODO use a custom List class that also updates averages for every
            // data point whenever a new Measurement is added
            cache.put(station, new LinkedList<Measurement>());
        }
    }

    public static List<Measurement> getCache(Integer station) {
        return cache.get(station);
    }
}

@@ -127,93 +127,45 @@
 ap;%0A
+%0A
 import 
-java.sql.ResultSet;%0Aimport java.sql.Statement;%0Aimport java.sql.SQLExcep
+weatherhandler.data.Sta
 tion;%0A
-%0A
 impo
@@ -190,21 +190,17 @@
 data
-base.Database
+.Stations
 ;%0A%0Ap
@@ -342,231 +342,66 @@
 t() 
-throws SQLException %7B%0A        Statement st = Database.getConnection().createStatement();%0A        ResultSet rs = st.executeQuery(%22SELECT id FROM stations%22);%0A        while (rs.next()) %7B%0A            int station = rs.getInt(1);
+%7B%0A        for (Station station : Stations.getStations()) %7B
 %0A   
@@ -569,16 +569,24 @@
 (station
+.getID()
 , new Li

Use loaded Stations in MeasurementsCache