/** * Get a LocalDate field (converted from a String internally). Throws a QuandlRuntimeException if * it cannot find the field * * @param fieldName the name of the field * @return the field value, or null if the field is null */ public LocalDate getLocalDate(final String fieldName) { try { if (_jsonObject.isNull(fieldName)) { return null; } else { return LocalDate.parse(_jsonObject.getString(fieldName), DATE_FORMATTER); } } catch (JSONException ex) { throw new QuandlRuntimeException("Cannot find field", ex); } }
public void basicOperation() { NonVersionedRedisHistoricalTimeSeriesSource source = new NonVersionedRedisHistoricalTimeSeriesSource(getJedisPool(), getRedisPrefix()); UniqueId id1 = UniqueId.of("Test", "1"); UniqueId id2 = UniqueId.of("Test", "2"); UniqueId id3 = UniqueId.of("Test", "3"); source.setTimeSeriesPoint(id1, LocalDate.parse("2013-06-04"), 14.0); source.setTimeSeriesPoint(id1, LocalDate.parse("2013-06-05"), 15.0); source.setTimeSeriesPoint(id1, LocalDate.parse("2013-06-06"), 16.0); source.setTimeSeriesPoint(id1, LocalDate.parse("2013-06-07"), 17.0); source.setTimeSeriesPoint(id1, LocalDate.parse("2013-06-08"), 18.0); source.setTimeSeriesPoint(id2, LocalDate.parse("2013-06-04"), 24.0); source.setTimeSeriesPoint(id2, LocalDate.parse("2013-06-05"), 25.0); source.setTimeSeriesPoint(id2, LocalDate.parse("2013-06-06"), 26.0); source.setTimeSeriesPoint(id2, LocalDate.parse("2013-06-07"), 27.0); source.setTimeSeriesPoint(id2, LocalDate.parse("2013-06-08"), 28.0); source.setTimeSeriesPoint(id3, LocalDate.parse("2013-06-04"), 34.0); source.setTimeSeriesPoint(id3, LocalDate.parse("2013-06-05"), 35.0); source.setTimeSeriesPoint(id3, LocalDate.parse("2013-06-06"), 36.0); source.setTimeSeriesPoint(id3, LocalDate.parse("2013-06-07"), 37.0); source.setTimeSeriesPoint(id3, LocalDate.parse("2013-06-08"), 38.0); Pair<LocalDate, Double> pair = null; HistoricalTimeSeries hts = null; LocalDateDoubleTimeSeries ts = null; pair = source.getLatestDataPoint(id3); assertNotNull(pair); assertEquals(LocalDate.parse("2013-06-08"), pair.getFirst()); assertEquals(38.0, pair.getSecond(), 0.000001); assertNull(source.getHistoricalTimeSeries(UniqueId.of("Test", "5"))); hts = source.getHistoricalTimeSeries(id2); assertNotNull(hts); assertEquals(id2, hts.getUniqueId()); ts = hts.getTimeSeries(); assertNotNull(ts); assertEquals(5, ts.size()); assertEquals(24.0, ts.getValue(LocalDate.parse("2013-06-04")), 0.00001); assertEquals(25.0, ts.getValue(LocalDate.parse("2013-06-05")), 0.00001); assertEquals(26.0, ts.getValue(LocalDate.parse("2013-06-06")), 0.00001); assertEquals(27.0, ts.getValue(LocalDate.parse("2013-06-07")), 0.00001); assertEquals(28.0, ts.getValue(LocalDate.parse("2013-06-08")), 0.00001); hts = source.getHistoricalTimeSeries( ExternalIdBundle.of(ExternalId.of("Test", "1")), LocalDate.now(), "Data Source", "Data Provider", "Data Field"); assertNotNull(hts); assertEquals(id1, hts.getUniqueId()); ts = hts.getTimeSeries(); assertNotNull(ts); assertEquals(5, ts.size()); assertEquals(14.0, ts.getValue(LocalDate.parse("2013-06-04")), 0.00001); assertEquals(15.0, ts.getValue(LocalDate.parse("2013-06-05")), 0.00001); assertEquals(16.0, ts.getValue(LocalDate.parse("2013-06-06")), 0.00001); assertEquals(17.0, ts.getValue(LocalDate.parse("2013-06-07")), 0.00001); assertEquals(18.0, ts.getValue(LocalDate.parse("2013-06-08")), 0.00001); }
@Override public LocalDate fromNonNullValue(String s) { return LocalDate.parse(s); }