diff --git a/core/src/main/java/com/google/zxing/oned/rss/RSS14Reader.java b/core/src/main/java/com/google/zxing/oned/rss/RSS14Reader.java index 604a2aa7a..bbeeac1a4 100644 --- a/core/src/main/java/com/google/zxing/oned/rss/RSS14Reader.java +++ b/core/src/main/java/com/google/zxing/oned/rss/RSS14Reader.java @@ -71,13 +71,9 @@ public final class RSS14Reader extends AbstractRSSReader { Pair rightPair = decodePair(row, true, rowNumber, hints); addOrTally(possibleRightPairs, rightPair); row.reverse(); - int lefSize = possibleLeftPairs.size(); - for (int i = 0; i < lefSize; i++) { - Pair left = possibleLeftPairs.get(i); + for (Pair left : possibleLeftPairs) { if (left.getCount() > 1) { - int rightSize = possibleRightPairs.size(); - for (int j = 0; j < rightSize; j++) { - Pair right = possibleRightPairs.get(j); + for (Pair right : possibleRightPairs) { if (right.getCount() > 1) { if (checkChecksum(left, right)) { return constructResult(left, right); diff --git a/core/src/main/java/com/google/zxing/oned/rss/expanded/RSSExpandedReader.java b/core/src/main/java/com/google/zxing/oned/rss/expanded/RSSExpandedReader.java index e52829e87..f6b0859d4 100644 --- a/core/src/main/java/com/google/zxing/oned/rss/expanded/RSSExpandedReader.java +++ b/core/src/main/java/com/google/zxing/oned/rss/expanded/RSSExpandedReader.java @@ -216,9 +216,8 @@ public final class RSSExpandedReader extends AbstractRSSReader { for (int i = currentRow; i < rows.size(); i++) { ExpandedRow row = rows.get(i); this.pairs.clear(); - int size = collectedRows.size(); - for (int j = 0; j < size; j++) { - this.pairs.addAll(collectedRows.get(j).getPairs()); + for (ExpandedRow collectedRow : collectedRows) { + this.pairs.addAll(collectedRow.getPairs()); } this.pairs.addAll(row.getPairs()); diff --git a/core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI01decoder.java b/core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI01decoder.java index 49bc9f9b1..589d35bdc 100644 --- a/core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI01decoder.java +++ b/core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI01decoder.java @@ -34,13 +34,13 @@ import com.google.zxing.common.BitArray; */ abstract class AI01decoder extends AbstractExpandedDecoder { - protected static final int GTIN_SIZE = 40; + static final int GTIN_SIZE = 40; AI01decoder(BitArray information) { super(information); } - protected final void encodeCompressedGtin(StringBuilder buf, int currentPos) { + final void encodeCompressedGtin(StringBuilder buf, int currentPos) { buf.append("(01)"); int initialPosition = buf.length(); buf.append('9'); @@ -48,7 +48,7 @@ abstract class AI01decoder extends AbstractExpandedDecoder { encodeCompressedGtinWithoutAI(buf, currentPos, initialPosition); } - protected final void encodeCompressedGtinWithoutAI(StringBuilder buf, int currentPos, int initialBufferPosition) { + final void encodeCompressedGtinWithoutAI(StringBuilder buf, int currentPos, int initialBufferPosition) { for(int i = 0; i < 4; ++i){ int currentBlock = this.getGeneralDecoder().extractNumericValueFromBitArray(currentPos + 10 * i, 10); if (currentBlock / 100 == 0) { diff --git a/core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI01weightDecoder.java b/core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI01weightDecoder.java index 357a13dcb..beddc2ef7 100644 --- a/core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI01weightDecoder.java +++ b/core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AI01weightDecoder.java @@ -37,7 +37,7 @@ abstract class AI01weightDecoder extends AI01decoder { super(information); } - protected final void encodeCompressedWeight(StringBuilder buf, int currentPos, int weightSize) { + final void encodeCompressedWeight(StringBuilder buf, int currentPos, int weightSize) { int originalWeightNumeric = this.getGeneralDecoder().extractNumericValueFromBitArray(currentPos, weightSize); addWeightCode(buf, originalWeightNumeric); diff --git a/core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AbstractExpandedDecoder.java b/core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AbstractExpandedDecoder.java index bdb7e1085..53d133bf3 100644 --- a/core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AbstractExpandedDecoder.java +++ b/core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/AbstractExpandedDecoder.java @@ -48,7 +48,7 @@ public abstract class AbstractExpandedDecoder { return information; } - protected final GeneralAppIdDecoder getGeneralDecoder() { + final GeneralAppIdDecoder getGeneralDecoder() { return generalDecoder; } diff --git a/core/src/test/java/com/google/zxing/aztec/encoder/EncoderTest.java b/core/src/test/java/com/google/zxing/aztec/encoder/EncoderTest.java index 5331ad14b..15de77263 100644 --- a/core/src/test/java/com/google/zxing/aztec/encoder/EncoderTest.java +++ b/core/src/test/java/com/google/zxing/aztec/encoder/EncoderTest.java @@ -45,6 +45,7 @@ import java.util.regex.Pattern; public final class EncoderTest extends Assert { private static final Pattern DOTX = Pattern.compile("[^.X]"); + private static final Pattern SPACES = Pattern.compile("\\s+"); private static final ResultPoint[] NO_POINTS = new ResultPoint[0]; // real life tests @@ -509,15 +510,14 @@ public final class EncoderTest extends Assert { private static void testModeMessage(boolean compact, int layers, int words, String expected) { BitArray in = Encoder.generateModeMessage(compact, layers, words); - assertEquals("generateModeMessage() failed", expected.replace(" ", ""), in.toString().replace(" ", "")); + assertEquals("generateModeMessage() failed", stripSpace(expected), stripSpace(in.toString())); } private static void testStuffBits(int wordSize, String bits, String expected) { BitArray in = toBitArray(bits); BitArray stuffed = Encoder.stuffBits(in, wordSize); assertEquals("stuffBits() failed for input string: " + bits, - expected.replace(" ", ""), - stuffed.toString().replace(" ", "")); + stripSpace(expected), stripSpace(stuffed.toString())); } private static BitArray toBitArray(CharSequence bits) { @@ -539,16 +539,21 @@ public final class EncoderTest extends Assert { private static void testHighLevelEncodeString(String s, String expectedBits) { BitArray bits = new HighLevelEncoder(s.getBytes(StandardCharsets.ISO_8859_1)).encode(); - String receivedBits = bits.toString().replace(" ", ""); - assertEquals("highLevelEncode() failed for input string: " + s, expectedBits.replace(" ", ""), receivedBits); + String receivedBits = stripSpace(bits.toString()); + assertEquals("highLevelEncode() failed for input string: " + s, stripSpace(expectedBits), receivedBits); assertEquals(s, Decoder.highLevelDecode(toBooleanArray(bits))); } private static void testHighLevelEncodeString(String s, int expectedReceivedBits) { BitArray bits = new HighLevelEncoder(s.getBytes(StandardCharsets.ISO_8859_1)).encode(); - int receivedBitCount = bits.toString().replace(" ", "").length(); + int receivedBitCount = stripSpace(bits.toString()).length(); assertEquals("highLevelEncode() failed for input string: " + s, expectedReceivedBits, receivedBitCount); assertEquals(s, Decoder.highLevelDecode(toBooleanArray(bits))); } + + private static String stripSpace(String s) { + return SPACES.matcher(s).replaceAll(""); + } + } diff --git a/core/src/test/java/com/google/zxing/datamatrix/encoder/DebugPlacement.java b/core/src/test/java/com/google/zxing/datamatrix/encoder/DebugPlacement.java index db3503e53..60aed9c6e 100644 --- a/core/src/test/java/com/google/zxing/datamatrix/encoder/DebugPlacement.java +++ b/core/src/test/java/com/google/zxing/datamatrix/encoder/DebugPlacement.java @@ -22,15 +22,6 @@ final class DebugPlacement extends DefaultPlacement { super(codewords, numcols, numrows); } - public String toBitFieldString() { - byte[] bits = getBits(); - StringBuilder sb = new StringBuilder(bits.length); - for (byte bit : bits) { - sb.append(bit == 1 ? '1' : '0'); - } - return sb.toString(); - } - String[] toBitFieldStringArray() { byte[] bits = getBits(); int numrows = getNumrows(); diff --git a/core/src/test/java/com/google/zxing/oned/Code128WriterTestCase.java b/core/src/test/java/com/google/zxing/oned/Code128WriterTestCase.java index cf68414fb..1d26507d4 100644 --- a/core/src/test/java/com/google/zxing/oned/Code128WriterTestCase.java +++ b/core/src/test/java/com/google/zxing/oned/Code128WriterTestCase.java @@ -32,8 +32,8 @@ public class Code128WriterTestCase extends Assert { private static final String FNC3 = "10111100010"; private static final String FNC4 = "10111101110"; private static final String START_CODE_B = "11010010000"; - public static final String QUIET_SPACE = "00000"; - public static final String STOP = "1100011101011"; + private static final String QUIET_SPACE = "00000"; + private static final String STOP = "1100011101011"; private Writer writer; diff --git a/core/src/test/java/com/google/zxing/oned/rss/expanded/decoders/AbstractDecoderTest.java b/core/src/test/java/com/google/zxing/oned/rss/expanded/decoders/AbstractDecoderTest.java index 96a689126..0cc69835a 100644 --- a/core/src/test/java/com/google/zxing/oned/rss/expanded/decoders/AbstractDecoderTest.java +++ b/core/src/test/java/com/google/zxing/oned/rss/expanded/decoders/AbstractDecoderTest.java @@ -36,39 +36,39 @@ import org.junit.Assert; /** * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es) */ -public abstract class AbstractDecoderTest extends Assert { +abstract class AbstractDecoderTest extends Assert { - protected static final String numeric_10 = "..X..XX"; - protected static final String numeric_12 = "..X.X.X"; - protected static final String numeric_1FNC1 = "..XXX.X"; - //protected static final String numeric_FNC11 = "XXX.XXX"; + static final String numeric_10 = "..X..XX"; + static final String numeric_12 = "..X.X.X"; + static final String numeric_1FNC1 = "..XXX.X"; + // static final String numeric_FNC11 = "XXX.XXX"; - protected static final String numeric2alpha = "...."; + static final String numeric2alpha = "...."; - protected static final String alpha_A = "X....."; - protected static final String alpha_FNC1 = ".XXXX"; - protected static final String alpha2numeric = "..."; - protected static final String alpha2isoiec646 = "..X.."; + static final String alpha_A = "X....."; + static final String alpha_FNC1 = ".XXXX"; + static final String alpha2numeric = "..."; + static final String alpha2isoiec646 = "..X.."; - protected static final String i646_B = "X.....X"; - protected static final String i646_C = "X....X."; - protected static final String i646_FNC1 = ".XXXX"; - protected static final String isoiec646_2alpha = "..X.."; + static final String i646_B = "X.....X"; + static final String i646_C = "X....X."; + static final String i646_FNC1 = ".XXXX"; + static final String isoiec646_2alpha = "..X.."; - protected static final String compressedGtin_900123456798908 = ".........X..XXX.X.X.X...XX.XXXXX.XXXX.X."; - protected static final String compressedGtin_900000000000008 = "........................................"; + static final String compressedGtin_900123456798908 = ".........X..XXX.X.X.X...XX.XXXXX.XXXX.X."; + static final String compressedGtin_900000000000008 = "........................................"; - protected static final String compressed15bitWeight_1750 = "....XX.XX.X.XX."; - protected static final String compressed15bitWeight_11750 = ".X.XX.XXXX..XX."; - protected static final String compressed15bitWeight_0 = "..............."; + static final String compressed15bitWeight_1750 = "....XX.XX.X.XX."; + static final String compressed15bitWeight_11750 = ".X.XX.XXXX..XX."; + static final String compressed15bitWeight_0 = "..............."; - protected static final String compressed20bitWeight_1750 = ".........XX.XX.X.XX."; + static final String compressed20bitWeight_1750 = ".........XX.XX.X.XX."; - protected static final String compressedDate_March_12th_2010 = "....XXXX.X..XX.."; - protected static final String compressedDate_End = "X..X.XX........."; + static final String compressedDate_March_12th_2010 = "....XXXX.X..XX.."; + static final String compressedDate_End = "X..X.XX........."; - protected static void assertCorrectBinaryString(CharSequence binaryString, - String expectedNumber) throws NotFoundException, FormatException { + static void assertCorrectBinaryString(CharSequence binaryString, + String expectedNumber) throws NotFoundException, FormatException { BitArray binary = BinaryUtil.buildBitArrayFromStringWithoutSpaces(binaryString); AbstractExpandedDecoder decoder = AbstractExpandedDecoder.createDecoder(binary); String result = decoder.parseInformation(); diff --git a/core/src/test/java/com/google/zxing/pdf417/PDF417BlackBox4TestCase.java b/core/src/test/java/com/google/zxing/pdf417/PDF417BlackBox4TestCase.java index 01ac1e34c..e93f0cfd0 100644 --- a/core/src/test/java/com/google/zxing/pdf417/PDF417BlackBox4TestCase.java +++ b/core/src/test/java/com/google/zxing/pdf417/PDF417BlackBox4TestCase.java @@ -74,16 +74,14 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase { testPDF417BlackBoxCountingResults(true); } - SummaryResults testPDF417BlackBoxCountingResults(boolean assertOnFailure) throws IOException { + private SummaryResults testPDF417BlackBoxCountingResults(boolean assertOnFailure) throws IOException { assertFalse(testResults.isEmpty()); Map> imageFiles = getImageFileLists(); int testCount = testResults.size(); int[] passedCounts = new int[testCount]; - int[] misreadCounts = new int[testCount]; int[] tryHarderCounts = new int[testCount]; - int[] tryHaderMisreadCounts = new int[testCount]; Path testBase = getTestBase(); @@ -144,8 +142,6 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase { // Print the results of all tests first int totalFound = 0; int totalMustPass = 0; - int totalMisread = 0; - int totalMaxMisread = 0; int numberOfTests = imageFiles.keySet().size(); for (int x = 0; x < testResults.size(); x++) { @@ -153,18 +149,10 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase { log.info(String.format("Rotation %d degrees:", (int) testResult.getRotation())); log.info(String.format(" %d of %d images passed (%d required)", passedCounts[x], numberOfTests, testResult.getMustPassCount())); - int failed = numberOfTests - passedCounts[x]; - log.info(String - .format(" %d failed due to misreads, %d not detected", misreadCounts[x], failed - misreadCounts[x])); log.info(String.format(" %d of %d images passed with try harder (%d required)", tryHarderCounts[x], numberOfTests, testResult.getTryHarderCount())); - failed = numberOfTests - tryHarderCounts[x]; - log.info(String.format(" %d failed due to misreads, %d not detected", tryHaderMisreadCounts[x], failed - - tryHaderMisreadCounts[x])); totalFound += passedCounts[x] + tryHarderCounts[x]; totalMustPass += testResult.getMustPassCount() + testResult.getTryHarderCount(); - totalMisread += misreadCounts[x] + tryHaderMisreadCounts[x]; - totalMaxMisread += testResult.getMaxMisreads() + testResult.getMaxTryHarderMisreads(); } int totalTests = numberOfTests * testCount * 2; @@ -177,12 +165,6 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase { log.warning(String.format("--- Test failed by %d images", totalMustPass - totalFound)); } - if (totalMisread < totalMaxMisread) { - log.warning(String.format("+++ Test expects too many misreads by %d images", totalMaxMisread - totalMisread)); - } else if (totalMisread > totalMaxMisread) { - log.warning(String.format("--- Test had too many misreads by %d images", totalMisread - totalMaxMisread)); - } - // Then run through again and assert if any failed if (assertOnFailure) { for (int x = 0; x < testCount; x++) { @@ -190,9 +172,6 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase { String label = "Rotation " + testResult.getRotation() + " degrees: Too many images failed"; assertTrue(label, passedCounts[x] >= testResult.getMustPassCount()); assertTrue("Try harder, " + label, tryHarderCounts[x] >= testResult.getTryHarderCount()); - label = "Rotation " + testResult.getRotation() + " degrees: Too many images misread"; - assertTrue(label, misreadCounts[x] <= testResult.getMaxMisreads()); - assertTrue("Try harder, " + label, tryHaderMisreadCounts[x] <= testResult.getMaxTryHarderMisreads()); } } return new SummaryResults(totalFound, totalMustPass, totalTests);