MCPcopy Create free account
hub / github.com/DiUS/java-faker / gtin8

Method gtin8

src/main/java/com/github/javafaker/Code.java:195–207  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

193 }
194
195 public String gtin8() {
196 char[] values = faker.regexify("\\d{7}").toCharArray();
197 int sum = 0;
198 for (int i = 0; i < values.length; i++) {
199 sum += Character.getNumericValue(values[i]) * GTIN_8_CHECK_DIGITS[i];
200 }
201 int checkDigit = 10 - sum % 10;
202 if (checkDigit == 10) {
203 return new String(ArrayUtils.add(values, Character.forDigit(0, 10)));
204 } else {
205 return new String(ArrayUtils.add(values, Character.forDigit(checkDigit, 10)));
206 }
207 }
208
209 public String ean13() {
210 return gtin13();

Callers 1

ean8Method · 0.95

Calls 2

addMethod · 0.80
regexifyMethod · 0.45

Tested by

no test coverage detected