Update deps including Guava 20; use switch in pref to chained if-else for slightly more consistent style

This commit is contained in:
Sean Owen 2016-11-11 20:20:46 +00:00
parent 995da03a39
commit 28f8bd37f3
No known key found for this signature in database
GPG key ID: F6CE9695C9318406
11 changed files with 422 additions and 327 deletions

View file

@ -82,10 +82,13 @@ public final class WifiConfigManager extends AsyncTask<WifiParsedResult,Object,O
} else { } else {
String password = theWifiResult.getPassword(); String password = theWifiResult.getPassword();
if (password != null && !password.isEmpty()) { if (password != null && !password.isEmpty()) {
if (networkType == NetworkType.WEP) { switch (networkType) {
changeNetworkWEP(wifiManager, theWifiResult); case WEP:
} else if (networkType == NetworkType.WPA) { changeNetworkWEP(wifiManager, theWifiResult);
changeNetworkWPA(wifiManager, theWifiResult); break;
case WPA:
changeNetworkWPA(wifiManager, theWifiResult);
break;
} }
} }
} }

View file

@ -146,39 +146,49 @@ final class DecodedBitStreamParser {
result.append('0'); result.append('0');
} }
result.append(value); result.append(value);
} else if (oneByte == 230) { // Latch to C40 encodation } else {
return Mode.C40_ENCODE; switch (oneByte) {
} else if (oneByte == 231) { // Latch to Base 256 encodation case 230: // Latch to C40 encodation
return Mode.BASE256_ENCODE; return Mode.C40_ENCODE;
} else if (oneByte == 232) { case 231: // Latch to Base 256 encodation
// FNC1 return Mode.BASE256_ENCODE;
result.append((char) 29); // translate as ASCII 29 case 232: // FNC1
} else if (oneByte == 233 || oneByte == 234) { result.append((char) 29); // translate as ASCII 29
// Structured Append, Reader Programming break;
// Ignore these symbols for now case 233: // Structured Append
//throw ReaderException.getInstance(); case 234: // Reader Programming
} else if (oneByte == 235) { // Upper Shift (shift to Extended ASCII) // Ignore these symbols for now
upperShift = true; //throw ReaderException.getInstance();
} else if (oneByte == 236) { // 05 Macro break;
result.append("[)>\u001E05\u001D"); case 235: // Upper Shift (shift to Extended ASCII)
resultTrailer.insert(0, "\u001E\u0004"); upperShift = true;
} else if (oneByte == 237) { // 06 Macro break;
result.append("[)>\u001E06\u001D"); case 236: // 05 Macro
resultTrailer.insert(0, "\u001E\u0004"); result.append("[)>\u001E05\u001D");
} else if (oneByte == 238) { // Latch to ANSI X12 encodation resultTrailer.insert(0, "\u001E\u0004");
return Mode.ANSIX12_ENCODE; break;
} else if (oneByte == 239) { // Latch to Text encodation case 237: // 06 Macro
return Mode.TEXT_ENCODE; result.append("[)>\u001E06\u001D");
} else if (oneByte == 240) { // Latch to EDIFACT encodation resultTrailer.insert(0, "\u001E\u0004");
return Mode.EDIFACT_ENCODE; break;
} else if (oneByte == 241) { // ECI Character case 238: // Latch to ANSI X12 encodation
// TODO(bbrown): I think we need to support ECI return Mode.ANSIX12_ENCODE;
//throw ReaderException.getInstance(); case 239: // Latch to Text encodation
// Ignore this symbol for now return Mode.TEXT_ENCODE;
} else if (oneByte >= 242) { // Not to be used in ASCII encodation case 240: // Latch to EDIFACT encodation
// ... but work around encoders that end with 254, latch back to ASCII return Mode.EDIFACT_ENCODE;
if (oneByte != 254 || bits.available() != 0) { case 241: // ECI Character
throw FormatException.getFormatInstance(); // TODO(bbrown): I think we need to support ECI
//throw ReaderException.getInstance();
// Ignore this symbol for now
break;
default:
// Not to be used in ASCII encodation
// but work around encoders that end with 254, latch back to ASCII
if (oneByte >= 242 && (oneByte != 254 || bits.available() != 0)) {
throw FormatException.getFormatInstance();
}
break;
} }
} }
} while (bits.available() > 0); } while (bits.available() > 0);
@ -245,12 +255,17 @@ final class DecodedBitStreamParser {
} else { } else {
result.append(c40char); result.append(c40char);
} }
} else if (cValue == 27) { // FNC1
result.append((char) 29); // translate as ASCII 29
} else if (cValue == 30) { // Upper Shift
upperShift = true;
} else { } else {
throw FormatException.getFormatInstance(); switch (cValue) {
case 27: // FNC1
result.append((char) 29); // translate as ASCII 29
break;
case 30: // Upper Shift
upperShift = true;
break;
default:
throw FormatException.getFormatInstance();
}
} }
shift = 0; shift = 0;
break; break;
@ -330,12 +345,17 @@ final class DecodedBitStreamParser {
} else { } else {
result.append(textChar); result.append(textChar);
} }
} else if (cValue == 27) { // FNC1
result.append((char) 29); // translate as ASCII 29
} else if (cValue == 30) { // Upper Shift
upperShift = true;
} else { } else {
throw FormatException.getFormatInstance(); switch (cValue) {
case 27: // FNC1
result.append((char) 29); // translate as ASCII 29
break;
case 30: // Upper Shift
upperShift = true;
break;
default:
throw FormatException.getFormatInstance();
}
} }
shift = 0; shift = 0;
break; break;
@ -383,20 +403,28 @@ final class DecodedBitStreamParser {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
int cValue = cValues[i]; int cValue = cValues[i];
if (cValue == 0) { // X12 segment terminator <CR> switch (cValue) {
result.append('\r'); case 0: // X12 segment terminator <CR>
} else if (cValue == 1) { // X12 segment separator * result.append('\r');
result.append('*'); break;
} else if (cValue == 2) { // X12 sub-element separator > case 1: // X12 segment separator *
result.append('>'); result.append('*');
} else if (cValue == 3) { // space break;
result.append(' '); case 2: // X12 sub-element separator >
} else if (cValue < 14) { // 0 - 9 result.append('>');
result.append((char) (cValue + 44)); break;
} else if (cValue < 40) { // A - Z case 3: // space
result.append((char) (cValue + 51)); result.append(' ');
} else { break;
throw FormatException.getFormatInstance(); default:
if (cValue < 14) { // 0 - 9
result.append((char) (cValue + 44));
} else if (cValue < 40) { // A - Z
result.append((char) (cValue + 51));
} else {
throw FormatException.getFormatInstance();
}
break;
} }
} }
} while (bits.available() > 0); } while (bits.available() > 0);

