Permalink
Browse files

Many more changes from recent IJ inspections

  • Loading branch information...
srowen committed Sep 3, 2018
1 parent 431ae9e commit 36f38c5beb3a782baa34f7c98386d6b910c0450a
Showing with 77 additions and 68 deletions.
  1. +0 −1 .gitignore
  2. +2 −1 android/src/com/google/zxing/client/android/encode/QRCodeEncoder.java
  3. +1 −1 android/src/com/google/zxing/client/android/result/supplement/BookResultInfoRetriever.java
  4. +2 −0 android/src/com/google/zxing/client/android/result/supplement/SupplementalInfoRetriever.java
  5. +3 −1 core/src/main/java/com/google/zxing/MultiFormatReader.java
  6. +1 −2 core/src/main/java/com/google/zxing/aztec/encoder/HighLevelEncoder.java
  7. +1 −1 core/src/main/java/com/google/zxing/client/result/AddressBookAUResultParser.java
  8. +3 −1 core/src/main/java/com/google/zxing/client/result/ResultParser.java
  9. +3 −3 core/src/main/java/com/google/zxing/client/result/SMSMMSResultParser.java
  10. +2 −2 core/src/main/java/com/google/zxing/client/result/VCardResultParser.java
  11. +2 −2 core/src/main/java/com/google/zxing/common/BitArray.java
  12. +1 −6 core/src/main/java/com/google/zxing/common/detector/WhiteRectangleDetector.java
  13. +1 −2 core/src/main/java/com/google/zxing/datamatrix/encoder/C40Encoder.java
  14. +4 −8 core/src/main/java/com/google/zxing/maxicode/MaxiCodeReader.java
  15. +3 −1 core/src/main/java/com/google/zxing/multi/GenericMultipleBarcodeReader.java
  16. +1 −1 core/src/main/java/com/google/zxing/multi/qrcode/QRCodeMultiReader.java
  17. +1 −1 core/src/main/java/com/google/zxing/multi/qrcode/detector/MultiDetector.java
  18. +7 −6 core/src/main/java/com/google/zxing/multi/qrcode/detector/MultiFinderPatternFinder.java
  19. +3 −1 core/src/main/java/com/google/zxing/oned/MultiFormatOneDReader.java
  20. +3 −1 core/src/main/java/com/google/zxing/oned/MultiFormatUPCEANReader.java
  21. +3 −1 core/src/main/java/com/google/zxing/pdf417/PDF417Reader.java
  22. +1 −1 core/src/main/java/com/google/zxing/pdf417/decoder/PDF417ScanningDecoder.java
  23. +3 −3 core/src/test/java/com/google/zxing/multi/qrcode/MultiQRCodeTestCase.java
  24. +3 −3 javase/src/main/java/com/google/zxing/client/j2se/CommandLineRunner.java
  25. +2 −2 zxing.appspot.com/src/main/java/com/google/zxing/web/generator/client/GeoLocationGenerator.java
  26. +14 −12 zxingorg/src/main/java/com/google/zxing/web/DecodeServlet.java
  27. +1 −1 zxingorg/src/test/java/com/google/zxing/web/DoSFilterTestCase.java
  28. +3 −1 zxingorg/src/test/java/com/google/zxing/web/LRUMapTestCase.java
  29. +3 −2 zxingorg/src/test/java/com/google/zxing/web/WelcomeFilterTestCase.java
