From d5c1c54aa5241bd082b44c50efdfc73652ef6fb6 Mon Sep 17 00:00:00 2001 From: Lubomir Torok Date: Sat, 3 Oct 2020 21:42:06 +0200 Subject: [PATCH 1/2] Added date to CryptoUnit --- .../response/CryptoResponse.java | 5 ++++- .../cryptocurrency/response/CryptoUnit.java | 18 ++++++++++++++++-- src/test/java/crypto/CryptoUnitTest.java | 2 ++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/crazzyghost/alphavantage/cryptocurrency/response/CryptoResponse.java b/src/main/java/com/crazzyghost/alphavantage/cryptocurrency/response/CryptoResponse.java index 8af5515..4c2624e 100644 --- a/src/main/java/com/crazzyghost/alphavantage/cryptocurrency/response/CryptoResponse.java +++ b/src/main/java/com/crazzyghost/alphavantage/cryptocurrency/response/CryptoResponse.java @@ -78,8 +78,10 @@ public CryptoResponse parse(Map metaDataMap, Map cryptoUnits = new ArrayList<>(); - for (Map m: units.values()) { + for (String key : units.keySet()){ + Map m = units.get(key); CryptoUnit.Builder cryptoUnit = new CryptoUnit.Builder(); + cryptoUnit.date(key); cryptoUnit.open(Double.parseDouble(m.get("1a. open (" + market + ")" ))); cryptoUnit.high(Double.parseDouble(m.get("2a. high (" + market + ")" ))); cryptoUnit.low(Double.parseDouble(m.get("3a. low (" + market + ")" ))); @@ -92,6 +94,7 @@ public CryptoResponse parse(Map metaDataMap, Map Date: Wed, 7 Oct 2020 21:22:12 +0200 Subject: [PATCH 2/2] Changed iteration from Keys to Entries --- .../cryptocurrency/response/CryptoResponse.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/crazzyghost/alphavantage/cryptocurrency/response/CryptoResponse.java b/src/main/java/com/crazzyghost/alphavantage/cryptocurrency/response/CryptoResponse.java index 4c2624e..4085c5f 100644 --- a/src/main/java/com/crazzyghost/alphavantage/cryptocurrency/response/CryptoResponse.java +++ b/src/main/java/com/crazzyghost/alphavantage/cryptocurrency/response/CryptoResponse.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import com.crazzyghost.alphavantage.parser.DefaultParser; import com.crazzyghost.alphavantage.parser.Parser; @@ -78,10 +79,10 @@ public CryptoResponse parse(Map metaDataMap, Map cryptoUnits = new ArrayList<>(); - for (String key : units.keySet()){ - Map m = units.get(key); + for (Entry> entry : units.entrySet()){ + Map m = entry.getValue(); CryptoUnit.Builder cryptoUnit = new CryptoUnit.Builder(); - cryptoUnit.date(key); + cryptoUnit.date(entry.getKey()); cryptoUnit.open(Double.parseDouble(m.get("1a. open (" + market + ")" ))); cryptoUnit.high(Double.parseDouble(m.get("2a. high (" + market + ")" ))); cryptoUnit.low(Double.parseDouble(m.get("3a. low (" + market + ")" )));