Skip to content

Commit

Permalink
Enable RAT check in build; enable checkstyle; fix some violations; up…
Browse files Browse the repository at this point in the history
…date Jetty/Android plugin
  • Loading branch information
srowen committed May 15, 2015
1 parent ec9487c commit 867d580
Show file tree
Hide file tree
Showing 19 changed files with 311 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,56 +227,55 @@ private void encodeFromStreamExtra(Intent intent) throws WriterException {

private void encodeQRCodeContents(Intent intent, String type) {
switch (type) {
case Contents.Type.TEXT: {
String data = intent.getStringExtra(Intents.Encode.DATA);
if (data != null && !data.isEmpty()) {
contents = data;
displayContents = data;
case Contents.Type.TEXT:
String textData = intent.getStringExtra(Intents.Encode.DATA);
if (textData != null && !textData.isEmpty()) {
contents = textData;
displayContents = textData;
title = activity.getString(R.string.contents_text);
}
break;
}
case Contents.Type.EMAIL: {
String data = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
if (data != null) {
contents = "mailto:" + data;
displayContents = data;

case Contents.Type.EMAIL:
String emailData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
if (emailData != null) {
contents = "mailto:" + emailData;
displayContents = emailData;
title = activity.getString(R.string.contents_email);
}
break;
}
case Contents.Type.PHONE: {
String data = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
if (data != null) {
contents = "tel:" + data;
displayContents = PhoneNumberUtils.formatNumber(data);

case Contents.Type.PHONE:
String phoneData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
if (phoneData != null) {
contents = "tel:" + phoneData;
displayContents = PhoneNumberUtils.formatNumber(phoneData);
title = activity.getString(R.string.contents_phone);
}
break;
}
case Contents.Type.SMS: {
String data = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
if (data != null) {
contents = "sms:" + data;
displayContents = PhoneNumberUtils.formatNumber(data);

case Contents.Type.SMS:
String smsData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
if (smsData != null) {
contents = "sms:" + smsData;
displayContents = PhoneNumberUtils.formatNumber(smsData);
title = activity.getString(R.string.contents_sms);
}
break;
}
case Contents.Type.CONTACT: {

Bundle bundle = intent.getBundleExtra(Intents.Encode.DATA);
if (bundle != null) {

String name = bundle.getString(ContactsContract.Intents.Insert.NAME);
String organization = bundle.getString(ContactsContract.Intents.Insert.COMPANY);
String address = bundle.getString(ContactsContract.Intents.Insert.POSTAL);
List<String> phones = getAllBundleValues(bundle, Contents.PHONE_KEYS);
List<String> phoneTypes = getAllBundleValues(bundle, Contents.PHONE_TYPE_KEYS);
List<String> emails = getAllBundleValues(bundle, Contents.EMAIL_KEYS);
String url = bundle.getString(Contents.URL_KEY);

case Contents.Type.CONTACT:
Bundle contactBundle = intent.getBundleExtra(Intents.Encode.DATA);
if (contactBundle != null) {

String name = contactBundle.getString(ContactsContract.Intents.Insert.NAME);
String organization = contactBundle.getString(ContactsContract.Intents.Insert.COMPANY);
String address = contactBundle.getString(ContactsContract.Intents.Insert.POSTAL);
List<String> phones = getAllBundleValues(contactBundle, Contents.PHONE_KEYS);
List<String> phoneTypes = getAllBundleValues(contactBundle, Contents.PHONE_TYPE_KEYS);
List<String> emails = getAllBundleValues(contactBundle, Contents.EMAIL_KEYS);
String url = contactBundle.getString(Contents.URL_KEY);
List<String> urls = url == null ? null : Collections.singletonList(url);
String note = bundle.getString(Contents.NOTE_KEY);
String note = contactBundle.getString(Contents.NOTE_KEY);

ContactEncoder encoder = useVCard ? new VCardContactEncoder() : new MECARDContactEncoder();
String[] encoded = encoder.encode(Collections.singletonList(name),
Expand All @@ -295,23 +294,21 @@ private void encodeQRCodeContents(Intent intent, String type) {
}

}

break;
}
case Contents.Type.LOCATION: {
Bundle bundle = intent.getBundleExtra(Intents.Encode.DATA);
if (bundle != null) {

case Contents.Type.LOCATION:
Bundle locationBundle = intent.getBundleExtra(Intents.Encode.DATA);
if (locationBundle != null) {
// These must use Bundle.getFloat(), not getDouble(), it's part of the API.
float latitude = bundle.getFloat("LAT", Float.MAX_VALUE);
float longitude = bundle.getFloat("LONG", Float.MAX_VALUE);
float latitude = locationBundle.getFloat("LAT", Float.MAX_VALUE);
float longitude = locationBundle.getFloat("LONG", Float.MAX_VALUE);
if (latitude != Float.MAX_VALUE && longitude != Float.MAX_VALUE) {
contents = "geo:" + latitude + ',' + longitude;
displayContents = latitude + "," + longitude;
title = activity.getString(R.string.contents_location);
}
}
break;
}
}
}

Expand Down
14 changes: 3 additions & 11 deletions core/src/main/java/com/google/zxing/ChecksumException.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
public final class ChecksumException extends ReaderException {

private static final ChecksumException instance = new ChecksumException();
private static final ChecksumException INSTANCE = new ChecksumException();

private ChecksumException() {
// do nothing
Expand All @@ -35,18 +35,10 @@ private ChecksumException(Throwable cause) {
}

public static ChecksumException getChecksumInstance() {
if (isStackTrace) {
return new ChecksumException();
} else {
return instance;
}
return IS_STACK_TRACE ? new ChecksumException() : INSTANCE;
}

public static ChecksumException getChecksumInstance(Throwable cause) {
if (isStackTrace) {
return new ChecksumException(cause);
} else {
return instance;
}
return IS_STACK_TRACE ? new ChecksumException(cause) : INSTANCE;
}
}
14 changes: 3 additions & 11 deletions core/src/main/java/com/google/zxing/FormatException.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
public final class FormatException extends ReaderException {

private static final FormatException instance = new FormatException();
private static final FormatException INSTANCE = new FormatException();

private FormatException() {
}
Expand All @@ -35,18 +35,10 @@ private FormatException(Throwable cause) {
}

public static FormatException getFormatInstance() {
if (isStackTrace) {
return new FormatException();
} else {
return instance;
}
return IS_STACK_TRACE ? new FormatException() : INSTANCE;
}

public static FormatException getFormatInstance(Throwable cause) {
if (isStackTrace) {
return new FormatException(cause);
} else {
return instance;
}
return IS_STACK_TRACE ? new FormatException(cause) : INSTANCE;
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/com/google/zxing/NotFoundException.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
*/
public final class NotFoundException extends ReaderException {

private static final NotFoundException instance = new NotFoundException();
private static final NotFoundException INSTANCE = new NotFoundException();

private NotFoundException() {
// do nothing
}

public static NotFoundException getNotFoundInstance() {
return instance;
return INSTANCE;
}

}
3 changes: 2 additions & 1 deletion core/src/main/java/com/google/zxing/ReaderException.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
public abstract class ReaderException extends Exception {

// disable stack traces when not running inside test units
protected static final boolean isStackTrace = System.getProperty("surefire.test.class.path") != null;
protected static final boolean IS_STACK_TRACE =
System.getProperty("surefire.test.class.path") != null;

ReaderException() {
// do nothing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,15 @@ private void updateStateForChar(State state, int index, Collection<State> result
// any other mode except possibly digit (which uses only 4 bits). Any
// other latch would be equally successful *after* this character, and
// so wouldn't save any bits.
State latch_state = stateNoBinary.latchAndAppend(mode, charInMode);
result.add(latch_state);
State latchState = stateNoBinary.latchAndAppend(mode, charInMode);
result.add(latchState);
}
// Try generating the character by switching to its mode.
if (!charInCurrentTable && SHIFT_TABLE[state.getMode()][mode] >= 0) {
// It never makes sense to temporarily shift to another mode if the
// character exists in the current mode. That can never save bits.
State shift_state = stateNoBinary.shiftAndAppend(mode, charInMode);
result.add(shift_state);
State shiftState = stateNoBinary.shiftAndAppend(mode, charInMode);
result.add(shiftState);
}
}
}
Expand Down Expand Up @@ -270,10 +270,10 @@ private static void updateStateForPair(State state, int index, int pairCode, Col
}
if (pairCode == 3 || pairCode == 4) {
// both characters are in DIGITS. Sometimes better to just add two digits
State digit_state = stateNoBinary
State digitState = stateNoBinary
.latchAndAppend(MODE_DIGIT, 16 - pairCode) // period or comma in DIGIT
.latchAndAppend(MODE_DIGIT, 1); // space in DIGIT
result.add(digit_state);
result.add(digitState);
}
if (state.getBinaryShiftByteCount() > 0) {
// It only makes sense to do the characters as binary if we're already
Expand All @@ -287,7 +287,7 @@ private static Collection<State> simplifyStates(Iterable<State> states) {
List<State> result = new LinkedList<>();
for (State newState : states) {
boolean add = true;
for (Iterator<State> iterator = result.iterator(); iterator.hasNext(); ) {
for (Iterator<State> iterator = result.iterator(); iterator.hasNext();) {
State oldState = iterator.next();
if (oldState.isBetterThanOrEqualTo(newState)) {
add = false;
Expand Down
11 changes: 4 additions & 7 deletions core/src/main/java/com/google/zxing/common/BitMatrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,20 @@ public static BitMatrix parse(String stringRepresentation, String setString, Str
if (stringRepresentation.charAt(pos) == '\n' ||
stringRepresentation.charAt(pos) == '\r') {
if (bitsPos > rowStartPos) {
if(rowLength == -1) {
if (rowLength == -1) {
rowLength = bitsPos - rowStartPos;
}
else if (bitsPos - rowStartPos != rowLength) {
} else if (bitsPos - rowStartPos != rowLength) {
throw new IllegalArgumentException("row lengths do not match");
}
rowStartPos = bitsPos;
nRows++;
}
pos++;
}
else if (stringRepresentation.substring(pos, pos + setString.length()).equals(setString)) {
} else if (stringRepresentation.substring(pos, pos + setString.length()).equals(setString)) {
pos += setString.length();
bits[bitsPos] = true;
bitsPos++;
}
else if (stringRepresentation.substring(pos, pos + unsetString.length()).equals(unsetString)) {
} else if (stringRepresentation.substring(pos, pos + unsetString.length()).equals(unsetString)) {
pos += unsetString.length();
bits[bitsPos] = false;
bitsPos++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private static BitMatrix encodeLowLevel(DefaultPlacement placement, SymbolInfo s
for (int y = 0; y < symbolHeight; y++) {
// Fill the top edge with alternate 0 / 1
int matrixX;
if ((y % symbolInfo.matrixHeight) == 0) {
if ((y % symbolInfo.getMatrixHeight()) == 0) {
matrixX = 0;
for (int x = 0; x < symbolInfo.getSymbolWidth(); x++) {
matrix.set(matrixX, matrixY, (x % 2) == 0);
Expand All @@ -126,21 +126,21 @@ private static BitMatrix encodeLowLevel(DefaultPlacement placement, SymbolInfo s
matrixX = 0;
for (int x = 0; x < symbolWidth; x++) {
// Fill the right edge with full 1
if ((x % symbolInfo.matrixWidth) == 0) {
if ((x % symbolInfo.getMatrixWidth()) == 0) {
matrix.set(matrixX, matrixY, true);
matrixX++;
}
matrix.set(matrixX, matrixY, placement.getBit(x, y));
matrixX++;
// Fill the right edge with alternate 0 / 1
if ((x % symbolInfo.matrixWidth) == symbolInfo.matrixWidth - 1) {
if ((x % symbolInfo.getMatrixWidth()) == symbolInfo.getMatrixWidth() - 1) {
matrix.set(matrixX, matrixY, (y % 2) == 0);
matrixX++;
}
}
matrixY++;
// Fill the bottom edge with full 1
if ((y % symbolInfo.matrixHeight) == symbolInfo.matrixHeight - 1) {
if ((y % symbolInfo.getMatrixHeight()) == symbolInfo.getMatrixHeight() - 1) {
matrixX = 0;
for (int x = 0; x < symbolInfo.getSymbolWidth(); x++) {
matrix.set(matrixX, matrixY, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public static void overrideSymbolSet(SymbolInfo[] override) {
private final boolean rectangular;
private final int dataCapacity;
private final int errorCodewords;
public final int matrixWidth;
public final int matrixHeight;
private final int matrixWidth;
private final int matrixHeight;
private final int dataRegions;
private final int rsBlockData;
private final int rsBlockError;
Expand Down Expand Up @@ -186,6 +186,14 @@ final int getVerticalDataRegions() {
}
}

public int getMatrixWidth() {
return matrixWidth;
}

public int getMatrixHeight() {
return matrixHeight;
}

public final int getSymbolDataWidth() {
return getHorizontalDataRegions() * matrixWidth;
}
Expand Down
3 changes: 0 additions & 3 deletions core/src/main/java/com/google/zxing/oned/ITFReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,6 @@ int[] decodeEnd(BitArray row) throws NotFoundException {
private static int[] findGuardPattern(BitArray row,
int rowOffset,
int[] pattern) throws NotFoundException {

// TODO: This is very similar to implementation in UPCEANReader. Consider if they can be
// merged to a single method.
int patternLength = pattern.length;
int[] counters = new int[patternLength];
int width = row.getSize();
Expand Down
Loading

0 comments on commit 867d580

Please sign in to comment.