InsituSource { public InsituRecord[] getValuesFor(String parameterName, GeoPos position) { final int columnIndex = getIndexForParameter(parameterName); final Iterable<Record> records = recordSource.getRecords(); final List<InsituRecord> parameterRecords = new ArrayList<InsituRecord>(); for (Record record : records) { final GeoPos pos = record.getLocation(); if (position != null && !pos.equals(position)) { continue; } final Date time = record.getTime(); final Double value = (Double) record.getAttributeValues()[columnIndex]; if (value == null) { continue; } final String stationName = record.getStationName() == null ? "" : record.getStationName(); final InsituRecord insituRecord = new InsituRecord(pos, time, stationName, value); parameterRecords.add(insituRecord); } sortRecordsAscending(parameterRecords); return parameterRecords.toArray(new InsituRecord[parameterRecords.size()]); } InsituSource(RecordSource recordSource); Collection<GeoPos> getInsituPositionsFor(String parameterName); InsituRecord[] getValuesFor(String parameterName, GeoPos position); boolean hasStationNames(); String[] getParameterNames(); String getNameFor(GeoPos geoPos); void close();  }
@Test public void testGetValuesForCHL_TimeOrdered() throws Exception { InsituRecord[] chlRecords = insituSource.getValuesFor("CHL", null); assertEquals(4, chlRecords.length); InsituRecord expectedRecord; expectedRecord = new InsituRecord(new GeoPos(20, 40), getDate("02.04.2003"), "Name 2", 0.5); assertEquals(expectedRecord, chlRecords[0]); expectedRecord = new InsituRecord(new GeoPos(20, 40), getDate("05.04.2003"), "Name 2", 0.6); assertEquals(expectedRecord, chlRecords[1]); expectedRecord = new InsituRecord(new GeoPos(10, 30), getDate("08.04.2003"), "Name 1", 0.9); assertEquals(expectedRecord, chlRecords[2]); expectedRecord = new InsituRecord(new GeoPos(20, 50), getDate("11.04.2003"), "Name 3", 0.4); assertEquals(expectedRecord, chlRecords[3]); }
@Test public void testGetValuesForYS_TimeOrdered() throws Exception { InsituRecord[] ysRecords = insituSource.getValuesFor("ys", null); assertEquals(4, ysRecords.length); InsituRecord expectedRecord; expectedRecord = new InsituRecord(new GeoPos(20, 40), getDate("02.04.2003"), "Name 2", 30); assertEquals(expectedRecord, ysRecords[0]); expectedRecord = new InsituRecord(new GeoPos(20, 40), getDate("05.04.2003"), "Name 2", 40); assertEquals(expectedRecord, ysRecords[1]); expectedRecord = new InsituRecord(new GeoPos(10, 30), getDate("08.04.2003"), "Name 1", 20); assertEquals(expectedRecord, ysRecords[2]); expectedRecord = new InsituRecord(new GeoPos(20, 50), getDate("11.04.2003"), "Name 3", 50); assertEquals(expectedRecord, ysRecords[3]); }
@Test public void testGetValuesForGeoPos() throws Exception { InsituRecord[] chlRecordsPos1 = insituSource.getValuesFor("ys", new GeoPos(20, 40)); InsituRecord[] chlRecordsPos2 = insituSource.getValuesFor("ys", new GeoPos(10, 30)); assertEquals(2, chlRecordsPos1.length); assertEquals(1, chlRecordsPos2.length); InsituRecord expectedRecord; expectedRecord = new InsituRecord(new GeoPos(20, 40), getDate("02.04.2003"), "Name 2", 30); assertEquals(expectedRecord, chlRecordsPos1[0]); expectedRecord = new InsituRecord(new GeoPos(20, 40), getDate("05.04.2003"), "Name 2", 40); assertEquals(expectedRecord, chlRecordsPos1[1]); expectedRecord = new InsituRecord(new GeoPos(10, 30), getDate("08.04.2003"), "Name 1", 20); assertEquals(expectedRecord, chlRecordsPos2[0]); }