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) {
case WEP:
changeNetworkWEP(wifiManager, theWifiResult); changeNetworkWEP(wifiManager, theWifiResult);
} else if (networkType == NetworkType.WPA) { break;
case WPA:
changeNetworkWPA(wifiManager, theWifiResult); changeNetworkWPA(wifiManager, theWifiResult);
break;
} }
} }
} }

View file

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

View file

@ -49,21 +49,29 @@ final class X12Encoder extends C40Encoder {
@Override @Override
int encodeChar(char c, StringBuilder sb) { int encodeChar(char c, StringBuilder sb) {
if (c == '\r') { switch (c) {
case '\r':
sb.append('\0'); sb.append('\0');
} else if (c == '*') { break;
case '*':
sb.append('\1'); sb.append('\1');
} else if (c == '>') { break;
case '>':
sb.append('\2'); sb.append('\2');
} else if (c == ' ') { break;
case ' ':
sb.append('\3'); sb.append('\3');
} else if (c >= '0' && c <= '9') { break;
default:
if (c >= '0' && c <= '9') {
sb.append((char) (c - 48 + 4)); sb.append((char) (c - 48 + 4));
} else if (c >= 'A' && c <= 'Z') { } else if (c >= 'A' && c <= 'Z') {
sb.append((char) (c - 65 + 14)); sb.append((char) (c - 65 + 14));
} else { } else {
HighLevelEncoder.illegalCharacter(c); 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,7 +173,8 @@ 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]) {
case BEGIN_MACRO_PDF417_OPTIONAL_FIELD:
codeIndex++; codeIndex++;
int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex]; int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
int additionalOptionCodeWordsIndex = 0; int additionalOptionCodeWordsIndex = 0;
@ -195,11 +196,12 @@ final class DecodedBitStreamParser {
} }
} }
} }
resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex)); resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
} else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) { break;
case 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) {
case 26:
ch = ' '; ch = ' ';
} else if (subModeCh == LL) { break;
case LL:
subMode = Mode.LOWER; subMode = Mode.LOWER;
} else if (subModeCh == ML) { break;
case ML:
subMode = Mode.MIXED; subMode = Mode.MIXED;
} else if (subModeCh == PS) { break;
case PS:
// Shift to punctuation // Shift to punctuation
priorToShiftMode = subMode; priorToShiftMode = subMode;
subMode = Mode.PUNCT_SHIFT; subMode = Mode.PUNCT_SHIFT;
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) { break;
case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
result.append((char) byteCompactionData[i]); result.append((char) byteCompactionData[i]);
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) { break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA; 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) {
case 26:
ch = ' '; ch = ' ';
} else if (subModeCh == AS) { break;
case AS:
// Shift to alpha // Shift to alpha
priorToShiftMode = subMode; priorToShiftMode = subMode;
subMode = Mode.ALPHA_SHIFT; subMode = Mode.ALPHA_SHIFT;
} else if (subModeCh == ML) { break;
case ML:
subMode = Mode.MIXED; subMode = Mode.MIXED;
} else if (subModeCh == PS) { break;
case PS:
// Shift to punctuation // Shift to punctuation
priorToShiftMode = subMode; priorToShiftMode = subMode;
subMode = Mode.PUNCT_SHIFT; subMode = Mode.PUNCT_SHIFT;
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) { break;
case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
// TODO Does this need to use the current character encoding? See other occurrences below // TODO Does this need to use the current character encoding? See other occurrences below
result.append((char) byteCompactionData[i]); result.append((char) byteCompactionData[i]);
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) { break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA; 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) {
case PL:
subMode = Mode.PUNCT; subMode = Mode.PUNCT;
} else if (subModeCh == 26) { break;
case 26:
ch = ' '; ch = ' ';
} else if (subModeCh == LL) { break;
case LL:
subMode = Mode.LOWER; subMode = Mode.LOWER;
} else if (subModeCh == AL) { break;
case AL:
subMode = Mode.ALPHA; subMode = Mode.ALPHA;
} else if (subModeCh == PS) { break;
case PS:
// Shift to punctuation // Shift to punctuation
priorToShiftMode = subMode; priorToShiftMode = subMode;
subMode = Mode.PUNCT_SHIFT; subMode = Mode.PUNCT_SHIFT;
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) { break;
case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
result.append((char) byteCompactionData[i]); result.append((char) byteCompactionData[i]);
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) { break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA; 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) {
case PAL:
subMode = Mode.ALPHA; subMode = Mode.ALPHA;
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) { break;
case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
result.append((char) byteCompactionData[i]); result.append((char) byteCompactionData[i]);
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) { break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA; 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) {
case 26:
ch = ' '; ch = ' ';
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) { break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA; 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) {
case PAL:
subMode = Mode.ALPHA; subMode = Mode.ALPHA;
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) { break;
case MODE_SHIFT_TO_BYTE_COMPACTION_MODE:
// PS before Shift-to-Byte is used as a padding character, // PS before Shift-to-Byte is used as a padding character,
// see 5.4.2.4 of the specification // see 5.4.2.4 of the specification
result.append((char) byteCompactionData[i]); result.append((char) byteCompactionData[i]);
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) { break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA; subMode = Mode.ALPHA;
break;
} }
} }
break; break;
@ -442,13 +477,16 @@ 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) {
// Total number of Byte Compaction characters to be encoded
// is not a multiple of 6
int count = 0; int count = 0;
long value = 0; long value = 0;
int[] byteCompactedCodewords = new int[6];
boolean end = false; boolean end = false;
switch (mode) {
case BYTE_COMPACTION_MODE_LATCH:
// Total number of Byte Compaction characters to be encoded
// is not a multiple of 6
int[] byteCompactedCodewords = new int[6];
int nextCode = codewords[codeIndex++]; int nextCode = codewords[codeIndex++];
while ((codeIndex < codewords[0]) && !end) { while ((codeIndex < codewords[0]) && !end) {
byteCompactedCodewords[count++] = nextCode; byteCompactedCodewords[count++] = nextCode;
@ -456,16 +494,18 @@ final class DecodedBitStreamParser {
value = 900 * value + nextCode; value = 900 * value + nextCode;
nextCode = codewords[codeIndex++]; nextCode = codewords[codeIndex++];
// perhaps it should be ok to check only nextCode >= TEXT_COMPACTION_MODE_LATCH // perhaps it should be ok to check only nextCode >= TEXT_COMPACTION_MODE_LATCH
if (nextCode == TEXT_COMPACTION_MODE_LATCH || switch (nextCode) {
nextCode == BYTE_COMPACTION_MODE_LATCH || case TEXT_COMPACTION_MODE_LATCH:
nextCode == NUMERIC_COMPACTION_MODE_LATCH || case BYTE_COMPACTION_MODE_LATCH:
nextCode == BYTE_COMPACTION_MODE_LATCH_6 || case NUMERIC_COMPACTION_MODE_LATCH:
nextCode == BEGIN_MACRO_PDF417_CONTROL_BLOCK || case BYTE_COMPACTION_MODE_LATCH_6:
nextCode == BEGIN_MACRO_PDF417_OPTIONAL_FIELD || case BEGIN_MACRO_PDF417_CONTROL_BLOCK:
nextCode == MACRO_PDF417_TERMINATOR) { case BEGIN_MACRO_PDF417_OPTIONAL_FIELD:
case MACRO_PDF417_TERMINATOR:
codeIndex--; codeIndex--;
end = true; end = true;
} else { break;
default:
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
@ -475,6 +515,7 @@ final class DecodedBitStreamParser {
value = 0; value = 0;
count = 0; count = 0;
} }
break;
} }
} }
@ -490,12 +531,11 @@ final class DecodedBitStreamParser {
decodedBytes.write((byte) byteCompactedCodewords[i]); decodedBytes.write((byte) byteCompactedCodewords[i]);
} }
} else if (mode == BYTE_COMPACTION_MODE_LATCH_6) { break;
case BYTE_COMPACTION_MODE_LATCH_6:
// Total number of Byte Compaction characters to be encoded // Total number of Byte Compaction characters to be encoded
// is an integer multiple of 6 // is an integer multiple of 6
int count = 0;
long value = 0;
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) {
@ -503,15 +543,17 @@ final class DecodedBitStreamParser {
// Base 900 // Base 900
value = 900 * value + code; value = 900 * value + code;
} else { } else {
if (code == TEXT_COMPACTION_MODE_LATCH || switch (code) {
code == BYTE_COMPACTION_MODE_LATCH || case TEXT_COMPACTION_MODE_LATCH:
code == NUMERIC_COMPACTION_MODE_LATCH || case BYTE_COMPACTION_MODE_LATCH:
code == BYTE_COMPACTION_MODE_LATCH_6 || case NUMERIC_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:
case MACRO_PDF417_TERMINATOR:
codeIndex--; codeIndex--;
end = true; end = true;
break;
} }
} }
if ((count % 5 == 0) && (count > 0)) { if ((count % 5 == 0) && (count > 0)) {
@ -524,6 +566,7 @@ final class DecodedBitStreamParser {
count = 0; count = 0;
} }
} }
break;
} }
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:
case MACRO_PDF417_TERMINATOR:
codeIndex--; codeIndex--;
end = true; 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,18 +179,19 @@ 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) {
case TEXT:
encodeText(msg, p, len, sb, textSubMode); encodeText(msg, p, len, sb, textSubMode);
break;
} else if (compaction == Compaction.BYTE) { case BYTE:
byte[] bytes = msg.getBytes(encoding); byte[] msgBytes = msg.getBytes(encoding);
encodeBinary(bytes, p, bytes.length, BYTE_COMPACTION, sb); encodeBinary(msgBytes, p, msgBytes.length, BYTE_COMPACTION, sb);
break;
} else if (compaction == Compaction.NUMERIC) { case NUMERIC:
sb.append((char) LATCH_TO_NUMERIC); sb.append((char) LATCH_TO_NUMERIC);
encodeNumeric(msg, p, len, sb); encodeNumeric(msg, p, len, sb);
break;
} else { default:
int encodingMode = TEXT_COMPACTION; //Default mode, see 4.4.2.1 int encodingMode = TEXT_COMPACTION; //Default mode, see 4.4.2.1
while (p < len) { while (p < len) {
int n = determineConsecutiveDigitCount(msg, p); int n = determineConsecutiveDigitCount(msg, p);
@ -229,6 +230,7 @@ final class PDF417HighLevelEncoder {
} }
} }
} }
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 { break;
default:
// "Normal" QR code modes: // "Normal" QR code modes:
// How many characters will follow, encoded in this mode? // How many characters will follow, encoded in this mode?
int count = bits.readBits(mode.getCharacterCountBits(version)); int count = bits.readBits(mode.getCharacterCountBits(version));
if (mode == Mode.NUMERIC) { switch (mode) {
case NUMERIC:
decodeNumericSegment(bits, result, count); decodeNumericSegment(bits, result, count);
} else if (mode == Mode.ALPHANUMERIC) { break;
case ALPHANUMERIC:
decodeAlphanumericSegment(bits, result, count, fc1InEffect); decodeAlphanumericSegment(bits, result, count, fc1InEffect);
} else if (mode == Mode.BYTE) { break;
case BYTE:
decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints); decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
} else if (mode == Mode.KANJI) { break;
case KANJI:
decodeKanjiSegment(bits, result, count); decodeKanjiSegment(bits, result, count);
} else { break;
default:
throw FormatException.getFormatInstance(); 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>