View file

@ -49,20 +49,28 @@ final class X12Encoder extends C40Encoder {
@Override @Override
int encodeChar(char c, StringBuilder sb) { int encodeChar(char c, StringBuilder sb) {
if (c == '\r') { switch (c) {
sb.append('\0'); case '\r':
} else if (c == '*') { sb.append('\0');
sb.append('\1'); break;
} else if (c == '>') { case '*':
sb.append('\2'); sb.append('\1');
} else if (c == ' ') { break;
sb.append('\3'); case '>':
} else if (c >= '0' && c <= '9') { sb.append('\2');
sb.append((char) (c - 48 + 4)); break;
} else if (c >= 'A' && c <= 'Z') { case ' ':
sb.append((char) (c - 65 + 14)); sb.append('\3');
} else { break;
HighLevelEncoder.illegalCharacter(c); default:
if (c >= '0' && c <= '9') {
sb.append((char) (c - 48 + 4));
} else if (c >= 'A' && c <= 'Z') {
sb.append((char) (c - 65 + 14));
} else {
HighLevelEncoder.illegalCharacter(c);
}
break;
} }
return 1; return 1;
} }

View file

@ -212,16 +212,16 @@ public final class Code128Writer extends OneDimensionalCodeWriter {
return CODE_CODE_B; // no choice return CODE_CODE_B; // no choice
} }
if (oldCode == CODE_CODE_C) { // can continue in code C if (oldCode == CODE_CODE_C) { // can continue in code C
return oldCode; return CODE_CODE_C;
} }
if (oldCode == CODE_CODE_B) { if (oldCode == CODE_CODE_B) {
if (lookahead == CType.FNC_1) { if (lookahead == CType.FNC_1) {
return oldCode; // can continue in code B return CODE_CODE_B; // can continue in code B
} }
// Seen two consecutive digits, see what follows // Seen two consecutive digits, see what follows
lookahead = findCType(value, start + 2); lookahead = findCType(value, start + 2);
if (lookahead == CType.UNCODABLE || lookahead == CType.ONE_DIGIT) { if (lookahead == CType.UNCODABLE || lookahead == CType.ONE_DIGIT) {
return oldCode; // not worth switching now return CODE_CODE_B; // not worth switching now
} }
if (lookahead == CType.FNC_1) { // two digits, then FNC_1... if (lookahead == CType.FNC_1) { // two digits, then FNC_1...
lookahead = findCType(value, start + 3); lookahead = findCType(value, start + 3);

View file

@ -173,33 +173,35 @@ final class DecodedBitStreamParser {
codeIndex = textCompaction(codewords, codeIndex, fileId); codeIndex = textCompaction(codewords, codeIndex, fileId);
resultMetadata.setFileId(fileId.toString()); resultMetadata.setFileId(fileId.toString());
if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) { switch (codewords[codeIndex]) {
codeIndex++; case BEGIN_MACRO_PDF417_OPTIONAL_FIELD:
int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex]; codeIndex++;
int additionalOptionCodeWordsIndex = 0; int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
int additionalOptionCodeWordsIndex = 0;
boolean end = false; boolean end = false;
while ((codeIndex < codewords[0]) && !end) { while ((codeIndex < codewords[0]) && !end) {
int code = codewords[codeIndex++]; int code = codewords[codeIndex++];
if (code < TEXT_COMPACTION_MODE_LATCH) { if (code < TEXT_COMPACTION_MODE_LATCH) {
additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code; additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = code;
} else { } else {
switch (code) { switch (code) {
case MACRO_PDF417_TERMINATOR: case MACRO_PDF417_TERMINATOR:
resultMetadata.setLastSegment(true); resultMetadata.setLastSegment(true);
codeIndex++; codeIndex++;
end = true; end = true;
break; break;
default: default:
throw FormatException.getFormatInstance(); throw FormatException.getFormatInstance();
}
} }
} }
} resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
break;
resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex)); case MACRO_PDF417_TERMINATOR:
} else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) { resultMetadata.setLastSegment(true);
resultMetadata.setLastSegment(true); codeIndex++;
codeIndex++; break;
} }
return codeIndex; return codeIndex;
@ -300,20 +302,27 @@ final class DecodedBitStreamParser {
// Upper case Alpha Character // Upper case Alpha Character
ch = (char) ('A' + subModeCh); ch = (char) ('A' + subModeCh);
} else { } else {
if (subModeCh == 26) { switch (subModeCh) {
ch = ' '; case 26:
} else if (subModeCh == LL) { ch = ' ';
subMode = Mode.LOWER; break;
} else if (subModeCh == ML) { case LL:
subMode = Mode.MIXED; subMode = Mode.LOWER;
} else if (subModeCh == PS) { break;
// Shift to punctuation case ML:
priorToShiftMode = subMode; subMode = Mode.MIXED;
subMode = Mode.PUNCT_SHIFT; break;
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) { case PS:
result.append((char) byteCompactionData[i]); // Shift to punctuation
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) { priorToShiftMode = subMode;
subMode = Mode.ALPHA; subMode = Mode.PUNCT_SHIFT;
break;
case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
result.append((char) byteCompactionData[i]);
break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA;
break;
} }
} }
break; break;
@ -323,23 +332,30 @@ final class DecodedBitStreamParser {
if (subModeCh < 26) { if (subModeCh < 26) {
ch = (char) ('a' + subModeCh); ch = (char) ('a' + subModeCh);
} else { } else {
if (subModeCh == 26) { switch (subModeCh) {
ch = ' '; case 26:
} else if (subModeCh == AS) { ch = ' ';
// Shift to alpha break;
priorToShiftMode = subMode; case AS:
subMode = Mode.ALPHA_SHIFT; // Shift to alpha
} else if (subModeCh == ML) { priorToShiftMode = subMode;
subMode = Mode.MIXED; subMode = Mode.ALPHA_SHIFT;
} else if (subModeCh == PS) { break;
// Shift to punctuation case ML:
priorToShiftMode = subMode; subMode = Mode.MIXED;
subMode = Mode.PUNCT_SHIFT; break;
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) { case PS:
// TODO Does this need to use the current character encoding? See other occurrences below // Shift to punctuation
result.append((char) byteCompactionData[i]); priorToShiftMode = subMode;
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) { subMode = Mode.PUNCT_SHIFT;
subMode = Mode.ALPHA; break;
case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
// TODO Does this need to use the current character encoding? See other occurrences below
result.append((char) byteCompactionData[i]);
break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA;
break;
} }
} }
break; break;
@ -349,22 +365,30 @@ final class DecodedBitStreamParser {
if (subModeCh < PL) { if (subModeCh < PL) {
ch = MIXED_CHARS[subModeCh]; ch = MIXED_CHARS[subModeCh];
} else { } else {
if (subModeCh == PL) { switch (subModeCh) {
subMode = Mode.PUNCT; case PL:
} else if (subModeCh == 26) { subMode = Mode.PUNCT;
ch = ' '; break;
} else if (subModeCh == LL) { case 26:
subMode = Mode.LOWER; ch = ' ';
} else if (subModeCh == AL) { break;
subMode = Mode.ALPHA; case LL:
} else if (subModeCh == PS) { subMode = Mode.LOWER;
// Shift to punctuation break;
priorToShiftMode = subMode; case AL:
subMode = Mode.PUNCT_SHIFT; subMode = Mode.ALPHA;
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) { break;
result.append((char) byteCompactionData[i]); case PS:
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) { // Shift to punctuation
subMode = Mode.ALPHA; priorToShiftMode = subMode;
subMode = Mode.PUNCT_SHIFT;
break;
case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
result.append((char) byteCompactionData[i]);
break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA;
break;
} }
} }
break; break;
@ -374,12 +398,16 @@ final class DecodedBitStreamParser {
if (subModeCh < PAL) { if (subModeCh < PAL) {
ch = PUNCT_CHARS[subModeCh]; ch = PUNCT_CHARS[subModeCh];
} else { } else {
if (subModeCh == PAL) { switch (subModeCh) {
subMode = Mode.ALPHA; case PAL:
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) { subMode = Mode.ALPHA;
result.append((char) byteCompactionData[i]); break;
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) { case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
subMode = Mode.ALPHA; result.append((char) byteCompactionData[i]);
break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA;
break;
} }
} }
break; break;
@ -390,10 +418,13 @@ final class DecodedBitStreamParser {
if (subModeCh < 26) { if (subModeCh < 26) {
ch = (char) ('A' + subModeCh); ch = (char) ('A' + subModeCh);
} else { } else {
if (subModeCh == 26) { switch (subModeCh) {
ch = ' '; case 26:
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) { ch = ' ';
subMode = Mode.ALPHA; break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA;
break;
} }
} }
break; break;
@ -404,14 +435,18 @@ final class DecodedBitStreamParser {
if (subModeCh < PAL) { if (subModeCh < PAL) {
ch = PUNCT_CHARS[subModeCh]; ch = PUNCT_CHARS[subModeCh];
} else { } else {
if (subModeCh == PAL) { switch (subModeCh) {
subMode = Mode.ALPHA; case PAL:
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) { subMode = Mode.ALPHA;
// PS before Shift-to-Byte is used as a padding character, break;
// see 5.4.2.4 of the specification case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
result.append((char) byteCompactionData[i]); // PS before Shift-to-Byte is used as a padding character,
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) { // see 5.4.2.4 of the specification
subMode = Mode.ALPHA; result.append((char) byteCompactionData[i]);
break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA;
break;
} }
} }
break; break;
@ -442,30 +477,85 @@ final class DecodedBitStreamParser {
int codeIndex, int codeIndex,
StringBuilder result) { StringBuilder result) {
ByteArrayOutputStream decodedBytes = new ByteArrayOutputStream(); ByteArrayOutputStream decodedBytes = new ByteArrayOutputStream();
if (mode == BYTE_COMPACTION_MODE_LATCH) { int count = 0;
// Total number of Byte Compaction characters to be encoded long value = 0;
// is not a multiple of 6 boolean end = false;
int count = 0;
long value = 0; switch (mode) {
int[] byteCompactedCodewords = new int[6]; case BYTE_COMPACTION_MODE_LATCH:
boolean end = false; // Total number of Byte Compaction characters to be encoded
int nextCode = codewords[codeIndex++]; // is not a multiple of 6
while ((codeIndex < codewords[0]) && !end) {
byteCompactedCodewords[count++] = nextCode; int[] byteCompactedCodewords = new int[6];
// Base 900 int nextCode = codewords[codeIndex++];
value = 900 * value + nextCode; while ((codeIndex < codewords[0]) && !end) {
nextCode = codewords[codeIndex++]; byteCompactedCodewords[count++] = nextCode;
// perhaps it should be ok to check only nextCode >= TEXT_COMPACTION_MODE_LATCH // Base 900
if (nextCode == TEXT_COMPACTION_MODE_LATCH || value = 900 * value + nextCode;
nextCode == BYTE_COMPACTION_MODE_LATCH || nextCode = codewords[codeIndex++];
nextCode == NUMERIC_COMPACTION_MODE_LATCH || // perhaps it should be ok to check only nextCode >= TEXT_COMPACTION_MODE_LATCH
nextCode == BYTE_COMPACTION_MODE_LATCH_6 || switch (nextCode) {
nextCode == BEGIN_MACRO_PDF417_CONTROL_BLOCK || case TEXT_COMPACTION_MODE_LATCH:
nextCode == BEGIN_MACRO_PDF417_OPTIONAL_FIELD || case BYTE_COMPACTION_MODE_LATCH:
nextCode == MACRO_PDF417_TERMINATOR) { case NUMERIC_COMPACTION_MODE_LATCH:
codeIndex--; case BYTE_COMPACTION_MODE_LATCH_6:
end = true; case BEGIN_MACRO_PDF417_CONTROL_BLOCK:
} else { case BEGIN_MACRO_PDF417_OPTIONAL_FIELD:
case MACRO_PDF417_TERMINATOR:
codeIndex--;
end = true;
break;
default:
if ((count % 5 == 0) && (count > 0)) {
// Decode every 5 codewords
// Convert to Base 256
for (int j = 0; j < 6; ++j) {
decodedBytes.write((byte) (value >> (8 * (5 - j))));
}
value = 0;
count = 0;
}
break;
}
}
// if the end of all codewords is reached the last codeword needs to be added
if (codeIndex == codewords[0] && nextCode < TEXT_COMPACTION_MODE_LATCH) {
byteCompactedCodewords[count++] = nextCode;
}
// If Byte Compaction mode is invoked with codeword 901,
// the last group of codewords is interpreted directly
// as one byte per codeword, without compaction.
for (int i = 0; i < count; i++) {
decodedBytes.write((byte) byteCompactedCodewords[i]);
}
break;
case BYTE_COMPACTION_MODE_LATCH_6:
// Total number of Byte Compaction characters to be encoded
// is an integer multiple of 6
while (codeIndex < codewords[0] && !end) {
int code = codewords[codeIndex++];
if (code < TEXT_COMPACTION_MODE_LATCH) {
count++;
// Base 900
value = 900 * value + code;
} else {
switch (code) {
case TEXT_COMPACTION_MODE_LATCH:
case BYTE_COMPACTION_MODE_LATCH:
case NUMERIC_COMPACTION_MODE_LATCH:
case BYTE_COMPACTION_MODE_LATCH_6:
case BEGIN_MACRO_PDF417_CONTROL_BLOCK:
case BEGIN_MACRO_PDF417_OPTIONAL_FIELD:
case MACRO_PDF417_TERMINATOR:
codeIndex--;
end = true;
break;
}
}
if ((count % 5 == 0) && (count > 0)) { if ((count % 5 == 0) && (count > 0)) {
// Decode every 5 codewords // Decode every 5 codewords
// Convert to Base 256 // Convert to Base 256
@ -476,54 +566,7 @@ final class DecodedBitStreamParser {
count = 0; count = 0;
} }
} }
} break;
// if the end of all codewords is reached the last codeword needs to be added
if (codeIndex == codewords[0] && nextCode < TEXT_COMPACTION_MODE_LATCH) {
byteCompactedCodewords[count++] = nextCode;
}
// If Byte Compaction mode is invoked with codeword 901,
// the last group of codewords is interpreted directly
// as one byte per codeword, without compaction.
for (int i = 0; i < count; i++) {
decodedBytes.write((byte) byteCompactedCodewords[i]);
}
} else if (mode == BYTE_COMPACTION_MODE_LATCH_6) {
// Total number of Byte Compaction characters to be encoded
// is an integer multiple of 6
int count = 0;
long value = 0;
boolean end = false;
while (codeIndex < codewords[0] && !end) {
int code = codewords[codeIndex++];
if (code < TEXT_COMPACTION_MODE_LATCH) {
count++;
// Base 900
value = 900 * value + code;
} else {
if (code == TEXT_COMPACTION_MODE_LATCH ||
code == BYTE_COMPACTION_MODE_LATCH ||
code == NUMERIC_COMPACTION_MODE_LATCH ||
code == BYTE_COMPACTION_MODE_LATCH_6 ||
code == BEGIN_MACRO_PDF417_CONTROL_BLOCK ||
code == BEGIN_MACRO_PDF417_OPTIONAL_FIELD ||
code == MACRO_PDF417_TERMINATOR) {
codeIndex--;
end = true;
}
}
if ((count % 5 == 0) && (count > 0)) {
// Decode every 5 codewords
// Convert to Base 256
for (int j = 0; j < 6; ++j) {
decodedBytes.write((byte) (value >> (8 * (5 - j))));
}
value = 0;
count = 0;
}
}
} }
result.append(new String(decodedBytes.toByteArray(), encoding)); result.append(new String(decodedBytes.toByteArray(), encoding));
return codeIndex; return codeIndex;
@ -552,14 +595,16 @@ final class DecodedBitStreamParser {
numericCodewords[count] = code; numericCodewords[count] = code;
count++; count++;
} else { } else {
if (code == TEXT_COMPACTION_MODE_LATCH || switch (code) {
code == BYTE_COMPACTION_MODE_LATCH || case TEXT_COMPACTION_MODE_LATCH:
code == BYTE_COMPACTION_MODE_LATCH_6 || case BYTE_COMPACTION_MODE_LATCH:
code == BEGIN_MACRO_PDF417_CONTROL_BLOCK || case BYTE_COMPACTION_MODE_LATCH_6:
code == BEGIN_MACRO_PDF417_OPTIONAL_FIELD || case BEGIN_MACRO_PDF417_CONTROL_BLOCK:
code == MACRO_PDF417_TERMINATOR) { case BEGIN_MACRO_PDF417_OPTIONAL_FIELD:
codeIndex--; case MACRO_PDF417_TERMINATOR:
end = true; codeIndex--;
end = true;
break;
} }
} }
if (count % MAX_NUMERIC_CODEWORDS == 0 || if (count % MAX_NUMERIC_CODEWORDS == 0 ||

View file

@ -269,8 +269,7 @@ public final class Detector {
int x = patternStart; int x = patternStart;
int counterPosition = 0; int counterPosition = 0;
int patternLength = pattern.length; int patternLength = pattern.length;
boolean isWhite = whiteFirst; for (boolean isWhite = whiteFirst; x < width; x++) {
for (; x < width; x++) {
boolean pixel = matrix.get(x, row); boolean pixel = matrix.get(x, row);
if (pixel ^ isWhite) { if (pixel ^ isWhite) {
counters[counterPosition]++; counters[counterPosition]++;

View file

@ -179,56 +179,58 @@ final class PDF417HighLevelEncoder {
int textSubMode = SUBMODE_ALPHA; int textSubMode = SUBMODE_ALPHA;
// User selected encoding mode // User selected encoding mode
if (compaction == Compaction.TEXT) { switch (compaction) {
encodeText(msg, p, len, sb, textSubMode); case TEXT:
encodeText(msg, p, len, sb, textSubMode);
} else if (compaction == Compaction.BYTE) { break;
byte[] bytes = msg.getBytes(encoding); case BYTE:
encodeBinary(bytes, p, bytes.length, BYTE_COMPACTION, sb); byte[] msgBytes = msg.getBytes(encoding);
encodeBinary(msgBytes, p, msgBytes.length, BYTE_COMPACTION, sb);
} else if (compaction == Compaction.NUMERIC) { break;
sb.append((char) LATCH_TO_NUMERIC); case NUMERIC:
encodeNumeric(msg, p, len, sb); sb.append((char) LATCH_TO_NUMERIC);
encodeNumeric(msg, p, len, sb);
} else { break;
int encodingMode = TEXT_COMPACTION; //Default mode, see 4.4.2.1 default:
while (p < len) { int encodingMode = TEXT_COMPACTION; //Default mode, see 4.4.2.1
int n = determineConsecutiveDigitCount(msg, p); while (p < len) {
if (n >= 13) { int n = determineConsecutiveDigitCount(msg, p);
sb.append((char) LATCH_TO_NUMERIC); if (n >= 13) {
encodingMode = NUMERIC_COMPACTION; sb.append((char) LATCH_TO_NUMERIC);
textSubMode = SUBMODE_ALPHA; //Reset after latch encodingMode = NUMERIC_COMPACTION;
encodeNumeric(msg, p, n, sb); textSubMode = SUBMODE_ALPHA; //Reset after latch
p += n; encodeNumeric(msg, p, n, sb);
} else { p += n;
int t = determineConsecutiveTextCount(msg, p);
if (t >= 5 || n == len) {
if (encodingMode != TEXT_COMPACTION) {
sb.append((char) LATCH_TO_TEXT);
encodingMode = TEXT_COMPACTION;
textSubMode = SUBMODE_ALPHA; //start with submode alpha after latch
}
textSubMode = encodeText(msg, p, t, sb, textSubMode);
p += t;
} else { } else {
int b = determineConsecutiveBinaryCount(msg, p, encoding); int t = determineConsecutiveTextCount(msg, p);
if (b == 0) { if (t >= 5 || n == len) {
b = 1; if (encodingMode != TEXT_COMPACTION) {
} sb.append((char) LATCH_TO_TEXT);
byte[] bytes = msg.substring(p, p + b).getBytes(encoding); encodingMode = TEXT_COMPACTION;
if (bytes.length == 1 && encodingMode == TEXT_COMPACTION) { textSubMode = SUBMODE_ALPHA; //start with submode alpha after latch
//Switch for one byte (instead of latch) }
encodeBinary(bytes, 0, 1, TEXT_COMPACTION, sb); textSubMode = encodeText(msg, p, t, sb, textSubMode);
p += t;
} else { } else {
//Mode latch performed by encodeBinary() int b = determineConsecutiveBinaryCount(msg, p, encoding);
encodeBinary(bytes, 0, bytes.length, encodingMode, sb); if (b == 0) {
encodingMode = BYTE_COMPACTION; b = 1;
textSubMode = SUBMODE_ALPHA; //Reset after latch }
byte[] bytes = msg.substring(p, p + b).getBytes(encoding);
if (bytes.length == 1 && encodingMode == TEXT_COMPACTION) {
//Switch for one byte (instead of latch)
encodeBinary(bytes, 0, 1, TEXT_COMPACTION, sb);
} else {
//Mode latch performed by encodeBinary()
encodeBinary(bytes, 0, bytes.length, encodingMode, sb);
encodingMode = BYTE_COMPACTION;
textSubMode = SUBMODE_ALPHA; //Reset after latch
}
p += b;
} }
p += b;
} }
} }
} break;
} }
return sb.toString(); return sb.toString();

View file

@ -71,11 +71,15 @@ final class DecodedBitStreamParser {
} else { } else {
mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits
} }
if (mode != Mode.TERMINATOR) { switch (mode) {
if (mode == Mode.FNC1_FIRST_POSITION || mode == Mode.FNC1_SECOND_POSITION) { case TERMINATOR:
break;
case FNC1_FIRST_POSITION:
case FNC1_SECOND_POSITION:
// We do little with FNC1 except alter the parsed result a bit according to the spec // We do little with FNC1 except alter the parsed result a bit according to the spec
fc1InEffect = true; fc1InEffect = true;
} else if (mode == Mode.STRUCTURED_APPEND) { break;
case STRUCTURED_APPEND:
if (bits.available() < 16) { if (bits.available() < 16) {
throw FormatException.getFormatInstance(); throw FormatException.getFormatInstance();
} }
@ -83,39 +87,45 @@ final class DecodedBitStreamParser {
// Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue // Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue
symbolSequence = bits.readBits(8); symbolSequence = bits.readBits(8);
parityData = bits.readBits(8); parityData = bits.readBits(8);
} else if (mode == Mode.ECI) { break;
case ECI:
// Count doesn't apply to ECI // Count doesn't apply to ECI
int value = parseECIValue(bits); int value = parseECIValue(bits);
currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value); currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
if (currentCharacterSetECI == null) { if (currentCharacterSetECI == null) {
throw FormatException.getFormatInstance(); throw FormatException.getFormatInstance();
} }
} else { break;
case HANZI:
// First handle Hanzi mode which does not start with character count // First handle Hanzi mode which does not start with character count
if (mode == Mode.HANZI) { // Chinese mode contains a sub set indicator right after mode indicator
//chinese mode contains a sub set indicator right after mode indicator int subset = bits.readBits(4);
int subset = bits.readBits(4); int countHanzi = bits.readBits(mode.getCharacterCountBits(version));
int countHanzi = bits.readBits(mode.getCharacterCountBits(version)); if (subset == GB2312_SUBSET) {
if (subset == GB2312_SUBSET) { decodeHanziSegment(bits, result, countHanzi);
decodeHanziSegment(bits, result, countHanzi);
}
} else {
// "Normal" QR code modes:
// How many characters will follow, encoded in this mode?
int count = bits.readBits(mode.getCharacterCountBits(version));
if (mode == Mode.NUMERIC) {
decodeNumericSegment(bits, result, count);
} else if (mode == Mode.ALPHANUMERIC) {
decodeAlphanumericSegment(bits, result, count, fc1InEffect);
} else if (mode == Mode.BYTE) {
decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
} else if (mode == Mode.KANJI) {
decodeKanjiSegment(bits, result, count);
} else {
throw FormatException.getFormatInstance();
}
} }
} break;
default:
// "Normal" QR code modes:
// How many characters will follow, encoded in this mode?
int count = bits.readBits(mode.getCharacterCountBits(version));
switch (mode) {
case NUMERIC:
decodeNumericSegment(bits, result, count);
break;
case ALPHANUMERIC:
decodeAlphanumericSegment(bits, result, count, fc1InEffect);
break;
case BYTE:
decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
break;
case KANJI:
decodeKanjiSegment(bits, result, count);
break;
default:
throw FormatException.getFormatInstance();
}
break;
} }
} while (mode != Mode.TERMINATOR); } while (mode != Mode.TERMINATOR);
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {

View file

@ -44,7 +44,7 @@
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
<version>19.0</version> <version>20.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.android</groupId> <groupId>com.google.android</groupId>
@ -95,7 +95,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.7</java.version> <java.version>1.7</java.version>
<maven.version.min>3.2.1</maven.version.min> <maven.version.min>3.2.1</maven.version.min>
<proguard.version>5.2.1</proguard.version> <proguard.version>5.3.1</proguard.version>
<proguard.plugin.version>2.0.13</proguard.plugin.version> <proguard.plugin.version>2.0.13</proguard.plugin.version>
<slf4j.version>1.7.21</slf4j.version> <slf4j.version>1.7.21</slf4j.version>
<!-- This can't reference project.version as some subprojects version differently --> <!-- This can't reference project.version as some subprojects version differently -->
@ -170,7 +170,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version> <version>3.6.0</version>
<configuration> <configuration>
<source>${java.version}</source> <source>${java.version}</source>
<target>${java.version}</target> <target>${java.version}</target>

View file

@ -37,7 +37,7 @@
</parent> </parent>
<properties> <properties>
<gwt.version>2.8.0-rc2</gwt.version> <gwt.version>2.8.0</gwt.version>
</properties> </properties>
<build> <build>

View file

@ -57,7 +57,7 @@
<plugin> <plugin>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId> <artifactId>jetty-maven-plugin</artifactId>
<version>9.4.0.RC0</version> <version>9.4.0.RC1</version>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>