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 {
String password = theWifiResult.getPassword();
if (password != null && !password.isEmpty()) {
if (networkType == NetworkType.WEP) {
switch (networkType) {
case WEP:
changeNetworkWEP(wifiManager, theWifiResult);
} else if (networkType == NetworkType.WPA) {
break;
case WPA:
changeNetworkWPA(wifiManager, theWifiResult);
break;
}
}
}

View file

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

View file

@ -49,21 +49,29 @@ final class X12Encoder extends C40Encoder {
@Override
int encodeChar(char c, StringBuilder sb) {
if (c == '\r') {
switch (c) {
case '\r':
sb.append('\0');
} else if (c == '*') {
break;
case '*':
sb.append('\1');
} else if (c == '>') {
break;
case '>':
sb.append('\2');
} else if (c == ' ') {
break;
case ' ':
sb.append('\3');
} else if (c >= '0' && c <= '9') {
break;
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;
}

View file

@ -212,16 +212,16 @@ public final class Code128Writer extends OneDimensionalCodeWriter {
return CODE_CODE_B; // no choice
}
if (oldCode == CODE_CODE_C) { // can continue in code C
return oldCode;
return CODE_CODE_C;
}
if (oldCode == CODE_CODE_B) {
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
lookahead = findCType(value, start + 2);
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...
lookahead = findCType(value, start + 3);

View file

@ -173,7 +173,8 @@ final class DecodedBitStreamParser {
codeIndex = textCompaction(codewords, codeIndex, fileId);
resultMetadata.setFileId(fileId.toString());
if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) {
switch (codewords[codeIndex]) {
case BEGIN_MACRO_PDF417_OPTIONAL_FIELD:
codeIndex++;
int[] additionalOptionCodeWords = new int[codewords[0] - codeIndex];
int additionalOptionCodeWordsIndex = 0;
@ -195,11 +196,12 @@ final class DecodedBitStreamParser {
}
}
}
resultMetadata.setOptionalData(Arrays.copyOf(additionalOptionCodeWords, additionalOptionCodeWordsIndex));
} else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) {
break;
case MACRO_PDF417_TERMINATOR:
resultMetadata.setLastSegment(true);
codeIndex++;
break;
}
return codeIndex;
@ -300,20 +302,27 @@ final class DecodedBitStreamParser {
// Upper case Alpha Character
ch = (char) ('A' + subModeCh);
} else {
if (subModeCh == 26) {
switch (subModeCh) {
case 26:
ch = ' ';
} else if (subModeCh == LL) {
break;
case LL:
subMode = Mode.LOWER;
} else if (subModeCh == ML) {
break;
case ML:
subMode = Mode.MIXED;
} else if (subModeCh == PS) {
break;
case PS:
// Shift to punctuation
priorToShiftMode = subMode;
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]);
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA;
break;
}
}
break;
@ -323,23 +332,30 @@ final class DecodedBitStreamParser {
if (subModeCh < 26) {
ch = (char) ('a' + subModeCh);
} else {
if (subModeCh == 26) {
switch (subModeCh) {
case 26:
ch = ' ';
} else if (subModeCh == AS) {
break;
case AS:
// Shift to alpha
priorToShiftMode = subMode;
subMode = Mode.ALPHA_SHIFT;
} else if (subModeCh == ML) {
break;
case ML:
subMode = Mode.MIXED;
} else if (subModeCh == PS) {
break;
case PS:
// Shift to punctuation
priorToShiftMode = subMode;
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
result.append((char) byteCompactionData[i]);
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA;
break;
}
}
break;
@ -349,22 +365,30 @@ final class DecodedBitStreamParser {
if (subModeCh < PL) {
ch = MIXED_CHARS[subModeCh];
} else {
if (subModeCh == PL) {
switch (subModeCh) {
case PL:
subMode = Mode.PUNCT;
} else if (subModeCh == 26) {
break;
case 26:
ch = ' ';
} else if (subModeCh == LL) {
break;
case LL:
subMode = Mode.LOWER;
} else if (subModeCh == AL) {
break;
case AL:
subMode = Mode.ALPHA;
} else if (subModeCh == PS) {
break;
case PS:
// Shift to punctuation
priorToShiftMode = subMode;
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]);
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA;
break;
}
}
break;
@ -374,12 +398,16 @@ final class DecodedBitStreamParser {
if (subModeCh < PAL) {
ch = PUNCT_CHARS[subModeCh];
} else {
if (subModeCh == PAL) {
switch (subModeCh) {
case PAL:
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]);
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA;
break;
}
}
break;
@ -390,10 +418,13 @@ final class DecodedBitStreamParser {
if (subModeCh < 26) {
ch = (char) ('A' + subModeCh);
} else {
if (subModeCh == 26) {
switch (subModeCh) {
case 26:
ch = ' ';
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA;
break;
}
}
break;
@ -404,14 +435,18 @@ final class DecodedBitStreamParser {
if (subModeCh < PAL) {
ch = PUNCT_CHARS[subModeCh];
} else {
if (subModeCh == PAL) {
switch (subModeCh) {
case PAL:
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,
// see 5.4.2.4 of the specification
result.append((char) byteCompactionData[i]);
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
break;
case TEXT_COMPACTION_MODE_LATCH:
subMode = Mode.ALPHA;
break;
}
}
break;
@ -442,13 +477,16 @@ final class DecodedBitStreamParser {
int codeIndex,
StringBuilder result) {
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;
long value = 0;
int[] byteCompactedCodewords = new int[6];
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++];
while ((codeIndex < codewords[0]) && !end) {
byteCompactedCodewords[count++] = nextCode;
@ -456,16 +494,18 @@ final class DecodedBitStreamParser {
value = 900 * value + nextCode;
nextCode = codewords[codeIndex++];
// perhaps it should be ok to check only nextCode >= TEXT_COMPACTION_MODE_LATCH
if (nextCode == TEXT_COMPACTION_MODE_LATCH ||
nextCode == BYTE_COMPACTION_MODE_LATCH ||
nextCode == NUMERIC_COMPACTION_MODE_LATCH ||
nextCode == BYTE_COMPACTION_MODE_LATCH_6 ||
nextCode == BEGIN_MACRO_PDF417_CONTROL_BLOCK ||
nextCode == BEGIN_MACRO_PDF417_OPTIONAL_FIELD ||
nextCode == MACRO_PDF417_TERMINATOR) {
switch (nextCode) {
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;
} else {
break;
default:
if ((count % 5 == 0) && (count > 0)) {
// Decode every 5 codewords
// Convert to Base 256
@ -475,6 +515,7 @@ final class DecodedBitStreamParser {
value = 0;
count = 0;
}
break;
}
}
@ -490,12 +531,11 @@ final class DecodedBitStreamParser {
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
// 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) {
@ -503,15 +543,17 @@ final class DecodedBitStreamParser {
// 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) {
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)) {
@ -524,6 +566,7 @@ final class DecodedBitStreamParser {
count = 0;
}
}
break;
}
result.append(new String(decodedBytes.toByteArray(), encoding));
return codeIndex;
@ -552,14 +595,16 @@ final class DecodedBitStreamParser {
numericCodewords[count] = code;
count++;
} else {
if (code == TEXT_COMPACTION_MODE_LATCH ||
code == BYTE_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) {
switch (code) {
case TEXT_COMPACTION_MODE_LATCH:
case BYTE_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 % MAX_NUMERIC_CODEWORDS == 0 ||

View file

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

View file

@ -179,18 +179,19 @@ final class PDF417HighLevelEncoder {
int textSubMode = SUBMODE_ALPHA;
// User selected encoding mode
if (compaction == Compaction.TEXT) {
switch (compaction) {
case TEXT:
encodeText(msg, p, len, sb, textSubMode);
} else if (compaction == Compaction.BYTE) {
byte[] bytes = msg.getBytes(encoding);
encodeBinary(bytes, p, bytes.length, BYTE_COMPACTION, sb);
} else if (compaction == Compaction.NUMERIC) {
break;
case BYTE:
byte[] msgBytes = msg.getBytes(encoding);
encodeBinary(msgBytes, p, msgBytes.length, BYTE_COMPACTION, sb);
break;
case NUMERIC:
sb.append((char) LATCH_TO_NUMERIC);
encodeNumeric(msg, p, len, sb);
} else {
break;
default:
int encodingMode = TEXT_COMPACTION; //Default mode, see 4.4.2.1
while (p < len) {
int n = determineConsecutiveDigitCount(msg, p);
@ -229,6 +230,7 @@ final class PDF417HighLevelEncoder {
}
}
}
break;
}
return sb.toString();

View file

@ -71,11 +71,15 @@ final class DecodedBitStreamParser {
} else {
mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits
}
if (mode != Mode.TERMINATOR) {
if (mode == Mode.FNC1_FIRST_POSITION || mode == Mode.FNC1_SECOND_POSITION) {
switch (mode) {
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
fc1InEffect = true;
} else if (mode == Mode.STRUCTURED_APPEND) {
break;
case STRUCTURED_APPEND:
if (bits.available() < 16) {
throw FormatException.getFormatInstance();
}
@ -83,39 +87,45 @@ final class DecodedBitStreamParser {
// Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue
symbolSequence = bits.readBits(8);
parityData = bits.readBits(8);
} else if (mode == Mode.ECI) {
break;
case ECI:
// Count doesn't apply to ECI
int value = parseECIValue(bits);
currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value);
if (currentCharacterSetECI == null) {
throw FormatException.getFormatInstance();
}
} else {
break;
case HANZI:
// 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 countHanzi = bits.readBits(mode.getCharacterCountBits(version));
if (subset == GB2312_SUBSET) {
decodeHanziSegment(bits, result, countHanzi);
}
} else {
break;
default:
// "Normal" QR code modes:
// How many characters will follow, encoded in this mode?
int count = bits.readBits(mode.getCharacterCountBits(version));
if (mode == Mode.NUMERIC) {
switch (mode) {
case NUMERIC:
decodeNumericSegment(bits, result, count);
} else if (mode == Mode.ALPHANUMERIC) {
break;
case ALPHANUMERIC:
decodeAlphanumericSegment(bits, result, count, fc1InEffect);
} else if (mode == Mode.BYTE) {
break;
case BYTE:
decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints);
} else if (mode == Mode.KANJI) {
break;
case KANJI:
decodeKanjiSegment(bits, result, count);
} else {
break;
default:
throw FormatException.getFormatInstance();
}
}
}
break;
}
} while (mode != Mode.TERMINATOR);
} catch (IllegalArgumentException iae) {

View file

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

View file

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

View file

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