Skip to content

Instantly share code, notes, and snippets.

@michalbcz
Last active October 8, 2015 08:27
Show Gist options
  • Save michalbcz/0c90bfb5cdc806db8ef4 to your computer and use it in GitHub Desktop.
Save michalbcz/0c90bfb5cdc806db8ef4 to your computer and use it in GitHub Desktop.
private void test(List<ExchangeRate> exchangeRates) {
Map<String, ExchangeRate> rateType11Map = new HashMap<String, ExchangeRate>();
Map<String, ExchangeRate> rateType12Map = new HashMap<String, ExchangeRate>();
Collections.sort(exchangeRates, new Comparator<ExchangeRate>() {
@Override
public int compare(ExchangeRate e1, ExchangeRate e2) {
return ComparisonChain.start()
.compare(e1.getRateCurrency(), e2.getRateCurrency())
.compare(e1.getRateType(), e2.getRateType())
.result();
}
});
for (ExchangeRate exchangeRate : exchangeRates) {
String rateCurrency = exchangeRate.getRateCurrency();
if (rateType11Map.containsKey(rateCurrency)) {
rateType12Map.put(rateCurrency, exchangeRate);
} else {
rateType11Map.put(rateCurrency, exchangeRate);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment