More on #679 : convert UPC-E to A before getting check digit

This commit is contained in:
Sean Owen 2016-10-01 08:48:55 -05:00
parent aa0ee28cec
commit c219e28d56
No known key found for this signature in database
GPG key ID: F6CE9695C9318406
2 changed files with 10 additions and 2 deletions

View file

@ -173,7 +173,10 @@ public final class UPCEReader extends UPCEANReader {
result.append(lastChar);
break;
}
result.append(upce.charAt(7));
// Only append check digit in conversion if supplied
if (upce.length() >= 8) {
result.append(upce.charAt(7));
}
return result.toString();
}

View file

@ -56,7 +56,7 @@ public final class UPCEWriter extends UPCEANWriter {
// No check digit present, calculate it and add it
int check;
try {
check = UPCEANReader.getStandardUPCEANChecksum(contents);
check = UPCEANReader.getStandardUPCEANChecksum(UPCEReader.convertUPCEtoUPCA(contents));
} catch (FormatException fe) {
throw new IllegalArgumentException(fe);
}
@ -75,6 +75,11 @@ public final class UPCEWriter extends UPCEANWriter {
throw new IllegalArgumentException(
"Requested contents should be 8 digits long, but got " + length);
}
int firstDigit = Character.digit(contents.charAt(0), 10);
if (firstDigit != 0 && firstDigit != 1) {
throw new IllegalArgumentException("Number system must be 0 or 1");
}
int checkDigit = Character.digit(contents.charAt(7), 10);
int parities = UPCEReader.CHECK_DIGIT_ENCODINGS[checkDigit];