Permalink
Browse files

Minor updates / optimization from inspection; minor plugin / dependen…

…cy updates
1 parent 76b4f96 commit dfe4819691b4d62ccd355744ebc88caaaacf0ea9 @srowen srowen committed Dec 12, 2016
@@ -186,11 +186,11 @@ private static String findAIvalue(int i, String rawText) {
char currentChar = rawTextAux.charAt(index);
if (currentChar == ')') {
return buf.toString();
- } else if (currentChar >= '0' && currentChar <= '9') {
- buf.append(currentChar);
- } else {
+ }
+ if (currentChar < '0' || currentChar > '9') {
return null;
}
+ buf.append(currentChar);
}
return buf.toString();
}
@@ -202,13 +202,12 @@ private static String findValue(int i, String rawText) {
for (int index = 0; index < rawTextAux.length(); index++) {
char c = rawTextAux.charAt(index);
if (c == '(') {
- // We look for a new AI. If it doesn't exist (ERROR), we coninue
+ // We look for a new AI. If it doesn't exist (ERROR), we continue
// with the iteration
- if (findAIvalue(index, rawTextAux) == null) {
- buf.append('(');
- } else {
+ if (findAIvalue(index, rawTextAux) != null) {
break;
}
+ buf.append('(');
} else {
buf.append(c);
}
@@ -51,8 +51,9 @@ public DecoderResult decode(boolean[][] image) throws FormatException, ChecksumE
int dimension = image.length;
BitMatrix bits = new BitMatrix(dimension);
for (int i = 0; i < dimension; i++) {
+ boolean[] imageI = image[i];
for (int j = 0; j < dimension; j++) {
- if (image[i][j]) {
+ if (imageI[j]) {
bits.set(j, i);
}
}
@@ -241,7 +241,7 @@ public void reset() {
throw NotFoundException.getNotFoundInstance();
}
- // Whether the pairs form a valid find pattern seqience,
+ // Whether the pairs form a valid find pattern sequence,
// either complete or a prefix
private static boolean isValidSequence(List<ExpandedPair> pairs) {
for (int[] sequence : FINDER_PATTERN_SEQUENCES) {
@@ -37,12 +37,12 @@
/**
* default white space (margin) around the code
*/
- static final int WHITE_SPACE = 30;
+ private static final int WHITE_SPACE = 30;
/**
* default error correction level
*/
- static final int DEFAULT_ERROR_CORRECTION_LEVEL = 2;
+ private static final int DEFAULT_ERROR_CORRECTION_LEVEL = 2;
@Override
public BitMatrix encode(String contents,
@@ -130,9 +130,9 @@ private static BitMatrix bitMatrixFromEncoder(PDF417 encoder,
if (rotated) {
scaledMatrix = rotateArray(scaledMatrix);
}
- return bitMatrixFrombitArray(scaledMatrix, margin);
+ return bitMatrixFromBitArray(scaledMatrix, margin);
}
- return bitMatrixFrombitArray(originalScale, margin);
+ return bitMatrixFromBitArray(originalScale, margin);
}
/**
@@ -142,14 +142,15 @@ private static BitMatrix bitMatrixFromEncoder(PDF417 encoder,
* @param margin border around the barcode
* @return BitMatrix of the input
*/
- private static BitMatrix bitMatrixFrombitArray(byte[][] input, int margin) {
- // Creates the bitmatrix with extra space for whitespace
+ private static BitMatrix bitMatrixFromBitArray(byte[][] input, int margin) {
+ // Creates the bit matrix with extra space for whitespace
BitMatrix output = new BitMatrix(input[0].length + 2 * margin, input.length + 2 * margin);
output.clear();
for (int y = 0, yOutput = output.getHeight() - margin - 1; y < input.length; y++, yOutput--) {
+ byte[] inputY = input[y];
for (int x = 0; x < input[0].length; x++) {
- // Zero is white in the bytematrix
- if (input[y][x] == 1) {
+ // Zero is white in the byte matrix
+ if (inputY[x] == 1) {
output.set(x + margin, yOutput);
}
}
@@ -233,18 +233,19 @@ private static DetectionResultRowIndicatorColumn getRowIndicatorColumn(BitMatrix
private static void adjustCodewordCount(DetectionResult detectionResult, BarcodeValue[][] barcodeMatrix)
throws NotFoundException {
- int[] numberOfCodewords = barcodeMatrix[0][1].getValue();
+ BarcodeValue barcodeMatrix01 = barcodeMatrix[0][1];
+ int[] numberOfCodewords = barcodeMatrix01.getValue();
int calculatedNumberOfCodewords = detectionResult.getBarcodeColumnCount() *
detectionResult.getBarcodeRowCount() -
getNumberOfECCodeWords(detectionResult.getBarcodeECLevel());
if (numberOfCodewords.length == 0) {
if (calculatedNumberOfCodewords < 1 || calculatedNumberOfCodewords > PDF417Common.MAX_CODEWORDS_IN_BARCODE) {
throw NotFoundException.getNotFoundInstance();
}
- barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords);
+ barcodeMatrix01.setValue(calculatedNumberOfCodewords);
} else if (numberOfCodewords[0] != calculatedNumberOfCodewords) {
// The calculated one is more reliable as it is derived from the row indicator columns
- barcodeMatrix[0][1].setValue(calculatedNumberOfCodewords);
+ barcodeMatrix01.setValue(calculatedNumberOfCodewords);
}
}
@@ -60,8 +60,9 @@ public DecoderResult decode(boolean[][] image, Map<DecodeHintType,?> hints)
int dimension = image.length;
BitMatrix bits = new BitMatrix(dimension);
for (int i = 0; i < dimension; i++) {
+ boolean[] imageI = image[i];
for (int j = 0; j < dimension; j++) {
- if (image[i][j]) {
+ if (imageI[j]) {
bits.set(j, i);
}
}
@@ -16,6 +16,8 @@
package com.google.zxing.qrcode.encoder;
+import java.util.Arrays;
+
/**
* JAVAPORT: The original code was a 2D array of ints, but since it only ever gets assigned
* -1, 0, and 1, I'm going to use less memory and go with bytes.
@@ -66,19 +68,18 @@ public void set(int x, int y, boolean value) {
}
public void clear(byte value) {
- for (int y = 0; y < height; ++y) {
- for (int x = 0; x < width; ++x) {
- bytes[y][x] = value;
- }
+ for (byte[] aByte : bytes) {
+ Arrays.fill(aByte, value);
}
}
@Override
public String toString() {
StringBuilder result = new StringBuilder(2 * width * height + 2);
for (int y = 0; y < height; ++y) {
+ byte[] bytesY = bytes[y];
for (int x = 0; x < width; ++x) {
- switch (bytes[y][x]) {
+ switch (bytesY[x]) {
case 0:
result.append(" 0");
break;
@@ -52,9 +52,10 @@ static int applyMaskPenaltyRule2(ByteMatrix matrix) {
int width = matrix.getWidth();
int height = matrix.getHeight();
for (int y = 0; y < height - 1; y++) {
+ byte[] arrayY = array[y];
for (int x = 0; x < width - 1; x++) {
- int value = array[y][x];
- if (value == array[y][x + 1] && value == array[y + 1][x] && value == array[y + 1][x + 1]) {
+ int value = arrayY[x];
+ if (value == arrayY[x + 1] && value == array[y + 1][x] && value == array[y + 1][x + 1]) {
penalty++;
}
}
@@ -174,8 +174,9 @@ static void embedTypeInfo(ErrorCorrectionLevel ecLevel, int maskPattern, ByteMat
boolean bit = typeInfoBits.get(typeInfoBits.getSize() - 1 - i);
// Type info bits at the left top corner. See 8.9 of JISX0510:2004 (p.46).
- int x1 = TYPE_INFO_COORDINATES[i][0];
- int y1 = TYPE_INFO_COORDINATES[i][1];
+ int[] coordinates = TYPE_INFO_COORDINATES[i];
+ int x1 = coordinates[0];
+ int y1 = coordinates[1];
matrix.set(x1, y1, bit);
if (i < 8) {
@@ -401,21 +402,20 @@ private static void embedVerticalSeparationPattern(int xStart,
}
}
- // Note that we cannot unify the function with embedPositionDetectionPattern() despite they are
- // almost identical, since we cannot write a function that takes 2D arrays in different sizes in
- // C/C++. We should live with the fact.
private static void embedPositionAdjustmentPattern(int xStart, int yStart, ByteMatrix matrix) {
for (int y = 0; y < 5; ++y) {
+ int[] patternY = POSITION_ADJUSTMENT_PATTERN[y];
for (int x = 0; x < 5; ++x) {
- matrix.set(xStart + x, yStart + y, POSITION_ADJUSTMENT_PATTERN[y][x]);
+ matrix.set(xStart + x, yStart + y, patternY[x]);
}
}
}
private static void embedPositionDetectionPattern(int xStart, int yStart, ByteMatrix matrix) {
for (int y = 0; y < 7; ++y) {
+ int[] patternY = POSITION_DETECTION_PATTERN[y];
for (int x = 0; x < 7; ++x) {
- matrix.set(xStart + x, yStart + y, POSITION_DETECTION_PATTERN[y][x]);
+ matrix.set(xStart + x, yStart + y, patternY[x]);
}
}
}
@@ -151,8 +151,7 @@ private static void dumpResult(URI input, Result... results) throws IOException
System.out.println(uri + ": Success");
} else {
StringWriter output = new StringWriter();
- for (int resultIndex = 0; resultIndex < results.length; resultIndex++) {
- Result result = results[resultIndex];
+ for (Result result : results) {
ParsedResult parsedResult = ResultParser.parseResult(result);
output.write(uri +
" (format: " + result.getBarcodeFormat() +
@@ -169,9 +168,7 @@ private static void dumpResult(URI input, Result... results) throws IOException
output.write('\n');
}
}
- if (resultIndex != results.length - 1) {
- output.write('\n');
- }
+ output.write('\n');
}
System.out.println(output);
}
View
@@ -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.3.1</proguard.version>
+ <proguard.version>5.3.2</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 -->
@@ -240,7 +240,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
- <version>3.0.1</version>
+ <version>3.0.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -523,7 +523,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
- <version>0.7.7.201606060606</version>
+ <version>0.7.8</version>
<executions>
<execution>
<goals>
View
@@ -57,7 +57,7 @@
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
- <version>9.4.0.RC2</version>
+ <version>9.4.0.v20161208</version>
</plugin>
</plugins>
</build>

0 comments on commit dfe4819

Please sign in to comment.