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

Method isbn13CheckDigit

src/main/java/com/github/javafaker/Code.java:130–140  ·  view source on GitHub ↗
(CharSequence t)

Source from the content-addressed store, hash-verified

128 }
129
130 private final int isbn13CheckDigit(CharSequence t) {
131 String value = stripIsbnSeparator(t);
132 int sum = 0;
133 int multiplier = 0;
134 for (int i = 0; i < value.length(); i++) {
135 multiplier = i % 2 == 0 ? 1 : 3;
136 sum += multiplier * toInt(value.subSequence(i, i + 1).toString());
137 }
138
139 return (10 - sum % 10) % 10;
140 }
141
142 private final String stripIsbnSeparator(CharSequence t) {
143 return t.toString().replaceAll("-","");

Callers 1

isbn13Method · 0.95

Calls 2

stripIsbnSeparatorMethod · 0.95
toStringMethod · 0.80

Tested by

no test coverage detected