Use java.util.Currency in currency related fakers#1118
Conversation
PR Summary
|
snuyanzin
left a comment
There was a problem hiding this comment.
I tend to think that if we remove money.yml then we need to remove it from
net.datafaker.service.files.EnFile as well
+1 Also how about making deprecated |
-1. There's no such constructor to turn a Set into a List. |
I'm not sure if something changed in the meantime, but there's hardly any code in Currency, which duplicate code do you mean? |
in fact there is such, e.g. here this.availableCurrencies = new ArrayList<>(Currency.getAvailableCurrencies());and it could be replaced with (since we don't need mutable collection here it would be the advatage) this.availableCurrencies = List.copyOf(Currency.getAvailableCurrencies());May be public String name() {
return resolve("currency.name");
}which does the same or almost the same thing as public String currencyCode() {
int randomIndex = faker.random().nextInt(availableCurrencies.size());
return availableCurrencies.get(randomIndex).getCurrencyCode();
} |
Sure, but that Currency thing is going to be deleted one day anyway, does it matter much? It's a genuine question, I'm just wondering if that should hold up this PR, that's all. |
|
Ok for |
I agree about duplicate code and will push the fix soon. I thought about this (duplicate code or reuse Money faker) when I first implemented these changes, but I thought it might be better to not reuse Money (don't remember exactly the reason why I thought so, sorry). But it is better to reuse Money, indeed. Thank you all for reviewing. |
Don't know, but we have these methods for years (one is from 2019, the other from 2022). And at least the currency codes are now gone from the YML, and these currency codes in money.yml and country.yml were only half duplicated. At least now they're in sync. Small bit of duplication; we could remove one of the methods, or have one of them call the other. Or we leave them like they are. I lean towards leaving them like they are, but if there's good arguments for a different approach, I'm fine with that too. Ideally I don't want to break the API too much, Currency being a bit of an exception perhaps. |
|
RE: Duplication for my two cents these are basically all the same: They could be genericized to a single method that gets the index and accept a function to execute. ...or something like that. I haven't actually sat with an editor and tried/looked at it, that's just off the top of my head. |
snuyanzin
left a comment
There was a problem hiding this comment.
Thanks for addressing feedback
Issue: #1112