Permalink
Browse files

Update deps including Guava 20; use switch in pref to chained if-else…

… for slightly more consistent style
1 parent 995da03 commit 28f8bd37f3b60310bf33923fb8d7e6c2a55c601b @srowen srowen committed Nov 11, 2016
@@ -82,10 +82,13 @@ protected Object doInBackground(WifiParsedResult... args) {
} else {
String password = theWifiResult.getPassword();
if (password != null && !password.isEmpty()) {
- if (networkType == NetworkType.WEP) {
- changeNetworkWEP(wifiManager, theWifiResult);
- } else if (networkType == NetworkType.WPA) {
- changeNetworkWPA(wifiManager, theWifiResult);
+ switch (networkType) {
+ case WEP:
+ changeNetworkWEP(wifiManager, theWifiResult);
+ break;
+ case WPA:
+ changeNetworkWPA(wifiManager, theWifiResult);
+ break;
}
}
}
@@ -146,39 +146,49 @@ private static Mode decodeAsciiSegment(BitSource bits,
result.append('0');
}
result.append(value);
- } else if (oneByte == 230) { // Latch to C40 encodation
- return Mode.C40_ENCODE;
- } else if (oneByte == 231) { // Latch to Base 256 encodation
- return Mode.BASE256_ENCODE;
- } else if (oneByte == 232) {
- // FNC1
- result.append((char) 29); // translate as ASCII 29
- } else if (oneByte == 233 || oneByte == 234) {
- // Structured Append, Reader Programming
- // Ignore these symbols for now
- //throw ReaderException.getInstance();
- } else if (oneByte == 235) { // Upper Shift (shift to Extended ASCII)
- upperShift = true;
- } else if (oneByte == 236) { // 05 Macro
- result.append("[)>\u001E05\u001D");
- resultTrailer.insert(0, "\u001E\u0004");
- } else if (oneByte == 237) { // 06 Macro
- result.append("[)>\u001E06\u001D");
- resultTrailer.insert(0, "\u001E\u0004");
- } else if (oneByte == 238) { // Latch to ANSI X12 encodation
- return Mode.ANSIX12_ENCODE;
- } else if (oneByte == 239) { // Latch to Text encodation
- return Mode.TEXT_ENCODE;
- } else if (oneByte == 240) { // Latch to EDIFACT encodation
- return Mode.EDIFACT_ENCODE;
- } else if (oneByte == 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) {
- throw FormatException.getFormatInstance();
+ } else {
+ switch (oneByte) {
+ case 230: // Latch to C40 encodation
+ return Mode.C40_ENCODE;
+ case 231: // Latch to Base 256 encodation
+ return Mode.BASE256_ENCODE;
+ case 232: // FNC1
+ result.append((char) 29); // translate as ASCII 29
+ break;
+ case 233: // Structured Append
+ case 234: // Reader Programming
+ // Ignore these symbols for now
+ //throw ReaderException.getInstance();
+ break;
+ case 235: // Upper Shift (shift to Extended ASCII)
+ upperShift = true;
+ break;
+ case 236: // 05 Macro
+ result.append("[)>\u001E05\u001D");
+ resultTrailer.insert(0, "\u001E\u0004");
+ break;
+ case 237: // 06 Macro
+ result.append("[)>\u001E06\u001D");
+ resultTrailer.insert(0, "\u001E\u0004");
+ break;
+ case 238: // Latch to ANSI X12 encodation
+ return Mode.ANSIX12_ENCODE;
+ case 239: // Latch to Text encodation
+ return Mode.TEXT_ENCODE;
+ case 240: // Latch to EDIFACT encodation
+ return Mode.EDIFACT_ENCODE;
+ case 241: // ECI Character
+ // 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);
@@ -245,12 +255,17 @@ private static void decodeC40Segment(BitSource bits, StringBuilder result) throw
} 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 {
- 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;
break;
@@ -330,12 +345,17 @@ private static void decodeTextSegment(BitSource bits, StringBuilder result) thro
} 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 {
- 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;
break;
@@ -383,20 +403,28 @@ private static void decodeAnsiX12Segment(BitSource bits,
for (int i = 0; i < 3; i++) {
int cValue = cValues[i];
- if (cValue == 0) { // X12 segment terminator <CR>
- result.append('\r');
- } else if (cValue == 1) { // X12 segment separator *
- result.append('*');
- } else if (cValue == 2) { // X12 sub-element separator >
- result.append('>');
- } else if (cValue == 3) { // space
- result.append(' ');
- } else 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();
+ switch (cValue) {
+ case 0: // X12 segment terminator <CR>
+ result.append('\r');
+ break;
+ case 1: // X12 segment separator *
+ result.append('*');
+ break;
+ case 2: // X12 sub-element separator >
+ result.append('>');
+ break;
+ case 3: // space
+ result.append(' ');
+ 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);
@@ -49,20 +49,28 @@ public void encode(EncoderContext context) {
@Override
int encodeChar(char c, StringBuilder sb) {
- if (c == '\r') {
- sb.append('\0');
- } else if (c == '*') {
- sb.append('\1');
- } else if (c == '>') {
- sb.append('\2');
- } else if (c == ' ') {
- sb.append('\3');
- } else 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);
+ switch (c) {
+ case '\r':
+ sb.append('\0');
+ break;
+ case '*':
+ sb.append('\1');
+ break;
+ case '>':
+ sb.append('\2');
+ break;
+ case ' ':
+ sb.append('\3');
+ 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;
}
@@ -212,16 +212,16 @@ private static int chooseCode(CharSequence value, int start, int oldCode) {
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);
Oops, something went wrong.

0 comments on commit 28f8bd3

Please sign in to comment.