View
@@ -1,5 +1,4 @@
target
private
.idea
*.iml
.DS_Store
@@ -40,6 +40,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -195,7 +196,7 @@ private void encodeFromStreamExtra(Intent intent) throws WriterException {
baos.write(buffer, 0, bytesRead);
}
vcard = baos.toByteArray();
vcardString = new String(vcard, 0, vcard.length, "UTF-8");
vcardString = new String(vcard, 0, vcard.length, StandardCharsets.UTF_8);
} catch (IOException ioe) {
throw new WriterException(ioe);
}
@@ -99,7 +99,7 @@ void retrieveSupplementalInfo() throws IOException {
String baseBookUri = "http://www.google." + LocaleManager.getBookSearchCountryTLD(context)
+ "/search?tbm=bks&source=zxing&q=";
append(isbn, source, newTexts.toArray(new String[newTexts.size()]), baseBookUri + isbn);
append(isbn, source, newTexts.toArray(EMPTY_STR_ARRAY), baseBookUri + isbn);
}
}
@@ -46,6 +46,8 @@
private static final String TAG = "SupplementalInfo";
static final String[] EMPTY_STR_ARRAY = new String[0];
private final WeakReference<TextView> textViewRef;
private final WeakReference<HistoryManager> historyManagerRef;
private final Collection<Spannable> newContents;
@@ -37,6 +37,8 @@
*/
public final class MultiFormatReader implements Reader {
private static final Reader[] EMPTY_READER_ARRAY = new Reader[0];
private Map<DecodeHintType,?> hints;
private Reader[] readers;
@@ -152,7 +154,7 @@ public void setHints(Map<DecodeHintType,?> hints) {
readers.add(new MultiFormatOneDReader(hints));
}
}
this.readers = readers.toArray(new Reader[readers.size()]);
this.readers = readers.toArray(EMPTY_READER_ARRAY);
}
@Override
@@ -24,7 +24,6 @@
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
/**
* This produces nearly optimal encodings of text into the first-level of
@@ -284,7 +283,7 @@ private static void updateStateForPair(State state, int index, int pairCode, Col
}
private static Collection<State> simplifyStates(Iterable<State> states) {
List<State> result = new LinkedList<>();
Collection<State> result = new LinkedList<>();
for (State newState : states) {
boolean add = true;
for (Iterator<State> iterator = result.iterator(); iterator.hasNext();) {
@@ -85,7 +85,7 @@ public AddressBookParsedResult parse(Result result) {
if (values == null) {
return null;
}
return values.toArray(new String[values.size()]);
return values.toArray(EMPTY_STR_ARRAY);
}
}
@@ -67,6 +67,8 @@
private static final Pattern EQUALS = Pattern.compile("=");
private static final String BYTE_ORDER_MARK = "\ufeff";
static final String[] EMPTY_STR_ARRAY = new String[0];
/**
* Attempts to parse the raw {@link Result}'s contents as a particular type
* of information (email, URL, etc.) and return a {@link ParsedResult} encapsulating
@@ -236,7 +238,7 @@ static String urlDecode(String encoded) {
if (matches == null || matches.isEmpty()) {
return null;
}
return matches.toArray(new String[matches.size()]);
return matches.toArray(EMPTY_STR_ARRAY);
}
private static int countPrecedingBackslashes(CharSequence s, int pos) {
@@ -80,8 +80,8 @@ public SMSParsedResult parse(Result result) {
}
addNumberVia(numbers, vias, smsURIWithoutQuery.substring(lastComma + 1));
return new SMSParsedResult(numbers.toArray(new String[numbers.size()]),
vias.toArray(new String[vias.size()]),
return new SMSParsedResult(numbers.toArray(EMPTY_STR_ARRAY),
vias.toArray(EMPTY_STR_ARRAY),
subject,
body);
}
@@ -106,4 +106,4 @@ private static void addNumberVia(Collection<String> numbers,
}
}
}
}
@@ -296,7 +296,7 @@ private static String toPrimaryValue(List<String> list) {
result.add(value);
}
}
return result.toArray(new String[result.size()]);
return result.toArray(EMPTY_STR_ARRAY);
}
private static String[] toTypes(Collection<List<String>> lists) {
@@ -324,7 +324,7 @@ private static String toPrimaryValue(List<String> list) {
result.add(type);
}
}
return result.toArray(new String[result.size()]);
return result.toArray(EMPTY_STR_ARRAY);
}
private static boolean isLikeVCardDate(CharSequence value) {
@@ -99,7 +99,7 @@ public int getNextSet(int from) {
int bitsOffset = from / 32;
int currentBits = bits[bitsOffset];
// mask off lesser bits first
currentBits &= ~((1 << (from & 0x1F)) - 1);
currentBits &= -(1 << (from & 0x1F));
while (currentBits == 0) {
if (++bitsOffset == bits.length) {
return size;
@@ -122,7 +122,7 @@ public int getNextUnset(int from) {
int bitsOffset = from / 32;
int currentBits = ~bits[bitsOffset];
// mask off lesser bits first
currentBits &= ~((1 << (from & 0x1F)) - 1);
currentBits &= -(1 << (from & 0x1F));
while (currentBits == 0) {
if (++bitsOffset == bits.length) {
return size;
@@ -90,7 +90,6 @@ public WhiteRectangleDetector(BitMatrix image, int initSize, int x, int y) throw
int down = downInit;
boolean sizeExceeded = false;
boolean aBlackPointFoundOnBorder = true;
boolean atLeastOneBlackPointFoundOnBorder = false;
boolean atLeastOneBlackPointFoundOnRight = false;
boolean atLeastOneBlackPointFoundOnBottom = false;
@@ -181,13 +180,9 @@ public WhiteRectangleDetector(BitMatrix image, int initSize, int x, int y) throw
break;
}
if (aBlackPointFoundOnBorder) {
atLeastOneBlackPointFoundOnBorder = true;
}
}
if (!sizeExceeded && atLeastOneBlackPointFoundOnBorder) {
if (!sizeExceeded) {
int maxSize = right - left;
@@ -45,8 +45,7 @@ public void encode(EncoderContext context) {
if ((buffer.length() % 3) == 2 && (available < 2 || available > 2)) {
lastCharSize = backtrackOneCharacter(context, buffer, removed, lastCharSize);
}
while ((buffer.length() % 3) == 1
&& ((lastCharSize <= 3 && available != 1) || lastCharSize > 3)) {
while ((buffer.length() % 3) == 1 && (lastCharSize > 3 || available != 1)) {
lastCharSize = backtrackOneCharacter(context, buffer, removed, lastCharSize);
}
break;
@@ -59,14 +59,10 @@ public Result decode(BinaryBitmap image) throws NotFoundException, ChecksumExcep
@Override
public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
throws NotFoundException, ChecksumException, FormatException {
DecoderResult decoderResult;
if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
BitMatrix bits = extractPureBits(image.getBlackMatrix());
decoderResult = decoder.decode(bits, hints);
} else {
throw NotFoundException.getNotFoundInstance();
}
// Note that MaxiCode reader effectively always assumes PURE_BARCODE mode
// and can't detect it in an image
BitMatrix bits = extractPureBits(image.getBlackMatrix());
DecoderResult decoderResult = decoder.decode(bits, hints);
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), NO_POINTS, BarcodeFormat.MAXICODE);
String ecLevel = decoderResult.getECLevel();
@@ -47,6 +47,8 @@
private static final int MIN_DIMENSION_TO_RECUR = 100;
private static final int MAX_DEPTH = 4;
static final Result[] EMPTY_RESULT_ARRAY = new Result[0];
private final Reader delegate;
public GenericMultipleBarcodeReader(Reader delegate) {
@@ -66,7 +68,7 @@ public GenericMultipleBarcodeReader(Reader delegate) {
if (results.isEmpty()) {
throw NotFoundException.getNotFoundInstance();
}
return results.toArray(new Result[results.size()]);
return results.toArray(EMPTY_RESULT_ARRAY);
}
private void doDecodeMultiple(BinaryBitmap image,
@@ -92,7 +92,7 @@
return EMPTY_RESULT_ARRAY;
} else {
results = processStructuredAppend(results);
return results.toArray(new Result[results.size()]);
return results.toArray(EMPTY_RESULT_ARRAY);
}
}
@@ -66,7 +66,7 @@ public MultiDetector(BitMatrix image) {
if (result.isEmpty()) {
return EMPTY_DETECTOR_RESULTS;
} else {
return result.toArray(new DetectorResult[result.size()]);
return result.toArray(EMPTY_DETECTOR_RESULTS);
}
}
@@ -49,6 +49,7 @@
final class MultiFinderPatternFinder extends FinderPatternFinder {
private static final FinderPatternInfo[] EMPTY_RESULT_ARRAY = new FinderPatternInfo[0];
private static final FinderPattern[][] EMPTY_FP_2D_ARRAY = new FinderPattern[0][];
// TODO MIN_MODULE_COUNT and MAX_MODULE_COUNT would be great hints to ask the user for
// since it limits the number of regions to decode
@@ -216,12 +217,12 @@ public int compare(FinderPattern center1, FinderPattern center2) {
// All tests passed!
results.add(test);
} // end iterate p3
} // end iterate p2
} // end iterate p1
}
}
}
if (!results.isEmpty()) {
return results.toArray(new FinderPattern[results.size()][]);
return results.toArray(EMPTY_FP_2D_ARRAY);
}
// Nothing found!
@@ -279,7 +280,7 @@ public int compare(FinderPattern center1, FinderPattern center2) {
if (foundPatternCross(stateCount)) {
handlePossibleCenter(stateCount, i, maxJ);
} // end if foundPatternCross
}
} // for i=iSkip-1 ...
FinderPattern[][] patternInfo = selectMutipleBestPatterns();
List<FinderPatternInfo> result = new ArrayList<>();
@@ -291,7 +292,7 @@ public int compare(FinderPattern center1, FinderPattern center2) {
if (result.isEmpty()) {
return EMPTY_RESULT_ARRAY;
} else {
return result.toArray(new FinderPatternInfo[result.size()]);
return result.toArray(EMPTY_RESULT_ARRAY);
}
}
@@ -36,6 +36,8 @@
*/
public final class MultiFormatOneDReader extends OneDReader {
private static final OneDReader[] EMPTY_ONED_ARRAY = new OneDReader[0];
private final OneDReader[] readers;
public MultiFormatOneDReader(Map<DecodeHintType,?> hints) {
@@ -84,7 +86,7 @@ public MultiFormatOneDReader(Map<DecodeHintType,?> hints) {
readers.add(new RSS14Reader());
readers.add(new RSSExpandedReader());
}
this.readers = readers.toArray(new OneDReader[readers.size()]);
this.readers = readers.toArray(EMPTY_ONED_ARRAY);
}
@Override
@@ -37,6 +37,8 @@
*/
public final class MultiFormatUPCEANReader extends OneDReader {
private static final UPCEANReader[] EMPTY_READER_ARRAY = new UPCEANReader[0];
private final UPCEANReader[] readers;
public MultiFormatUPCEANReader(Map<DecodeHintType,?> hints) {
@@ -63,7 +65,7 @@ public MultiFormatUPCEANReader(Map<DecodeHintType,?> hints) {
readers.add(new EAN8Reader());
readers.add(new UPCEReader());
}
this.readers = readers.toArray(new UPCEANReader[readers.size()]);
this.readers = readers.toArray(EMPTY_READER_ARRAY);
}
@Override
@@ -43,6 +43,8 @@
*/
public final class PDF417Reader implements Reader, MultipleBarcodeReader {
private static final Result[] EMPTY_RESULT_ARRAY = new Result[0];
/**
* Locates and decodes a PDF417 code in an image.
*
@@ -94,7 +96,7 @@ public Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints) throws Not
}
results.add(result);
}
return results.toArray(new Result[results.size()]);
return results.toArray(EMPTY_RESULT_ARRAY);
}
private static int getMaxWidth(ResultPoint p1, ResultPoint p2) {
@@ -256,7 +256,7 @@ private static DecoderResult createDecoderResult(DetectionResult detectionResult
Collection<Integer> erasures = new ArrayList<>();
int[] codewords = new int[detectionResult.getBarcodeRowCount() * detectionResult.getBarcodeColumnCount()];
List<int[]> ambiguousIndexValuesList = new ArrayList<>();
List<Integer> ambiguousIndexesList = new ArrayList<>();
Collection<Integer> ambiguousIndexesList = new ArrayList<>();
for (int row = 0; row < detectionResult.getBarcodeRowCount(); row++) {
for (int column = 0; column < detectionResult.getBarcodeColumnCount(); column++) {
int[] values = barcodeMatrix[row][column + 1].getValue();
@@ -19,9 +19,9 @@
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.nio.file.Path;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
@@ -55,14 +55,14 @@ public void testMultiQRCodes() throws Exception {
assertNotNull(results);
assertEquals(4, results.length);
Set<String> barcodeContents = new HashSet<>();
Collection<String> barcodeContents = new HashSet<>();
for (Result result : results) {
barcodeContents.add(result.getText());
assertEquals(BarcodeFormat.QR_CODE, result.getBarcodeFormat());
Map<ResultMetadataType,Object> metadata = result.getResultMetadata();
assertNotNull(metadata);
}
Set<String> expectedContents = new HashSet<>();
Collection<String> expectedContents = new HashSet<>();
expectedContents.add("You earned the class a 5 MINUTE DANCE PARTY!! Awesome! Way to go! Let's boogie!");
expectedContents.add("You earned the class 5 EXTRA MINUTES OF RECESS!! Fabulous!! Way to go!!");
expectedContents.add("You get to SIT AT MRS. SIGMON'S DESK FOR A DAY!! Awesome!! Way to go!! Guess I better clean up! :)");
Oops, something went wrong.

0 comments on commit 36f38c5

Please sign in to comment.