Minor inspection stuff

git-svn-id: https://zxing.googlecode.com/svn/trunk@2247 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2012-04-05 17:41:28 +00:00
parent 7541fcda65
commit 346de1b561
20 changed files with 90 additions and 104 deletions

View file

@ -78,16 +78,14 @@ abstract class ContactEncoder {
Collection<String> uniques = new HashSet<String>(2);
for (String value : values) {
String trimmed = trim(value);
if (trimmed != null) {
if (!uniques.contains(trimmed)) {
newContents.append(prefix).append(':').append(fieldFormatter.format(trimmed)).append(terminator);
String display = formatter == null ? trimmed : formatter.format(trimmed);
newDisplayContents.append(display).append('\n');
if (++count == max) {
break;
}
uniques.add(trimmed);
if (trimmed != null && !uniques.contains(trimmed)) {
newContents.append(prefix).append(':').append(fieldFormatter.format(trimmed)).append(terminator);
String display = formatter == null ? trimmed : formatter.format(trimmed);
newDisplayContents.append(display).append('\n');
if (++count == max) {
break;
}
uniques.add(trimmed);
}
}
}

View file

@ -78,7 +78,7 @@ public final class MultiFormatWriter implements Writer {
writer = new PDF417Writer();
break;
case CODABAR:
writer = new CodaBarWriter();
writer = new CodaBarWriter();
break;
default:
throw new IllegalArgumentException("No encoder available for format " + format);

View file

@ -18,7 +18,6 @@ package com.google.zxing.aztec;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.ChecksumException;
import com.google.zxing.DecodeHintType;
import com.google.zxing.FormatException;
import com.google.zxing.NotFoundException;
@ -47,7 +46,7 @@ public final class AztecReader implements Reader {
* @return a String representing the content encoded by the Data Matrix code
* @throws NotFoundException if a Data Matrix code cannot be found
* @throws FormatException if a Data Matrix code cannot be decoded
* @throws ChecksumException if error correction fails
* @throws com.google.zxing.ChecksumException if error correction fails
*/
@Override
public Result decode(BinaryBitmap image) throws NotFoundException, FormatException {

View file

@ -598,7 +598,7 @@ public final class Detector {
return new Point(x,y);
}
private static class Point {
private static final class Point {
public final int x;
public final int y;

View file

@ -207,9 +207,7 @@ public final class VCardResultParser extends ResultParser {
case '=':
if (i < length - 2) {
char nextChar = value.charAt(i+1);
if (nextChar == '\r' || nextChar == '\n') {
// Ignore, it's just a continuation symbol
} else {
if (nextChar != '\r' && nextChar != '\n') {
char nextNextChar = value.charAt(i+2);
int firstDigit = parseHexDigit(nextChar);
int secondDigit = parseHexDigit(nextNextChar);

View file

@ -168,14 +168,14 @@ public final class HybridBinarizer extends GlobalHistogramBinarizer {
}
}
// short-circuit min/max tests once dynamic range is met
if (max - min > MIN_DYNAMIC_RANGE) {
// finish the rest of the rows quickly
for (yy++, offset += width; yy < BLOCK_SIZE; yy++, offset += width) {
for (int xx = 0; xx < BLOCK_SIZE; xx++) {
sum += luminances[offset + xx] & 0xFF;
}
}
}
if (max - min > MIN_DYNAMIC_RANGE) {
// finish the rest of the rows quickly
for (yy++, offset += width; yy < BLOCK_SIZE; yy++, offset += width) {
for (int xx = 0; xx < BLOCK_SIZE; xx++) {
sum += luminances[offset + xx] & 0xFF;
}
}
}
}
// The default estimate is the average of the values in the block.

View file

@ -174,9 +174,7 @@ final class DecodedBitStreamParser {
// Ignore this symbol for now
} else if (oneByte >= 242) { // Not to be used in ASCII encodation
// ... but work around encoders that end with 254, latch back to ASCII
if (oneByte == 254 && bits.available() == 0) {
// Ignore
} else {
if (oneByte != 254 || bits.available() != 0) {
throw FormatException.getFormatInstance();
}
}

View file

@ -159,8 +159,8 @@ public final class Detector {
// than twice the other, it's certainly rectangular, but to cut a bit more slack we accept it as
// rectangular if the bigger side is at least 7/4 times the other:
if (4 * dimensionTop >= 7 * dimensionRight || 4 * dimensionRight >= 7 * dimensionTop) {
// The matrix is rectangular
// The matrix is rectangular
correctedTopRight =
correctTopRightRectangular(bottomLeft, bottomRight, topLeft, topRight, dimensionTop, dimensionRight);
if (correctedTopRight == null){
@ -183,9 +183,9 @@ public final class Detector {
bits = sampleGrid(image, topLeft, bottomLeft, bottomRight, correctedTopRight, dimensionTop, dimensionRight);
} else {
// The matrix is square
// The matrix is square
int dimension = Math.min(dimensionRight, dimensionTop);
int dimension = Math.min(dimensionRight, dimensionTop);
// correct top right point to match the white module
correctedTopRight = correctTopRight(bottomLeft, bottomRight, topLeft, topRight, dimension);
if (correctedTopRight == null){
@ -222,20 +222,20 @@ public final class Detector {
ResultPoint topRight,
int dimensionTop,
int dimensionRight) {
float corr = distance(bottomLeft, bottomRight) / (float)dimensionTop;
int norm = distance(topLeft, topRight);
float cos = (topRight.getX() - topLeft.getX()) / norm;
float sin = (topRight.getY() - topLeft.getY()) / norm;
ResultPoint c1 = new ResultPoint(topRight.getX()+corr*cos, topRight.getY()+corr*sin);
corr = distance(bottomLeft, topLeft) / (float)dimensionRight;
norm = distance(bottomRight, topRight);
cos = (topRight.getX() - bottomRight.getX()) / norm;
sin = (topRight.getY() - bottomRight.getY()) / norm;
ResultPoint c2 = new ResultPoint(topRight.getX()+corr*cos, topRight.getY()+corr*sin);
float corr = distance(bottomLeft, bottomRight) / (float)dimensionTop;
int norm = distance(topLeft, topRight);
float cos = (topRight.getX() - topLeft.getX()) / norm;
float sin = (topRight.getY() - topLeft.getY()) / norm;
ResultPoint c1 = new ResultPoint(topRight.getX()+corr*cos, topRight.getY()+corr*sin);
corr = distance(bottomLeft, topLeft) / (float)dimensionRight;
norm = distance(bottomRight, topRight);
cos = (topRight.getX() - bottomRight.getX()) / norm;
sin = (topRight.getY() - bottomRight.getY()) / norm;
ResultPoint c2 = new ResultPoint(topRight.getX()+corr*cos, topRight.getY()+corr*sin);
if (!isValid(c1)) {
if (isValid(c2)) {
@ -248,15 +248,15 @@ public final class Detector {
}
int l1 = Math.abs(dimensionTop - transitionsBetween(topLeft, c1).getTransitions()) +
Math.abs(dimensionRight - transitionsBetween(bottomRight, c1).getTransitions());
int l2 = Math.abs(dimensionTop - transitionsBetween(topLeft, c2).getTransitions()) +
Math.abs(dimensionRight - transitionsBetween(bottomRight, c2).getTransitions());
if (l1 <= l2){
return c1;
}
return c2;
Math.abs(dimensionRight - transitionsBetween(bottomRight, c1).getTransitions());
int l2 = Math.abs(dimensionTop - transitionsBetween(topLeft, c2).getTransitions()) +
Math.abs(dimensionRight - transitionsBetween(bottomRight, c2).getTransitions());
if (l1 <= l2){
return c1;
}
return c2;
}
/**
@ -268,20 +268,20 @@ public final class Detector {
ResultPoint topLeft,
ResultPoint topRight,
int dimension) {
float corr = distance(bottomLeft, bottomRight) / (float) dimension;
int norm = distance(topLeft, topRight);
float cos = (topRight.getX() - topLeft.getX()) / norm;
float sin = (topRight.getY() - topLeft.getY()) / norm;
ResultPoint c1 = new ResultPoint(topRight.getX() + corr * cos, topRight.getY() + corr * sin);
corr = distance(bottomLeft, topLeft) / (float) dimension;
norm = distance(bottomRight, topRight);
cos = (topRight.getX() - bottomRight.getX()) / norm;
sin = (topRight.getY() - bottomRight.getY()) / norm;
ResultPoint c2 = new ResultPoint(topRight.getX() + corr * cos, topRight.getY() + corr * sin);
float corr = distance(bottomLeft, bottomRight) / (float) dimension;
int norm = distance(topLeft, topRight);
float cos = (topRight.getX() - topLeft.getX()) / norm;
float sin = (topRight.getY() - topLeft.getY()) / norm;
ResultPoint c1 = new ResultPoint(topRight.getX() + corr * cos, topRight.getY() + corr * sin);
corr = distance(bottomLeft, topLeft) / (float) dimension;
norm = distance(bottomRight, topRight);
cos = (topRight.getX() - bottomRight.getX()) / norm;
sin = (topRight.getY() - bottomRight.getY()) / norm;
ResultPoint c2 = new ResultPoint(topRight.getX() + corr * cos, topRight.getY() + corr * sin);
if (!isValid(c1)) {
if (isValid(c2)) {
@ -295,14 +295,14 @@ public final class Detector {
int l1 = Math.abs(transitionsBetween(topLeft, c1).getTransitions() -
transitionsBetween(bottomRight, c1).getTransitions());
int l2 = Math.abs(transitionsBetween(topLeft, c2).getTransitions() -
int l2 = Math.abs(transitionsBetween(topLeft, c2).getTransitions() -
transitionsBetween(bottomRight, c2).getTransitions());
return l1 <= l2 ? c1 : c2;
}
private boolean isValid(ResultPoint p) {
return p.getX() >= 0 && p.getX() < image.getWidth() && p.getY() > 0 && p.getY() < image.getHeight();
return p.getX() >= 0 && p.getX() < image.getWidth() && p.getY() > 0 && p.getY() < image.getHeight();
}
/**
@ -406,7 +406,7 @@ public final class Detector {
/**
* Simply encapsulates two points and a number of transitions between them.
*/
private static class ResultPointsAndTransitions {
private static final class ResultPointsAndTransitions {
private final ResultPoint from;
private final ResultPoint to;

View file

@ -16,7 +16,6 @@
package com.google.zxing.maxicode.decoder;
import com.google.zxing.FormatException;
import com.google.zxing.common.BitMatrix;
/**
@ -65,7 +64,6 @@ final class BitMatrixParser {
/**
* @param bitMatrix {@link BitMatrix} to parse
* @throws FormatException if height is not 33 or width is not 30
*/
BitMatrixParser(BitMatrix bitMatrix) {
this.bitMatrix = bitMatrix;

View file

@ -191,12 +191,10 @@ public final class Code128Reader extends OneDReader {
bestMatch = startCode;
}
}
if (bestMatch >= 0) {
// Look for whitespace before start pattern, >= 50% of width of start pattern
if (row.isRange(Math.max(0, patternStart - (i - patternStart) / 2), patternStart,
false)) {
return new int[]{patternStart, i, bestMatch};
}
// Look for whitespace before start pattern, >= 50% of width of start pattern
if (bestMatch >= 0 &&
row.isRange(Math.max(0, patternStart - (i - patternStart) / 2), patternStart, false)) {
return new int[]{patternStart, i, bestMatch};
}
patternStart += counters[0] + counters[1];
System.arraycopy(counters, 2, counters, 0, patternLength - 2);

View file

@ -184,11 +184,10 @@ public final class Code39Reader extends OneDReader {
counters[counterPosition]++;
} else {
if (counterPosition == patternLength - 1) {
if (toNarrowWidePattern(counters) == ASTERISK_ENCODING) {
// Look for whitespace before start pattern, >= 50% of width of start pattern
if (row.isRange(Math.max(0, patternStart - ((i - patternStart) >> 1)), patternStart, false)) {
return new int[]{patternStart, i};
}
// Look for whitespace before start pattern, >= 50% of width of start pattern
if (toNarrowWidePattern(counters) == ASTERISK_ENCODING &&
row.isRange(Math.max(0, patternStart - ((i - patternStart) >> 1)), patternStart, false)) {
return new int[]{patternStart, i};
}
patternStart += counters[0] + counters[1];
System.arraycopy(counters, 2, counters, 0, patternLength - 2);

View file

@ -67,7 +67,7 @@ public final class ITFWriter extends UPCEANWriter {
pos += appendPattern(result, pos, encoding, 1);
}
int[] end = {3, 1, 1};
pos += appendPattern(result, pos, end, 1);
appendPattern(result, pos, end, 1);
return result;
}

View file

@ -316,8 +316,6 @@ final class DecodedBitStreamParser {
ch = ' ';
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
subMode = Mode.ALPHA;
} else {
// is this even possible?
}
}
break;

View file

@ -33,7 +33,7 @@ public final class ModulusGF {
private final int modulus;
public ModulusGF(int modulus, int generator) {
this.modulus = modulus;
this.modulus = modulus;
expTable = new int[modulus];
logTable = new int[modulus];
int x = 1;

View file

@ -93,11 +93,11 @@ final class DecodedBitStreamParser {
} else {
// First handle Hanzi mode which does not start with character count
if (mode == Mode.HANZI) {
//chinese mode contains a sub set indicator right after mode indicator
int subset = bits.readBits(4);
int countHanzi = bits.readBits(mode.getCharacterCountBits(version));
if (subset == GB2312_SUBSET) {
decodeHanziSegment(bits, result, countHanzi);
//chinese mode contains a sub set indicator right after mode indicator
int subset = bits.readBits(4);
int countHanzi = bits.readBits(mode.getCharacterCountBits(version));
if (subset == GB2312_SUBSET) {
decodeHanziSegment(bits, result, countHanzi);
}
} else {
// "Normal" QR code modes:

View file

@ -70,7 +70,7 @@ public enum Mode {
case 0x9:
return FNC1_SECOND_POSITION;
case 0xD:
// 0xD is defined in GBT 18284-2000, may not be supported in foreign country
// 0xD is defined in GBT 18284-2000, may not be supported in foreign country
return HANZI;
default:
throw new IllegalArgumentException();

View file

@ -152,12 +152,14 @@ public class Detector {
if (alignmentPattern != null) {
bottomRightX = alignmentPattern.getX();
bottomRightY = alignmentPattern.getY();
sourceBottomRightX = sourceBottomRightY = dimMinusThree - 3.0f;
sourceBottomRightX = dimMinusThree - 3.0f;
sourceBottomRightY = sourceBottomRightX;
} else {
// Don't have an alignment pattern, just make up the bottom-right point
bottomRightX = (topRight.getX() - topLeft.getX()) + bottomLeft.getX();
bottomRightY = (topRight.getY() - topLeft.getY()) + bottomLeft.getY();
sourceBottomRightX = sourceBottomRightY = dimMinusThree;
sourceBottomRightX = dimMinusThree;
sourceBottomRightY = dimMinusThree;
}
return PerspectiveTransform.quadrilateralToQuadrilateral(

View file

@ -549,7 +549,7 @@ public class FinderPatternFinder {
/**
* <p>Orders by furthest from average</p>
*/
private static class FurthestFromAverageComparator implements Comparator<FinderPattern>, Serializable {
private static final class FurthestFromAverageComparator implements Comparator<FinderPattern>, Serializable {
private final float average;
private FurthestFromAverageComparator(float f) {
average = f;
@ -565,7 +565,7 @@ public class FinderPatternFinder {
/**
* <p>Orders by {@link FinderPattern#getCount()}, descending.</p>
*/
private static class CenterComparator implements Comparator<FinderPattern>, Serializable {
private static final class CenterComparator implements Comparator<FinderPattern>, Serializable {
private final float average;
private CenterComparator(float f) {
average = f;

View file

@ -542,7 +542,7 @@ public final class Encoder {
try {
bytes = content.getBytes(encoding);
} catch (UnsupportedEncodingException uee) {
throw new WriterException(uee.toString());
throw new WriterException(uee);
}
for (byte b : bytes) {
bits.appendBits(b, 8);
@ -554,7 +554,7 @@ public final class Encoder {
try {
bytes = content.getBytes("Shift_JIS");
} catch (UnsupportedEncodingException uee) {
throw new WriterException(uee.toString());
throw new WriterException(uee);
}
int length = bytes.length;
for (int i = 0; i < length; i += 2) {

View file

@ -255,10 +255,8 @@ final class MatrixUtil {
}
// Skip masking if mask_pattern is -1.
if (maskPattern != -1) {
if (MaskUtil.getDataMaskBit(maskPattern, xx, y)) {
bit = !bit;
}
if (maskPattern != -1 && MaskUtil.getDataMaskBit(maskPattern, xx, y)) {
bit = !bit;
}
matrix.set(xx, y, bit);
}