public UPCParsedResult(String rawText) {
super(ParsedReaderResultType.UPC);
- if (rawText.length() != 12) {
+ if (rawText.length() != 12 && rawText.length() != 13) {
throw new IllegalArgumentException("Wrong number of digits for UPC");
}
- for (int x = 0; x < 12; x++) {
+ for (int x = 0; x < rawText.length(); x++) {
char c = rawText.charAt(x);
if (c < '0' || c > '9') {
throw new IllegalArgumentException("Invalid character found in UPC");
}
int checksum = 0;
- int end = result.length()-2;
+ int end = result.length() - 2;
int factor = 3;
// Calculate from penultimate digit down to first. This avoids having to
// account for the optional '0' on the front, which won't actually affect
// the calculation.
for (int i = end; i >= 0; i--) {
- int value = (result.charAt(i) - (int) '0') * factor;
+ int value = (result.charAt(i) - (int)'0') * factor;
checksum += value;
factor = factor == 3 ? 1 : 3;
}
- int endValue = (result.charAt(end+1) - (int) '0');
+ int endValue = (result.charAt(end + 1) - (int)'0');
//Log("checksum + endValue = " + (checksum + endValue));
return (checksum + endValue) % 10 == 0;
}
private int decodeOneSide(BitArray rowData, int rowOffset, boolean checkBothParities) {
int[] counters = new int[4];
byte firstDigitPattern = 0;
+ CharResult foundChar = new CharResult();
for (int x = 0; x < 6 && rowOffset < width; x++) {
recordPattern(rowData, rowOffset, counters, 4);
for (int y = 0; y < 4; y++) {
rowOffset += counters[y];
}
- CharResult foundChar = new CharResult();
findDigit(counters, foundChar, checkBothParities);
if (foundChar.parity == UNKNOWN_PARITY) {
return -1;
char firstDigit = '-';
for (int i = 0; i < FIRST_DIGIT_ENCODINGS.length; i++) {
if (firstDigitPattern == FIRST_DIGIT_ENCODINGS[i]) {
- firstDigit = (char) ((int) '0' + i);
+ firstDigit = (char)((int)'0' + i);
break;
}
}
}
if (match) {
result.parity = ODD_PARITY;
- result.character = (char) ((int) '0' + x);
+ result.character = (char)((int)'0' + x);
return;
}
}
}
if (match) {
result.parity = EVEN_PARITY;
- result.character = (char) ((int) '0' + x);
+ result.character = (char)((int)'0' + x);
return;
}
}