@@ -99,7 +99,11 @@ public IMFRateProvider() throws MalformedURLException {
9999 super (CONTEXT );
100100 LoaderService loader = Bootstrap .getService (LoaderService .class );
101101 loader .addLoaderListener (this , DATA_ID );
102- loader .loadDataAsync (DATA_ID );
102+ try {
103+ loader .loadData (DATA_ID );
104+ } catch (IOException e ) {
105+ LOGGER .log (Level .WARNING , "Error loading initial data from IMF provider..." , e );
106+ }
103107 }
104108
105109 @ Override
@@ -154,7 +158,7 @@ private void loadRatesTSV(InputStream inputStream) throws IOException, ParseExce
154158 String [] parts = line .split ("\\ t" );
155159 CurrencyUnit currency = currenciesByName .get (parts [0 ]);
156160 if (Objects .isNull (currency )) {
157- LOGGER .warning ( "Unknown currency from, IMF data feed: " + parts [0 ]);
161+ LOGGER .finest (() -> "Uninterpretable data from IMF data feed: " + parts [0 ]);
158162 line = pr .readLine ();
159163 continue ;
160164 }
@@ -173,24 +177,16 @@ private void loadRatesTSV(InputStream inputStream) throws IOException, ParseExce
173177 rateType = RateType .DEFERRED ;
174178 }
175179 if (currencyToSdr ) { // Currency -> SDR
176- List <ExchangeRate > rates = this .currencyToSdr .get (currency );
177- if (Objects .isNull (rates )) {
178- rates = new ArrayList <>(5 );
179- newCurrencyToSdr .put (currency , rates );
180- }
181180 ExchangeRate rate = new ExchangeRateBuilder (
182181 ConversionContextBuilder .create (CONTEXT , rateType ).setTimestampMillis (toTS ).build ())
183- .setBase (currency ).setTerm (SDR ).setFactor (new DefaultNumberValue (values [i ])).build ();
182+ .setBase (currency ).setTerm (SDR ).setFactor (new DefaultNumberValue (1d / values [i ])).build ();
183+ List <ExchangeRate > rates = newCurrencyToSdr .computeIfAbsent (currency , c -> new ArrayList <>(5 ));
184184 rates .add (rate );
185185 } else { // SDR -> Currency
186- List <ExchangeRate > rates = this .sdrToCurrency .get (currency );
187- if (Objects .isNull (rates )) {
188- rates = new ArrayList <>(5 );
189- newSdrToCurrency .put (currency , rates );
190- }
191186 ExchangeRate rate = new ExchangeRateBuilder (
192187 ConversionContextBuilder .create (CONTEXT , rateType ).setTimestampMillis (fromTS ).build ())
193- .setBase (SDR ).setTerm (currency ).setFactor (DefaultNumberValue .of (values [i ])).build ();
188+ .setBase (SDR ).setTerm (currency ).setFactor (DefaultNumberValue .of (1d / values [i ])).build ();
189+ List <ExchangeRate > rates = newSdrToCurrency .computeIfAbsent (currency , (c ) -> new ArrayList <>(5 ));
194190 rates .add (rate );
195191 }
196192 }
@@ -201,6 +197,8 @@ private void loadRatesTSV(InputStream inputStream) throws IOException, ParseExce
201197 newCurrencyToSdr .values ().forEach ((c ) -> Collections .sort (List .class .cast (c )));
202198 this .sdrToCurrency = newSdrToCurrency ;
203199 this .currencyToSdr = newCurrencyToSdr ;
200+ this .sdrToCurrency .forEach ((c , l ) -> LOGGER .finest (() -> "SDR -> " + c .getCurrencyCode () + ": " + l ));
201+ this .currencyToSdr .forEach ((c , l ) -> LOGGER .finest (() -> c .getCurrencyCode () + " -> SDR: " + l ));
204202 }
205203
206204 private Double [] parseValues (NumberFormat f , String [] parts ) throws ParseException {
0 commit comments