Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/main/java/net/datafaker/providers/base/Country.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,20 @@ public String capital() {
return resolve("country.capital");
}

/**
* @see Money#currency()
* @return a random detailed ISO 4217 currency display name
*/
public String currency() {
return resolve("country.currency");
return faker.money().currency();
}

/**
* @see Money#currencyCode()
* @return an ISO 4217 currency code
*/
public String currencyCode() {
return resolve("country.currency_code");
return faker.money().currencyCode();
}

public String name() {
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/net/datafaker/providers/base/Currency.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,31 @@

/**
* @since 0.8.0
* @deprecated since 2.2.0. For removal in 3.0.0 version. This faker is deprecated due to the existence
* of duplicate {@link Money} faker with similar methods. Use {@link Money} instead.
*/
@Deprecated(since = "2.2.0", forRemoval = true)
public class Currency extends AbstractProvider<BaseProviders> {

public Currency(BaseProviders faker) {
super(faker);
}

/**
* @deprecated since 2.2.0. For removal in 3.0.0 version. Use {@link Money#currency} instead.
*/
@Deprecated(since = "2.2.0", forRemoval = true)
public String name() {
return resolve("currency.name");
}

/**
* @deprecated since 2.2.0. For removal in 3.0.0 version. Use {@link Money#currencyCode()} instead.
* @return an alphabetic currency code (ex. USD)
*/
@Deprecated(since = "2.2.0", forRemoval = true)
public String code() {
return resolve("currency.code");
}

/**
* <p>Returns an active ISO 4217 three-digit numeric currency code as of 1 April 2022</p>
*
* @return an ISO 4217 currency numeric code
* @since 2.2.0
*/
public String numericCode() {
return resolve("currency.numeric_code");
}

}
42 changes: 38 additions & 4 deletions src/main/java/net/datafaker/providers/base/Money.java
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);
}

}
1 change: 0 additions & 1 deletion src/main/java/net/datafaker/service/files/EnFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ public String getPath() {
"michael_scott.yml",
"military.yml",
"minecraft.yml",
"money.yml",
"money_heist.yml",
"most_interesting_man_in_the_world.yml",
"mood.yml",
Expand Down
Loading