Skip to content

Commit 7c92031

Browse files
committed
use faker.options() to pick element from list
... instead of re-implementing this method every time.
1 parent e4c04a9 commit 7c92031

5 files changed

Lines changed: 11 additions & 15 deletions

File tree

src/main/java/net/datafaker/providers/base/Finance.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ public String bic() {
134134
*/
135135
public String iban() {
136136
List<String> countryCodes = new ArrayList<>(countryCodeToBasicBankAccountNumberPattern.keySet());
137-
String randomCountryCode = countryCodes.get(faker.random().nextInt(countryCodes.size()));
138-
return iban(randomCountryCode);
137+
String countryCode = faker.options().nextElement(countryCodes);
138+
return iban(countryCode);
139139
}
140140

141141
/**

src/main/java/net/datafaker/providers/base/Nation.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package net.datafaker.providers.base;
22

3-
import java.nio.charset.Charset;
4-
import java.nio.charset.StandardCharsets;
53
import java.util.Locale;
64

75
/**
86
* @since 0.8.0
97
*/
108
public class Nation extends AbstractProvider<BaseProviders> {
11-
12-
private static final Charset UTF8_CHARSET = StandardCharsets.UTF_8;
9+
private static final String[] isoLanguages = Locale.getISOLanguages();
10+
private static final String[] isoCountries = Locale.getISOCountries();
1311

1412
protected Nation(BaseProviders faker) {
1513
super(faker);
@@ -32,12 +30,10 @@ public String flag() {
3230
}
3331

3432
public String isoLanguage() {
35-
String[] isoLangs = Locale.getISOLanguages();
36-
return isoLangs[faker.random().nextInt(isoLangs.length)];
33+
return faker.options().option(isoLanguages);
3734
}
3835

3936
public String isoCountry() {
40-
String[] isoCountries = Locale.getISOCountries();
41-
return isoCountries[faker.random().nextInt(isoCountries.length)];
37+
return faker.options().option(isoCountries);
4238
}
4339
}

src/main/java/net/datafaker/providers/base/Relationship.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public String sibling() {
4949
}
5050

5151
public String any() {
52-
Kind kind = faker.options().option(Kind.values());
52+
Kind kind = faker.options().option(Kind.class);
5353
return resolve(kind.expression);
5454
}
5555

src/main/java/net/datafaker/providers/base/Shakespeare.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public String romeoAndJulietQuote() {
7979
}
8080

8181
private String randomElement(String[] values) {
82-
return values[faker.random().nextInt(values.length)];
82+
return faker.options().option(values);
8383
}
8484

8585
}

src/main/java/net/datafaker/providers/base/Sip.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ public int messagingPort() {
5353
* @return an RTP UDP 5 digit port int, e.g. 40002.
5454
*/
5555
public int rtpPort() {
56-
return portPool[faker.random().nextInt(portPool.length)];
56+
return faker.options().option(portPool);
5757
}
5858

5959
/**
60-
* Proviosional code, the various response codes are listed in
60+
* Provisional code, the various response codes are listed in
6161
* <a href="https://en.wikipedia.org/wiki/List_of_SIP_response_codes">https://en.wikipedia.org/wiki/List_of_SIP_response_codes</a>.
6262
*
6363
* @return a 3 digit SIP provision response code between 100 and 199 int, e.g. {@code 180}.
@@ -117,7 +117,7 @@ public int globalErrorResponseCode() {
117117
}
118118

119119
/**
120-
* Proviosional phrase, the various response phrases are listed in
120+
* Provisional phrase, the various response phrases are listed in
121121
* <a href="https://en.wikipedia.org/wiki/List_of_SIP_response_codes">https://en.wikipedia.org/wiki/List_of_SIP_response_codes</a>.
122122
*
123123
* @return a SIP provisional response phrase String, e.g. {@code Ringing}.

0 commit comments

Comments
 (0)