Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/main/java/com/github/javafaker/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ public String lastName() {
}

public String latitude() {
return String.format("%.8g", (faker.random().nextDouble() * 180) - 90);
return String.format("%.8g", faker.random().nextDouble() * 180 - 90);
}

public String longitude() {
return String.format("%.8g", (faker.random().nextDouble() * 360) - 180);
return String.format("%.8g", faker.random().nextDouble() * 360 - 180);
}

public String timeZone() {
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/com/github/javafaker/Code.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,29 +118,28 @@ public String isbn13(boolean separator) {
return separator ? isbn13.toString() : stripIsbnSeparator(isbn13);
}

private final int isbn10CheckDigit(CharSequence t) {
private int isbn10CheckDigit(CharSequence t) {
String value = stripIsbnSeparator(t);
int sum = 0;
for (int i = 0; i < value.length(); i++) {
sum += ((i + 1) * toInt(value.substring(i, i + 1)));
sum += (i + 1) * toInt(value.substring(i, i + 1));
}
return sum % 11;
}
}

private final int isbn13CheckDigit(CharSequence t) {
private int isbn13CheckDigit(CharSequence t) {
String value = stripIsbnSeparator(t);
int sum = 0;
int multiplier = 0;
for (int i = 0; i < value.length(); i++) {
multiplier = i % 2 == 0 ? 1 : 3;
sum += multiplier * toInt(value.subSequence(i, i + 1).toString());
}

return (10 - sum % 10) % 10;
return sum % 10;
}

private final String stripIsbnSeparator(CharSequence t) {
return t.toString().replaceAll("-","");
private String stripIsbnSeparator(CharSequence t) {
return t.toString().replaceAll("-", "");
}

public String asin() {
Expand Down Expand Up @@ -180,7 +179,7 @@ public String imei() {
}

// Choose the last digit so that it causes the entire string to pass the checksum.
str[len - 1] = Character.forDigit(((10 - (sum % 10)) % 10), 10);
str[len - 1] = Character.forDigit((10 - (sum % 10)) % 10, 10);

return new String(str);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/github/javafaker/Color.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public String hex() {

public String hex(boolean includeHashSign) {
String hexString = faker.random().hex(6);
if(includeHashSign)
if(includeHashSign) {
return "#" + hexString;
}
return hexString;
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/github/javafaker/Company.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import static org.apache.commons.lang3.StringUtils.join;

Expand Down Expand Up @@ -79,7 +80,7 @@ public String url() {
}

private String domainName(){
return StringUtils.deleteWhitespace(name().toLowerCase().replaceAll(",", "").replaceAll("'", ""));
return StringUtils.deleteWhitespace(name().toLowerCase(Locale.ROOT).replaceAll(",", "").replaceAll("'", ""));
}

private String domainSuffix() {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/github/javafaker/File.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.javafaker;

import java.util.Locale;

public class File {
private final Faker faker;

Expand All @@ -22,7 +24,7 @@ public String fileName() {
public String fileName(String dirOrNull, String nameOrNull, String extensionOrNull, String separatorOrNull) {
final String sep = separatorOrNull == null ? System.getProperty("file.separator") : separatorOrNull;
final String dir = dirOrNull == null ? faker.internet().slug() : dirOrNull;
final String name = nameOrNull == null ? faker.lorem().word().toLowerCase() : nameOrNull;
final String name = nameOrNull == null ? faker.lorem().word().toLowerCase(Locale.ROOT) : nameOrNull;
final String ext = extensionOrNull == null ? extension() : extensionOrNull;
return dir + sep + name + "." + ext;
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/github/javafaker/Finance.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Locale;

public class Finance {
private final Faker faker;
Expand All @@ -20,7 +21,7 @@ protected Finance(Faker faker) {
createCountryCodeToBasicBankAccountNumberPatternMap();

public String creditCard(CreditCardType creditCardType) {
final String key = String.format("finance.credit_card.%s", creditCardType.toString().toLowerCase());
final String key = String.format("finance.credit_card.%s", creditCardType.toString().toLowerCase(Locale.ROOT));
String value = faker.fakeValuesService().resolve(key, this, faker);
final String template = faker.numerify(value);

Expand All @@ -35,7 +36,7 @@ public String creditCard(CreditCardType creditCardType) {
int luhnSum = 0;
int multiplier = 1;
for (Integer digit : reversedAsInt) {
multiplier = (multiplier == 2 ? 1 : 2);
multiplier = multiplier == 2 ? 1 : 2;
luhnSum += sum(String.valueOf(digit * multiplier).split(""));
}
int luhnDigit = (10 - (luhnSum % 10)) % 10;
Expand Down Expand Up @@ -84,7 +85,7 @@ private static String calculateIbanChecksum(String countryCode, String basicBank
String basis = basicBankAccountNumber + countryCode + "00";

StringBuilder sb = new StringBuilder();
char[] characters = basis.toLowerCase().toCharArray();
char[] characters = basis.toLowerCase(Locale.ROOT).toCharArray();
for (char c : characters) {
if (Character.isLetter(c)) {
sb.append(String.valueOf((c - 'a') + 10));
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/github/javafaker/Internet.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.Locale;

import static org.apache.commons.lang3.StringUtils.join;
import static org.apache.commons.lang3.StringUtils.stripAccents;
Expand Down Expand Up @@ -43,7 +44,7 @@ public String domainName() {
}

public String domainWord() {
return FakerIDN.toASCII(faker.name().lastName().toLowerCase().replaceAll("'", ""));
return FakerIDN.toASCII(faker.name().lastName().toLowerCase(Locale.ROOT).replaceAll("'", ""));
}

public String domainSuffix() {
Expand All @@ -55,7 +56,7 @@ public String url() {
"www",
".",
FakerIDN.toASCII(
faker.name().firstName().toLowerCase().replaceAll("'", "") +
faker.name().firstName().toLowerCase(Locale.ROOT).replaceAll("'", "") +
"-" +
domainWord()
),
Expand Down Expand Up @@ -85,7 +86,9 @@ public String avatar() {
*/
public String image() {
String[] dimension = StringUtils.split(faker.fakeValuesService().resolve("internet.image_dimension", this, faker), 'x');
if (dimension.length == 0) return "";
if (dimension.length == 0) {
return "";
}
return image(
Integer.valueOf(StringUtils.trim(dimension[0])), Integer.valueOf(StringUtils.trim(dimension[1])),
faker.bool().bool(), null);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/github/javafaker/Name.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.javafaker;

import org.apache.commons.lang3.StringUtils;
import java.util.Locale;

public class Name {

Expand Down Expand Up @@ -122,9 +123,9 @@ public String title() {
public String username() {

String username = StringUtils.join(
firstName().replaceAll("'", "").toLowerCase(),
firstName().replaceAll("'", "").toLowerCase(Locale.ROOT),
".",
lastName().replaceAll("'", "").toLowerCase()
lastName().replaceAll("'", "").toLowerCase(Locale.ROOT)
);

return StringUtils.deleteWhitespace(username);
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/github/javafaker/Number.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public int randomDigitNotZero() {
* @see Number#numberBetween(long, long)
*/
public int numberBetween(int min, int max) {
if (min == max) return min;
if (min == max){
return min;x
}

int value = decimalBetween(min,max).setScale(0, BigDecimal.ROUND_HALF_DOWN).intValue();
return value == max ? value - 1 : value;
Expand All @@ -42,7 +44,9 @@ public int numberBetween(int min, int max) {
* @param max exclusive (unless min == max)
*/
public long numberBetween(long min, long max) {
if (min == max) return min;
if (min == max) {
return min;
}

long value = decimalBetween(min, max).setScale(0, BigDecimal.ROUND_HALF_DOWN).longValue();
return value == max ? value - 1 : value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ private int calculateChecksum(String number) {
String calculatedNumber = calculateDigits(dateString + birthNumber);
int sum = calculateDigitSum(calculatedNumber);

int lastDigit = (sum % 10);
int lastDigit = sum % 10;
int difference = 10 - lastDigit;

return (difference % 10);
return difference % 10;
}

private String calculateDigits(String numbers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Locale;

public class FakeValuesService {

Expand Down Expand Up @@ -157,7 +158,9 @@ public String fetchString(String key) {
@SuppressWarnings("unchecked")
public String safeFetch(String key, String defaultIfNull) {
Object o = fetchObject(key);
if (o == null) return defaultIfNull;
if (o == null) {
return defaultIfNull;
}
if (o instanceof List) {
List<String> values = (List<String>) o;
if (values.size() == 0) {
Expand Down Expand Up @@ -278,7 +281,7 @@ public String letterify(String letterString) {
* @return
*/
public String letterify(String letterString, boolean isUpper) {
return letterHelper((isUpper) ? 65 : 97, letterString); // from ascii table
return letterHelper(isUpper ? 65 : 97, letterString); // from ascii table
}

private String letterHelper(int baseChar, String letterString) {
Expand Down Expand Up @@ -456,7 +459,7 @@ private String classNameToYamlName(Object current) {
private String javaNameToYamlName(String expression) {
return expression.replaceAll("([A-Z])", "_$1")
.substring(1)
.toLowerCase();
.toLowerCase(Locale.ROOT);
}


Expand Down