-
Notifications
You must be signed in to change notification settings - Fork 225
Use java.util.Currency in currency related fakers #1118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0c28391
Deprecate Currency faker
panilya f700fa9
Use java.util.Currency in Money faker, delete money.yml
panilya 80a3854
Use java.util.Currency in Country faker in currency related methods
panilya 1ebe497
Changed 2.3.0 to 2.2.0, and removed newly introduced but deprecated m…
bodiam 849ec70
Updated test
bodiam ee591ef
Updated 2.3.0 to 2.2.0
bodiam f75ef0d
resolve comments
panilya cdf2aec
Reuse Money faker in Country faker for currency related generation
panilya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,65 @@ | ||
| package net.datafaker.providers.base; | ||
|
|
||
| import java.util.Currency; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Support for different kind of money currencies. | ||
| * | ||
| * @since 1.5.0 | ||
| */ | ||
| public class Money extends AbstractProvider<BaseProviders> { | ||
|
|
||
| private final List<Currency> availableCurrencies; | ||
|
|
||
| public Money(BaseProviders faker) { | ||
| super(faker); | ||
| this.availableCurrencies = List.copyOf(Currency.getAvailableCurrencies()); | ||
| } | ||
|
|
||
| /** | ||
| * This method returns a currency value in a more descriptive manner like "United States dollar", etc. | ||
| * | ||
| * @see Currency#getDisplayName() | ||
| * @return detailed currency value. | ||
| */ | ||
| public String currency() { | ||
| return resolve("money.currency"); | ||
| return getRandomCurrency().getDisplayName(); | ||
| } | ||
|
|
||
| /** | ||
| * Method returns a randomly generated currency value like EUR, USD, etc. | ||
| * Returns a random ISO 4217 currency code (ex. EUR, USD) | ||
| * | ||
| * @return currency code. | ||
| * @see Currency#getCurrencyCode() | ||
| * @return an ISO 4217 currency code | ||
| */ | ||
| public String currencyCode() { | ||
| return resolve("money.code"); | ||
| return getRandomCurrency().getCurrencyCode(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the 3-digit ISO 4217 numeric code of a random currency. | ||
| * | ||
| * @see Currency#getNumericCodeAsString() | ||
| * @return an ISO 4217 currency numeric code | ||
| * @since 2.2.0 | ||
| */ | ||
| public String currencyNumericCode() { | ||
| return getRandomCurrency().getNumericCodeAsString(); | ||
| } | ||
|
|
||
| /** | ||
| * @see Currency#getSymbol() | ||
| * @return an ISO 4217 currency symbol | ||
| * @since 2.2.0 | ||
| */ | ||
| public String currencySymbol() { | ||
| return getRandomCurrency().getSymbol(); | ||
| } | ||
|
|
||
| private Currency getRandomCurrency() { | ||
| int randomIndex = faker.random().nextInt(availableCurrencies.size()); | ||
| return availableCurrencies.get(randomIndex); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.