mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Minor changes from inspection
This commit is contained in:
parent
a8d01bd85f
commit
30bb62bf4f
|
@ -71,13 +71,9 @@ public final class RSS14Reader extends AbstractRSSReader {
|
||||||
Pair rightPair = decodePair(row, true, rowNumber, hints);
|
Pair rightPair = decodePair(row, true, rowNumber, hints);
|
||||||
addOrTally(possibleRightPairs, rightPair);
|
addOrTally(possibleRightPairs, rightPair);
|
||||||
row.reverse();
|
row.reverse();
|
||||||
int lefSize = possibleLeftPairs.size();
|
for (Pair left : possibleLeftPairs) {
|
||||||
for (int i = 0; i < lefSize; i++) {
|
|
||||||
Pair left = possibleLeftPairs.get(i);
|
|
||||||
if (left.getCount() > 1) {
|
if (left.getCount() > 1) {
|
||||||
int rightSize = possibleRightPairs.size();
|
for (Pair right : possibleRightPairs) {
|
||||||
for (int j = 0; j < rightSize; j++) {
|
|
||||||
Pair right = possibleRightPairs.get(j);
|
|
||||||
if (right.getCount() > 1) {
|
if (right.getCount() > 1) {
|
||||||
if (checkChecksum(left, right)) {
|
if (checkChecksum(left, right)) {
|
||||||
return constructResult(left, right);
|
return constructResult(left, right);
|
||||||
|
|
|
@ -216,9 +216,8 @@ public final class RSSExpandedReader extends AbstractRSSReader {
|
||||||
for (int i = currentRow; i < rows.size(); i++) {
|
for (int i = currentRow; i < rows.size(); i++) {
|
||||||
ExpandedRow row = rows.get(i);
|
ExpandedRow row = rows.get(i);
|
||||||
this.pairs.clear();
|
this.pairs.clear();
|
||||||
int size = collectedRows.size();
|
for (ExpandedRow collectedRow : collectedRows) {
|
||||||
for (int j = 0; j < size; j++) {
|
this.pairs.addAll(collectedRow.getPairs());
|
||||||
this.pairs.addAll(collectedRows.get(j).getPairs());
|
|
||||||
}
|
}
|
||||||
this.pairs.addAll(row.getPairs());
|
this.pairs.addAll(row.getPairs());
|
||||||
|
|
||||||
|
|
|
@ -34,13 +34,13 @@ import com.google.zxing.common.BitArray;
|
||||||
*/
|
*/
|
||||||
abstract class AI01decoder extends AbstractExpandedDecoder {
|
abstract class AI01decoder extends AbstractExpandedDecoder {
|
||||||
|
|
||||||
protected static final int GTIN_SIZE = 40;
|
static final int GTIN_SIZE = 40;
|
||||||
|
|
||||||
AI01decoder(BitArray information) {
|
AI01decoder(BitArray information) {
|
||||||
super(information);
|
super(information);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void encodeCompressedGtin(StringBuilder buf, int currentPos) {
|
final void encodeCompressedGtin(StringBuilder buf, int currentPos) {
|
||||||
buf.append("(01)");
|
buf.append("(01)");
|
||||||
int initialPosition = buf.length();
|
int initialPosition = buf.length();
|
||||||
buf.append('9');
|
buf.append('9');
|
||||||
|
@ -48,7 +48,7 @@ abstract class AI01decoder extends AbstractExpandedDecoder {
|
||||||
encodeCompressedGtinWithoutAI(buf, currentPos, initialPosition);
|
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){
|
for(int i = 0; i < 4; ++i){
|
||||||
int currentBlock = this.getGeneralDecoder().extractNumericValueFromBitArray(currentPos + 10 * i, 10);
|
int currentBlock = this.getGeneralDecoder().extractNumericValueFromBitArray(currentPos + 10 * i, 10);
|
||||||
if (currentBlock / 100 == 0) {
|
if (currentBlock / 100 == 0) {
|
||||||
|
|
|
@ -37,7 +37,7 @@ abstract class AI01weightDecoder extends AI01decoder {
|
||||||
super(information);
|
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);
|
int originalWeightNumeric = this.getGeneralDecoder().extractNumericValueFromBitArray(currentPos, weightSize);
|
||||||
addWeightCode(buf, originalWeightNumeric);
|
addWeightCode(buf, originalWeightNumeric);
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ public abstract class AbstractExpandedDecoder {
|
||||||
return information;
|
return information;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final GeneralAppIdDecoder getGeneralDecoder() {
|
final GeneralAppIdDecoder getGeneralDecoder() {
|
||||||
return generalDecoder;
|
return generalDecoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ import java.util.regex.Pattern;
|
||||||
public final class EncoderTest extends Assert {
|
public final class EncoderTest extends Assert {
|
||||||
|
|
||||||
private static final Pattern DOTX = Pattern.compile("[^.X]");
|
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];
|
private static final ResultPoint[] NO_POINTS = new ResultPoint[0];
|
||||||
|
|
||||||
// real life tests
|
// 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) {
|
private static void testModeMessage(boolean compact, int layers, int words, String expected) {
|
||||||
BitArray in = Encoder.generateModeMessage(compact, layers, words);
|
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) {
|
private static void testStuffBits(int wordSize, String bits, String expected) {
|
||||||
BitArray in = toBitArray(bits);
|
BitArray in = toBitArray(bits);
|
||||||
BitArray stuffed = Encoder.stuffBits(in, wordSize);
|
BitArray stuffed = Encoder.stuffBits(in, wordSize);
|
||||||
assertEquals("stuffBits() failed for input string: " + bits,
|
assertEquals("stuffBits() failed for input string: " + bits,
|
||||||
expected.replace(" ", ""),
|
stripSpace(expected), stripSpace(stuffed.toString()));
|
||||||
stuffed.toString().replace(" ", ""));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BitArray toBitArray(CharSequence bits) {
|
private static BitArray toBitArray(CharSequence bits) {
|
||||||
|
@ -539,16 +539,21 @@ public final class EncoderTest extends Assert {
|
||||||
|
|
||||||
private static void testHighLevelEncodeString(String s, String expectedBits) {
|
private static void testHighLevelEncodeString(String s, String expectedBits) {
|
||||||
BitArray bits = new HighLevelEncoder(s.getBytes(StandardCharsets.ISO_8859_1)).encode();
|
BitArray bits = new HighLevelEncoder(s.getBytes(StandardCharsets.ISO_8859_1)).encode();
|
||||||
String receivedBits = bits.toString().replace(" ", "");
|
String receivedBits = stripSpace(bits.toString());
|
||||||
assertEquals("highLevelEncode() failed for input string: " + s, expectedBits.replace(" ", ""), receivedBits);
|
assertEquals("highLevelEncode() failed for input string: " + s, stripSpace(expectedBits), receivedBits);
|
||||||
assertEquals(s, Decoder.highLevelDecode(toBooleanArray(bits)));
|
assertEquals(s, Decoder.highLevelDecode(toBooleanArray(bits)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testHighLevelEncodeString(String s, int expectedReceivedBits) {
|
private static void testHighLevelEncodeString(String s, int expectedReceivedBits) {
|
||||||
BitArray bits = new HighLevelEncoder(s.getBytes(StandardCharsets.ISO_8859_1)).encode();
|
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,
|
assertEquals("highLevelEncode() failed for input string: " + s,
|
||||||
expectedReceivedBits, receivedBitCount);
|
expectedReceivedBits, receivedBitCount);
|
||||||
assertEquals(s, Decoder.highLevelDecode(toBooleanArray(bits)));
|
assertEquals(s, Decoder.highLevelDecode(toBooleanArray(bits)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String stripSpace(String s) {
|
||||||
|
return SPACES.matcher(s).replaceAll("");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,15 +22,6 @@ final class DebugPlacement extends DefaultPlacement {
|
||||||
super(codewords, numcols, numrows);
|
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() {
|
String[] toBitFieldStringArray() {
|
||||||
byte[] bits = getBits();
|
byte[] bits = getBits();
|
||||||
int numrows = getNumrows();
|
int numrows = getNumrows();
|
||||||
|
|
|
@ -32,8 +32,8 @@ public class Code128WriterTestCase extends Assert {
|
||||||
private static final String FNC3 = "10111100010";
|
private static final String FNC3 = "10111100010";
|
||||||
private static final String FNC4 = "10111101110";
|
private static final String FNC4 = "10111101110";
|
||||||
private static final String START_CODE_B = "11010010000";
|
private static final String START_CODE_B = "11010010000";
|
||||||
public static final String QUIET_SPACE = "00000";
|
private static final String QUIET_SPACE = "00000";
|
||||||
public static final String STOP = "1100011101011";
|
private static final String STOP = "1100011101011";
|
||||||
|
|
||||||
private Writer writer;
|
private Writer writer;
|
||||||
|
|
||||||
|
|
|
@ -36,39 +36,39 @@ import org.junit.Assert;
|
||||||
/**
|
/**
|
||||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
* @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";
|
static final String numeric_10 = "..X..XX";
|
||||||
protected static final String numeric_12 = "..X.X.X";
|
static final String numeric_12 = "..X.X.X";
|
||||||
protected static final String numeric_1FNC1 = "..XXX.X";
|
static final String numeric_1FNC1 = "..XXX.X";
|
||||||
//protected static final String numeric_FNC11 = "XXX.XXX";
|
// static final String numeric_FNC11 = "XXX.XXX";
|
||||||
|
|
||||||
protected static final String numeric2alpha = "....";
|
static final String numeric2alpha = "....";
|
||||||
|
|
||||||
protected static final String alpha_A = "X.....";
|
static final String alpha_A = "X.....";
|
||||||
protected static final String alpha_FNC1 = ".XXXX";
|
static final String alpha_FNC1 = ".XXXX";
|
||||||
protected static final String alpha2numeric = "...";
|
static final String alpha2numeric = "...";
|
||||||
protected static final String alpha2isoiec646 = "..X..";
|
static final String alpha2isoiec646 = "..X..";
|
||||||
|
|
||||||
protected static final String i646_B = "X.....X";
|
static final String i646_B = "X.....X";
|
||||||
protected static final String i646_C = "X....X.";
|
static final String i646_C = "X....X.";
|
||||||
protected static final String i646_FNC1 = ".XXXX";
|
static final String i646_FNC1 = ".XXXX";
|
||||||
protected static final String isoiec646_2alpha = "..X..";
|
static final String isoiec646_2alpha = "..X..";
|
||||||
|
|
||||||
protected static final String compressedGtin_900123456798908 = ".........X..XXX.X.X.X...XX.XXXXX.XXXX.X.";
|
static final String compressedGtin_900123456798908 = ".........X..XXX.X.X.X...XX.XXXXX.XXXX.X.";
|
||||||
protected static final String compressedGtin_900000000000008 = "........................................";
|
static final String compressedGtin_900000000000008 = "........................................";
|
||||||
|
|
||||||
protected static final String compressed15bitWeight_1750 = "....XX.XX.X.XX.";
|
static final String compressed15bitWeight_1750 = "....XX.XX.X.XX.";
|
||||||
protected static final String compressed15bitWeight_11750 = ".X.XX.XXXX..XX.";
|
static final String compressed15bitWeight_11750 = ".X.XX.XXXX..XX.";
|
||||||
protected static final String compressed15bitWeight_0 = "...............";
|
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..";
|
static final String compressedDate_March_12th_2010 = "....XXXX.X..XX..";
|
||||||
protected static final String compressedDate_End = "X..X.XX.........";
|
static final String compressedDate_End = "X..X.XX.........";
|
||||||
|
|
||||||
protected static void assertCorrectBinaryString(CharSequence binaryString,
|
static void assertCorrectBinaryString(CharSequence binaryString,
|
||||||
String expectedNumber) throws NotFoundException, FormatException {
|
String expectedNumber) throws NotFoundException, FormatException {
|
||||||
BitArray binary = BinaryUtil.buildBitArrayFromStringWithoutSpaces(binaryString);
|
BitArray binary = BinaryUtil.buildBitArrayFromStringWithoutSpaces(binaryString);
|
||||||
AbstractExpandedDecoder decoder = AbstractExpandedDecoder.createDecoder(binary);
|
AbstractExpandedDecoder decoder = AbstractExpandedDecoder.createDecoder(binary);
|
||||||
String result = decoder.parseInformation();
|
String result = decoder.parseInformation();
|
||||||
|
|
|
@ -74,16 +74,14 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
|
||||||
testPDF417BlackBoxCountingResults(true);
|
testPDF417BlackBoxCountingResults(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SummaryResults testPDF417BlackBoxCountingResults(boolean assertOnFailure) throws IOException {
|
private SummaryResults testPDF417BlackBoxCountingResults(boolean assertOnFailure) throws IOException {
|
||||||
assertFalse(testResults.isEmpty());
|
assertFalse(testResults.isEmpty());
|
||||||
|
|
||||||
Map<String,List<Path>> imageFiles = getImageFileLists();
|
Map<String,List<Path>> imageFiles = getImageFileLists();
|
||||||
int testCount = testResults.size();
|
int testCount = testResults.size();
|
||||||
|
|
||||||
int[] passedCounts = new int[testCount];
|
int[] passedCounts = new int[testCount];
|
||||||
int[] misreadCounts = new int[testCount];
|
|
||||||
int[] tryHarderCounts = new int[testCount];
|
int[] tryHarderCounts = new int[testCount];
|
||||||
int[] tryHaderMisreadCounts = new int[testCount];
|
|
||||||
|
|
||||||
Path testBase = getTestBase();
|
Path testBase = getTestBase();
|
||||||
|
|
||||||
|
@ -144,8 +142,6 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
|
||||||
// Print the results of all tests first
|
// Print the results of all tests first
|
||||||
int totalFound = 0;
|
int totalFound = 0;
|
||||||
int totalMustPass = 0;
|
int totalMustPass = 0;
|
||||||
int totalMisread = 0;
|
|
||||||
int totalMaxMisread = 0;
|
|
||||||
|
|
||||||
int numberOfTests = imageFiles.keySet().size();
|
int numberOfTests = imageFiles.keySet().size();
|
||||||
for (int x = 0; x < testResults.size(); x++) {
|
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("Rotation %d degrees:", (int) testResult.getRotation()));
|
||||||
log.info(String.format(" %d of %d images passed (%d required)", passedCounts[x], numberOfTests,
|
log.info(String.format(" %d of %d images passed (%d required)", passedCounts[x], numberOfTests,
|
||||||
testResult.getMustPassCount()));
|
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],
|
log.info(String.format(" %d of %d images passed with try harder (%d required)", tryHarderCounts[x],
|
||||||
numberOfTests, testResult.getTryHarderCount()));
|
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];
|
totalFound += passedCounts[x] + tryHarderCounts[x];
|
||||||
totalMustPass += testResult.getMustPassCount() + testResult.getTryHarderCount();
|
totalMustPass += testResult.getMustPassCount() + testResult.getTryHarderCount();
|
||||||
totalMisread += misreadCounts[x] + tryHaderMisreadCounts[x];
|
|
||||||
totalMaxMisread += testResult.getMaxMisreads() + testResult.getMaxTryHarderMisreads();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int totalTests = numberOfTests * testCount * 2;
|
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));
|
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
|
// Then run through again and assert if any failed
|
||||||
if (assertOnFailure) {
|
if (assertOnFailure) {
|
||||||
for (int x = 0; x < testCount; x++) {
|
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";
|
String label = "Rotation " + testResult.getRotation() + " degrees: Too many images failed";
|
||||||
assertTrue(label, passedCounts[x] >= testResult.getMustPassCount());
|
assertTrue(label, passedCounts[x] >= testResult.getMustPassCount());
|
||||||
assertTrue("Try harder, " + label, tryHarderCounts[x] >= testResult.getTryHarderCount());
|
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);
|
return new SummaryResults(totalFound, totalMustPass, totalTests);
|
||||||
|
|
Loading…
Reference in a new issue