diff options
| author | Sean Owen <srowen@gmail.com> | 2016-11-29 15:16:07 +0300 |
|---|---|---|
| committer | Sean Owen <srowen@gmail.com> | 2016-11-29 15:16:07 +0300 |
| commit | 0dfda0807876a53be295fa0abafd53866edf13bd (patch) | |
| tree | 18520e63e57e51361b7fe06ab0a3c8c69fdd3e7d /core/src | |
| parent | 64eb07747e24468d62bd86998dfa064832192d96 (diff) | |
| download | zxing-0dfda0807876a53be295fa0abafd53866edf13bd.tar.xz | |
Fix typos; avoid use of java.util.Date; other small improvements from inspection; deprecate some accidentally-public methods
Diffstat (limited to 'core/src')
24 files changed, 137 insertions, 121 deletions
diff --git a/core/src/main/java/com/google/zxing/aztec/decoder/Decoder.java b/core/src/main/java/com/google/zxing/aztec/decoder/Decoder.java index 508dd21c9..d456dd1ba 100644 --- a/core/src/main/java/com/google/zxing/aztec/decoder/Decoder.java +++ b/core/src/main/java/com/google/zxing/aztec/decoder/Decoder.java @@ -133,7 +133,7 @@ public final class Decoder { String str = getCharacter(shiftTable, code); if (str.startsWith("CTRL_")) { // Table changes - // ISO/IEC 24778:2008 prescibes ending a shift sequence in the mode from which it was invoked. + // ISO/IEC 24778:2008 prescribes ending a shift sequence in the mode from which it was invoked. // That's including when that mode is a shift. // Our test case dlusbs.png for issue #642 exercises that. latchTable = shiftTable; // Latch the current mode, so as to return to Upper after U/S B/S diff --git a/core/src/main/java/com/google/zxing/client/result/CalendarParsedResult.java b/core/src/main/java/com/google/zxing/client/result/CalendarParsedResult.java index 0bca993e3..7b478a323 100644 --- a/core/src/main/java/com/google/zxing/client/result/CalendarParsedResult.java +++ b/core/src/main/java/com/google/zxing/client/result/CalendarParsedResult.java @@ -48,9 +48,9 @@ public final class CalendarParsedResult extends ParsedResult { private static final Pattern DATE_TIME = Pattern.compile("[0-9]{8}(T[0-9]{6}Z?)?"); private final String summary; - private final Date start; + private final long start; private final boolean startAllDay; - private final Date end; + private final long end; private final boolean endAllDay; private final String location; private final String organizer; @@ -80,7 +80,7 @@ public final class CalendarParsedResult extends ParsedResult { if (endString == null) { long durationMS = parseDurationMS(durationString); - end = durationMS < 0L ? null : new Date(start.getTime() + durationMS); + end = durationMS < 0L ? -1L : start + durationMS; } else { try { this.end = parseDate(endString); @@ -106,8 +106,18 @@ public final class CalendarParsedResult extends ParsedResult { /** * @return start time + * @deprecated use {@link #getStartTimestamp()} */ + @Deprecated public Date getStart() { + return new Date(start); + } + + /** + * @return start time + * @see #getEndTimestamp() + */ + public long getStartTimestamp() { return start; } @@ -120,9 +130,18 @@ public final class CalendarParsedResult extends ParsedResult { /** * @return event end {@link Date}, or {@code null} if event has no duration - * @see #getStart() + * @deprecated use {@link #getEndTimestamp()} */ + @Deprecated public Date getEnd() { + return end < 0L ? null : new Date(end); + } + + /** + * @return event end {@link Date}, or -1 if event has no duration + * @see #getStartTimestamp() + */ + public long getEndTimestamp() { return end; } @@ -177,36 +196,35 @@ public final class CalendarParsedResult extends ParsedResult { * @param when The string to parse * @throws ParseException if not able to parse as a date */ - private static Date parseDate(String when) throws ParseException { + private static long parseDate(String when) throws ParseException { if (!DATE_TIME.matcher(when).matches()) { throw new ParseException(when, 0); } if (when.length() == 8) { // Show only year/month/day - return buildDateFormat().parse(when); - } else { - // The when string can be local time, or UTC if it ends with a Z - Date date; - if (when.length() == 16 && when.charAt(15) == 'Z') { - date = buildDateTimeFormat().parse(when.substring(0, 15)); - Calendar calendar = new GregorianCalendar(); - long milliseconds = date.getTime(); - // Account for time zone difference - milliseconds += calendar.get(Calendar.ZONE_OFFSET); - // Might need to correct for daylight savings time, but use target time since - // now might be in DST but not then, or vice versa - calendar.setTime(new Date(milliseconds)); - milliseconds += calendar.get(Calendar.DST_OFFSET); - date = new Date(milliseconds); - } else { - date = buildDateTimeFormat().parse(when); - } - return date; + DateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.ENGLISH); + // For dates without a time, for purposes of interacting with Android, the resulting timestamp + // needs to be midnight of that day in GMT. See: + // http://code.google.com/p/android/issues/detail?id=8330 + format.setTimeZone(TimeZone.getTimeZone("GMT")); + return format.parse(when).getTime(); } + // The when string can be local time, or UTC if it ends with a Z + if (when.length() == 16 && when.charAt(15) == 'Z') { + long milliseconds = parseDateTimeString(when.substring(0, 15)); + Calendar calendar = new GregorianCalendar(); + // Account for time zone difference + milliseconds += calendar.get(Calendar.ZONE_OFFSET); + // Might need to correct for daylight savings time, but use target time since + // now might be in DST but not then, or vice versa + calendar.setTime(new Date(milliseconds)); + return milliseconds + calendar.get(Calendar.DST_OFFSET); + } + return parseDateTimeString(when); } - private static String format(boolean allDay, Date date) { - if (date == null) { + private static String format(boolean allDay, long date) { + if (date < 0L) { return null; } DateFormat format = allDay @@ -233,17 +251,9 @@ public final class CalendarParsedResult extends ParsedResult { return durationMS; } - private static DateFormat buildDateFormat() { - DateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.ENGLISH); - // For dates without a time, for purposes of interacting with Android, the resulting timestamp - // needs to be midnight of that day in GMT. See: - // http://code.google.com/p/android/issues/detail?id=8330 - format.setTimeZone(TimeZone.getTimeZone("GMT")); - return format; - } - - private static DateFormat buildDateTimeFormat() { - return new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.ENGLISH); + private static long parseDateTimeString(String dateTimeString) throws ParseException { + DateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.ENGLISH); + return format.parse(dateTimeString).getTime(); } } diff --git a/core/src/main/java/com/google/zxing/datamatrix/decoder/BitMatrixParser.java b/core/src/main/java/com/google/zxing/datamatrix/decoder/BitMatrixParser.java index b43e890fa..13c37b63c 100644 --- a/core/src/main/java/com/google/zxing/datamatrix/decoder/BitMatrixParser.java +++ b/core/src/main/java/com/google/zxing/datamatrix/decoder/BitMatrixParser.java @@ -404,7 +404,7 @@ final class BitMatrixParser { int symbolSizeColumns = version.getSymbolSizeColumns(); if (bitMatrix.getHeight() != symbolSizeRows) { - throw new IllegalArgumentException("Dimension of bitMarix must match the version size"); + throw new IllegalArgumentException("Dimension of bitMatrix must match the version size"); } int dataRegionSizeRows = version.getDataRegionSizeRows(); diff --git a/core/src/main/java/com/google/zxing/datamatrix/detector/Detector.java b/core/src/main/java/com/google/zxing/datamatrix/detector/Detector.java index dbbda40d3..641c8ac1a 100644 --- a/core/src/main/java/com/google/zxing/datamatrix/detector/Detector.java +++ b/core/src/main/java/com/google/zxing/datamatrix/detector/Detector.java @@ -156,7 +156,7 @@ public final class Detector { BitMatrix bits; ResultPoint correctedTopRight; - // Rectanguar symbols are 6x16, 6x28, 10x24, 10x32, 14x32, or 14x44. If one dimension is more + // Rectangular symbols are 6x16, 6x28, 10x24, 10x32, 14x32, or 14x44. If one dimension is more // 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) { diff --git a/core/src/main/java/com/google/zxing/oned/CodaBarReader.java b/core/src/main/java/com/google/zxing/oned/CodaBarReader.java index 6f13e98be..0ba9f1e00 100644 --- a/core/src/main/java/com/google/zxing/oned/CodaBarReader.java +++ b/core/src/main/java/com/google/zxing/oned/CodaBarReader.java @@ -52,17 +52,17 @@ public final class CodaBarReader extends OneDReader { 0x00c, 0x018, 0x045, 0x051, 0x054, 0x015, 0x01A, 0x029, 0x00B, 0x00E, // -$:/.+ABCD }; - // minimal number of characters that should be present (inclusing start and stop characters) + // minimal number of characters that should be present (including start and stop characters) // under normal circumstances this should be set to 3, but can be set higher // as a last-ditch attempt to reduce false positives. private static final int MIN_CHARACTER_LENGTH = 3; // official start and end patterns private static final char[] STARTEND_ENCODING = {'A', 'B', 'C', 'D'}; - // some codabar generator allow the codabar string to be closed by every + // some Codabar generator allow the Codabar string to be closed by every // character. This will cause lots of false positives! - // some industries use a checksum standard but this is not part of the original codabar standard + // some industries use a checksum standard but this is not part of the original Codabar standard // for more information see : http://www.mecsw.com/specs/codabar.html // Keep some instance variables to avoid reallocations @@ -238,7 +238,7 @@ public final class CodaBarReader extends OneDReader { boolean isWhite = true; int count = 0; while (i < end) { - if (row.get(i) ^ isWhite) { // that is, exactly one is true + if (row.get(i) != isWhite) { count++; } else { counterAppend(count); diff --git a/core/src/main/java/com/google/zxing/oned/Code128Reader.java b/core/src/main/java/com/google/zxing/oned/Code128Reader.java index d835a9ed0..a9d2bc28e 100644 --- a/core/src/main/java/com/google/zxing/oned/Code128Reader.java +++ b/core/src/main/java/com/google/zxing/oned/Code128Reader.java @@ -177,7 +177,7 @@ public final class Code128Reader extends OneDReader { int patternLength = counters.length; for (int i = rowOffset; i < width; i++) { - if (row.get(i) ^ isWhite) { + if (row.get(i) != isWhite) { counters[counterPosition]++; } else { if (counterPosition == patternLength - 1) { @@ -197,9 +197,9 @@ public final class Code128Reader extends OneDReader { return new int[]{patternStart, i, bestMatch}; } patternStart += counters[0] + counters[1]; - System.arraycopy(counters, 2, counters, 0, patternLength - 2); - counters[patternLength - 2] = 0; - counters[patternLength - 1] = 0; + System.arraycopy(counters, 2, counters, 0, counterPosition - 1); + counters[counterPosition - 1] = 0; + counters[counterPosition] = 0; counterPosition--; } else { counterPosition++; diff --git a/core/src/main/java/com/google/zxing/oned/Code39Reader.java b/core/src/main/java/com/google/zxing/oned/Code39Reader.java index 59871242d..0ac7f928c 100644 --- a/core/src/main/java/com/google/zxing/oned/Code39Reader.java +++ b/core/src/main/java/com/google/zxing/oned/Code39Reader.java @@ -187,7 +187,7 @@ public final class Code39Reader extends OneDReader { int patternLength = counters.length; for (int i = rowOffset; i < width; i++) { - if (row.get(i) ^ isWhite) { + if (row.get(i) != isWhite) { counters[counterPosition]++; } else { if (counterPosition == patternLength - 1) { @@ -197,9 +197,9 @@ public final class Code39Reader extends OneDReader { return new int[]{patternStart, i}; } patternStart += counters[0] + counters[1]; - System.arraycopy(counters, 2, counters, 0, patternLength - 2); - counters[patternLength - 2] = 0; - counters[patternLength - 1] = 0; + System.arraycopy(counters, 2, counters, 0, counterPosition - 1); + counters[counterPosition - 1] = 0; + counters[counterPosition] = 0; counterPosition--; } else { counterPosition++; diff --git a/core/src/main/java/com/google/zxing/oned/Code93Reader.java b/core/src/main/java/com/google/zxing/oned/Code93Reader.java index b9425c701..bbbfbcee0 100644 --- a/core/src/main/java/com/google/zxing/oned/Code93Reader.java +++ b/core/src/main/java/com/google/zxing/oned/Code93Reader.java @@ -140,7 +140,7 @@ public final class Code93Reader extends OneDReader { int counterPosition = 0; for (int i = rowOffset; i < width; i++) { - if (row.get(i) ^ isWhite) { + if (row.get(i) != isWhite) { theCounters[counterPosition]++; } else { if (counterPosition == patternLength - 1) { @@ -148,9 +148,9 @@ public final class Code93Reader extends OneDReader { return new int[]{patternStart, i}; } patternStart += theCounters[0] + theCounters[1]; - System.arraycopy(theCounters, 2, theCounters, 0, patternLength - 2); - theCounters[patternLength - 2] = 0; - theCounters[patternLength - 1] = 0; + System.arraycopy(theCounters, 2, theCounters, 0, counterPosition - 1); + theCounters[counterPosition - 1] = 0; + theCounters[counterPosition] = 0; counterPosition--; } else { counterPosition++; diff --git a/core/src/main/java/com/google/zxing/oned/Code93Writer.java b/core/src/main/java/com/google/zxing/oned/Code93Writer.java index 53db6ec2f..a52eabbbc 100644 --- a/core/src/main/java/com/google/zxing/oned/Code93Writer.java +++ b/core/src/main/java/com/google/zxing/oned/Code93Writer.java @@ -48,36 +48,36 @@ public class Code93Writer extends OneDimensionalCodeWriter { //each character is encoded by 9 of 0/1's int[] widths = new int[9]; - //lenght of code + 2 start/stop characters + 2 checksums, each of 9 bits, plus a termination bar + //length of code + 2 start/stop characters + 2 checksums, each of 9 bits, plus a termination bar int codeWidth = (contents.length() + 2 + 2) * 9 + 1; - boolean[] result = new boolean[codeWidth]; - //start character (*) toIntArray(Code93Reader.CHARACTER_ENCODINGS[47], widths); - int pos = appendPattern(result, 0, widths, true); + + boolean[] result = new boolean[codeWidth]; + int pos = appendPattern(result, 0, widths); for (int i = 0; i < length; i++) { int indexInString = Code93Reader.ALPHABET_STRING.indexOf(contents.charAt(i)); toIntArray(Code93Reader.CHARACTER_ENCODINGS[indexInString], widths); - pos += appendPattern(result, pos, widths, true); + pos += appendPattern(result, pos, widths); } //add two checksums int check1 = computeChecksumIndex(contents, 20); toIntArray(Code93Reader.CHARACTER_ENCODINGS[check1], widths); - pos += appendPattern(result, pos, widths, true); + pos += appendPattern(result, pos, widths); //append the contents to reflect the first checksum added contents += Code93Reader.ALPHABET_STRING.charAt(check1); int check2 = computeChecksumIndex(contents, 15); toIntArray(Code93Reader.CHARACTER_ENCODINGS[check2], widths); - pos += appendPattern(result, pos, widths, true); + pos += appendPattern(result, pos, widths); //end character (*) toIntArray(Code93Reader.CHARACTER_ENCODINGS[47], widths); - pos += appendPattern(result, pos, widths, true); + pos += appendPattern(result, pos, widths); //termination bar (single black bar) result[pos] = true; @@ -92,7 +92,20 @@ public class Code93Writer extends OneDimensionalCodeWriter { } } + /** + * @param target output to append to + * @param pos start position + * @param pattern pattern to append + * @param startColor unused + * @return 9 + * @deprecated without replacement; intended as an internal-only method + */ + @Deprecated protected static int appendPattern(boolean[] target, int pos, int[] pattern, boolean startColor) { + return appendPattern(target, pos, pattern); + } + + private static int appendPattern(boolean[] target, int pos, int[] pattern) { for (int bit : pattern) { target[pos++] = bit != 0; } diff --git a/core/src/main/java/com/google/zxing/oned/ITFReader.java b/core/src/main/java/com/google/zxing/oned/ITFReader.java index aac0f10ad..ab763cf50 100644 --- a/core/src/main/java/com/google/zxing/oned/ITFReader.java +++ b/core/src/main/java/com/google/zxing/oned/ITFReader.java @@ -300,7 +300,7 @@ public final class ITFReader extends OneDReader { int counterPosition = 0; int patternStart = rowOffset; for (int x = rowOffset; x < width; x++) { - if (row.get(x) ^ isWhite) { + if (row.get(x) != isWhite) { counters[counterPosition]++; } else { if (counterPosition == patternLength - 1) { @@ -308,9 +308,9 @@ public final class ITFReader extends OneDReader { return new int[]{patternStart, x}; } patternStart += counters[0] + counters[1]; - System.arraycopy(counters, 2, counters, 0, patternLength - 2); - counters[patternLength - 2] = 0; - counters[patternLength - 1] = 0; + System.arraycopy(counters, 2, counters, 0, counterPosition - 1); + counters[counterPosition - 1] = 0; + counters[counterPosition] = 0; counterPosition--; } else { counterPosition++; diff --git a/core/src/main/java/com/google/zxing/oned/OneDReader.java b/core/src/main/java/com/google/zxing/oned/OneDReader.java index 1c7a95fd1..7941e6f13 100644 --- a/core/src/main/java/com/google/zxing/oned/OneDReader.java +++ b/core/src/main/java/com/google/zxing/oned/OneDReader.java @@ -106,7 +106,6 @@ public abstract class OneDReader implements Reader { int height = image.getHeight(); BitArray row = new BitArray(width); - int middle = height >> 1; boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER); int rowStep = Math.max(1, height >> (tryHarder ? 8 : 5)); int maxLines; @@ -116,6 +115,7 @@ public abstract class OneDReader implements Reader { maxLines = 15; // 15 rows spaced 1/32 apart is roughly the middle half of the image } + int middle = height / 2; for (int x = 0; x < maxLines; x++) { // Scanning from the middle out. Determine which row we're looking at next: @@ -200,11 +200,10 @@ public abstract class OneDReader implements Reader { int counterPosition = 0; int i = start; while (i < end) { - if (row.get(i) ^ isWhite) { // that is, exactly one is true + if (row.get(i) != isWhite) { counters[counterPosition]++; } else { - counterPosition++; - if (counterPosition == numCounters) { + if (++counterPosition == numCounters) { break; } else { counters[counterPosition] = 1; diff --git a/core/src/main/java/com/google/zxing/oned/UPCEANReader.java b/core/src/main/java/com/google/zxing/oned/UPCEANReader.java index 7a754838d..8e271ee2d 100644 --- a/core/src/main/java/com/google/zxing/oned/UPCEANReader.java +++ b/core/src/main/java/com/google/zxing/oned/UPCEANReader.java @@ -324,7 +324,7 @@ public abstract class UPCEANReader extends OneDReader { int patternLength = pattern.length; boolean isWhite = whiteFirst; for (int x = rowOffset; x < width; x++) { - if (row.get(x) ^ isWhite) { + if (row.get(x) != isWhite) { counters[counterPosition]++; } else { if (counterPosition == patternLength - 1) { @@ -332,9 +332,9 @@ public abstract class UPCEANReader extends OneDReader { return new int[]{patternStart, x}; } patternStart += counters[0] + counters[1]; - System.arraycopy(counters, 2, counters, 0, patternLength - 2); - counters[patternLength - 2] = 0; - counters[patternLength - 1] = 0; + System.arraycopy(counters, 2, counters, 0, counterPosition - 1); + counters[counterPosition - 1] = 0; + counters[counterPosition] = 0; counterPosition--; } else { counterPosition++; 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 7bded7301..4ec705351 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 @@ -133,7 +133,7 @@ public final class RSS14Reader extends AbstractRSSReader { ResultPoint[] leftPoints = leftPair.getFinderPattern().getResultPoints(); ResultPoint[] rightPoints = rightPair.getFinderPattern().getResultPoints(); return new Result( - String.valueOf(buffer.toString()), + buffer.toString(), null, new ResultPoint[] { leftPoints[0], leftPoints[1], rightPoints[0], rightPoints[1], }, BarcodeFormat.RSS_14); @@ -159,7 +159,7 @@ public final class RSS14Reader extends AbstractRSSReader { private Pair decodePair(BitArray row, boolean right, int rowNumber, Map<DecodeHintType,?> hints) { try { - int[] startEnd = findFinderPattern(row, 0, right); + int[] startEnd = findFinderPattern(row, right); FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd); ResultPointCallback resultPointCallback = hints == null ? null : @@ -281,7 +281,7 @@ public final class RSS14Reader extends AbstractRSSReader { } - private int[] findFinderPattern(BitArray row, int rowOffset, boolean rightFinderPattern) + private int[] findFinderPattern(BitArray row, boolean rightFinderPattern) throws NotFoundException { int[] counters = getDecodeFinderCounters(); @@ -292,6 +292,7 @@ public final class RSS14Reader extends AbstractRSSReader { int width = row.getSize(); boolean isWhite = false; + int rowOffset = 0; while (rowOffset < width) { isWhite = !row.get(rowOffset); if (rightFinderPattern == isWhite) { @@ -304,7 +305,7 @@ public final class RSS14Reader extends AbstractRSSReader { int counterPosition = 0; int patternStart = rowOffset; for (int x = rowOffset; x < width; x++) { - if (row.get(x) ^ isWhite) { + if (row.get(x) != isWhite) { counters[counterPosition]++; } else { if (counterPosition == 3) { @@ -334,7 +335,7 @@ public final class RSS14Reader extends AbstractRSSReader { boolean firstIsBlack = row.get(startEnd[0]); int firstElementStart = startEnd[0] - 1; // Locate element 1 - while (firstElementStart >= 0 && firstIsBlack ^ row.get(firstElementStart)) { + while (firstElementStart >= 0 && firstIsBlack != row.get(firstElementStart)) { firstElementStart--; } firstElementStart++; 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 b4ef45074..fb2e237ad 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 @@ -491,7 +491,7 @@ public final class RSSExpandedReader extends AbstractRSSReader { int counterPosition = 0; int patternStart = rowOffset; for (int x = rowOffset; x < width; x++) { - if (row.get(x) ^ isWhite) { + if (row.get(x) != isWhite) { counters[counterPosition]++; } else { if (counterPosition == 3) { diff --git a/core/src/main/java/com/google/zxing/pdf417/PDF417Writer.java b/core/src/main/java/com/google/zxing/pdf417/PDF417Writer.java index 000225063..85c47898b 100644 --- a/core/src/main/java/com/google/zxing/pdf417/PDF417Writer.java +++ b/core/src/main/java/com/google/zxing/pdf417/PDF417Writer.java @@ -109,7 +109,7 @@ public final class PDF417Writer implements Writer { int aspectRatio = 4; byte[][] originalScale = encoder.getBarcodeMatrix().getScaledMatrix(1, aspectRatio); boolean rotated = false; - if ((height > width) ^ (originalScale[0].length < originalScale.length)) { + if ((height > width) != (originalScale[0].length < originalScale.length)) { originalScale = rotateArray(originalScale); rotated = true; } diff --git a/core/src/main/java/com/google/zxing/pdf417/decoder/BarcodeValue.java b/core/src/main/java/com/google/zxing/pdf417/decoder/BarcodeValue.java index 79a8d23af..ea9bca910 100644 --- a/core/src/main/java/com/google/zxing/pdf417/decoder/BarcodeValue.java +++ b/core/src/main/java/com/google/zxing/pdf417/decoder/BarcodeValue.java @@ -61,7 +61,7 @@ final class BarcodeValue { return PDF417Common.toIntArray(result); } - public Integer getConfidence(int value) { + Integer getConfidence(int value) { return values.get(value); } diff --git a/core/src/main/java/com/google/zxing/pdf417/decoder/DetectionResult.java b/core/src/main/java/com/google/zxing/pdf417/decoder/DetectionResult.java index 74892ee54..0e28ff5fe 100644 --- a/core/src/main/java/com/google/zxing/pdf417/decoder/DetectionResult.java +++ b/core/src/main/java/com/google/zxing/pdf417/decoder/DetectionResult.java @@ -249,7 +249,7 @@ final class DetectionResult { return barcodeMetadata.getErrorCorrectionLevel(); } - public void setBoundingBox(BoundingBox boundingBox) { + void setBoundingBox(BoundingBox boundingBox) { this.boundingBox = boundingBox; } diff --git a/core/src/main/java/com/google/zxing/pdf417/detector/Detector.java b/core/src/main/java/com/google/zxing/pdf417/detector/Detector.java index 080123511..5203cc739 100644 --- a/core/src/main/java/com/google/zxing/pdf417/detector/Detector.java +++ b/core/src/main/java/com/google/zxing/pdf417/detector/Detector.java @@ -234,9 +234,7 @@ public final class Detector { result[3] = new ResultPoint(previousRowLoc[1], stopRow); } if (stopRow - startRow < BARCODE_MIN_HEIGHT) { - for (int i = 0; i < result.length; i++) { - result[i] = null; - } + Arrays.fill(result, null); } return result; } @@ -271,7 +269,7 @@ public final class Detector { int patternLength = pattern.length; for (boolean isWhite = whiteFirst; x < width; x++) { boolean pixel = matrix.get(x, row); - if (pixel ^ isWhite) { + if (pixel != isWhite) { counters[counterPosition]++; } else { if (counterPosition == patternLength - 1) { @@ -279,9 +277,9 @@ public final class Detector { return new int[] {patternStart, x}; } patternStart += counters[0] + counters[1]; - System.arraycopy(counters, 2, counters, 0, patternLength - 2); - counters[patternLength - 2] = 0; - counters[patternLength - 1] = 0; + System.arraycopy(counters, 2, counters, 0, counterPosition - 1); + counters[counterPosition - 1] = 0; + counters[counterPosition] = 0; counterPosition--; } else { counterPosition++; @@ -290,10 +288,9 @@ public final class Detector { isWhite = !isWhite; } } - if (counterPosition == patternLength - 1) { - if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) { - return new int[] {patternStart, x - 1}; - } + if (counterPosition == patternLength - 1 && + patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) { + return new int[] {patternStart, x - 1}; } return null; } diff --git a/core/src/main/java/com/google/zxing/pdf417/encoder/BarcodeMatrix.java b/core/src/main/java/com/google/zxing/pdf417/encoder/BarcodeMatrix.java index 1cff11359..cf1c11b0f 100644 --- a/core/src/main/java/com/google/zxing/pdf417/encoder/BarcodeMatrix.java +++ b/core/src/main/java/com/google/zxing/pdf417/encoder/BarcodeMatrix.java @@ -17,7 +17,7 @@ package com.google.zxing.pdf417.encoder; /** - * Holds all of the information for a barcode in a format where it can be easily accessable + * Holds all of the information for a barcode in a format where it can be easily accessible * * @author Jacob Haynes */ diff --git a/core/src/main/java/com/google/zxing/qrcode/detector/FinderPatternFinder.java b/core/src/main/java/com/google/zxing/qrcode/detector/FinderPatternFinder.java index 7fdffd60e..61fe3c146 100755 --- a/core/src/main/java/com/google/zxing/qrcode/detector/FinderPatternFinder.java +++ b/core/src/main/java/com/google/zxing/qrcode/detector/FinderPatternFinder.java @@ -653,7 +653,7 @@ public class FinderPatternFinder { public int compare(FinderPattern center1, FinderPattern center2) { float dA = Math.abs(center2.getEstimatedModuleSize() - average); float dB = Math.abs(center1.getEstimatedModuleSize() - average); - return dA < dB ? -1 : dA == dB ? 0 : 1; + return dA < dB ? -1 : dA > dB ? 1 : 0; } } @@ -670,7 +670,7 @@ public class FinderPatternFinder { if (center2.getCount() == center1.getCount()) { float dA = Math.abs(center2.getEstimatedModuleSize() - average); float dB = Math.abs(center1.getEstimatedModuleSize() - average); - return dA < dB ? 1 : dA == dB ? 0 : -1; + return dA < dB ? 1 : dA > dB ? -1 : 0; } else { return center2.getCount() - center1.getCount(); } diff --git a/core/src/main/java/com/google/zxing/qrcode/encoder/MatrixUtil.java b/core/src/main/java/com/google/zxing/qrcode/encoder/MatrixUtil.java index 9e2345e61..18d2070f9 100644 --- a/core/src/main/java/com/google/zxing/qrcode/encoder/MatrixUtil.java +++ b/core/src/main/java/com/google/zxing/qrcode/encoder/MatrixUtil.java @@ -298,7 +298,7 @@ final class MatrixUtil { // The return value is 0xc94 (1100 1001 0100) // // Since all coefficients in the polynomials are 1 or 0, we can do the calculation by bit - // operations. We don't care if cofficients are positive or negative. + // operations. We don't care if coefficients are positive or negative. static int calculateBCHCode(int value, int poly) { if (poly == 0) { throw new IllegalArgumentException("0 polynomial"); @@ -459,19 +459,15 @@ final class MatrixUtil { } int index = version.getVersionNumber() - 1; int[] coordinates = POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index]; - int numCoordinates = POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index].length; - for (int i = 0; i < numCoordinates; ++i) { - for (int j = 0; j < numCoordinates; ++j) { - int y = coordinates[i]; - int x = coordinates[j]; - if (x == -1 || y == -1) { - continue; - } - // If the cell is unset, we embed the position adjustment pattern here. - if (isEmpty(matrix.get(x, y))) { - // -2 is necessary since the x/y coordinates point to the center of the pattern, not the - // left top corner. - embedPositionAdjustmentPattern(x - 2, y - 2, matrix); + for (int y : coordinates) { + if (y >= 0) { + for (int x : coordinates) { + if (x >= 0 && isEmpty(matrix.get(x, y))) { + // If the cell is unset, we embed the position adjustment pattern here. + // -2 is necessary since the x/y coordinates point to the center of the pattern, not the + // left top corner. + embedPositionAdjustmentPattern(x - 2, y - 2, matrix); + } } } } diff --git a/core/src/test/java/com/google/zxing/client/result/CalendarParsedResultTestCase.java b/core/src/test/java/com/google/zxing/client/result/CalendarParsedResultTestCase.java index 4e53bbafe..e81f10979 100644 --- a/core/src/test/java/com/google/zxing/client/result/CalendarParsedResultTestCase.java +++ b/core/src/test/java/com/google/zxing/client/result/CalendarParsedResultTestCase.java @@ -231,8 +231,8 @@ public final class CalendarParsedResultTestCase extends Assert { assertEquals(summary, calResult.getSummary()); assertEquals(location, calResult.getLocation()); DateFormat dateFormat = makeGMTFormat(); - assertEquals(startString, dateFormat.format(calResult.getStart())); - assertEquals(endString, calResult.getEnd() == null ? null : dateFormat.format(calResult.getEnd())); + assertEquals(startString, dateFormat.format(calResult.getStartTimestamp())); + assertEquals(endString, calResult.getEndTimestamp() < 0L ? null : dateFormat.format(calResult.getEndTimestamp())); assertEquals(organizer, calResult.getOrganizer()); assertArrayEquals(attendees, calResult.getAttendees()); assertEqualOrNaN(latitude, calResult.getLatitude()); diff --git a/core/src/test/java/com/google/zxing/common/AbstractBlackBoxTestCase.java b/core/src/test/java/com/google/zxing/common/AbstractBlackBoxTestCase.java index d1a0eb5d4..c5129ee9c 100644 --- a/core/src/test/java/com/google/zxing/common/AbstractBlackBoxTestCase.java +++ b/core/src/test/java/com/google/zxing/common/AbstractBlackBoxTestCase.java @@ -141,7 +141,7 @@ public abstract class AbstractBlackBoxTestCase extends Assert { int[] passedCounts = new int[testCount]; int[] misreadCounts = new int[testCount]; int[] tryHarderCounts = new int[testCount]; - int[] tryHaderMisreadCounts = new int[testCount]; + int[] tryHarderMisreadCounts = new int[testCount]; for (Path testImage : imageFiles) { log.info(String.format("Starting %s", testImage)); @@ -186,7 +186,7 @@ public abstract class AbstractBlackBoxTestCase extends Assert { if (decode(bitmap, rotation, expectedText, expectedMetadata, true)) { tryHarderCounts[x]++; } else { - tryHaderMisreadCounts[x]++; + tryHarderMisreadCounts[x]++; } } catch (ReaderException ignored) { log.fine(String.format("could not read at rotation %f w/TH", rotation)); @@ -212,10 +212,10 @@ public abstract class AbstractBlackBoxTestCase extends Assert { tryHarderCounts[x], imageFiles.size(), testResult.getTryHarderCount())); failed = imageFiles.size() - tryHarderCounts[x]; log.info(String.format(" %d failed due to misreads, %d not detected", - tryHaderMisreadCounts[x], failed - tryHaderMisreadCounts[x])); + tryHarderMisreadCounts[x], failed - tryHarderMisreadCounts[x])); totalFound += passedCounts[x] + tryHarderCounts[x]; totalMustPass += testResult.getMustPassCount() + testResult.getTryHarderCount(); - totalMisread += misreadCounts[x] + tryHaderMisreadCounts[x]; + totalMisread += misreadCounts[x] + tryHarderMisreadCounts[x]; totalMaxMisread += testResult.getMaxMisreads() + testResult.getMaxTryHarderMisreads(); } @@ -247,7 +247,7 @@ public abstract class AbstractBlackBoxTestCase extends Assert { assertTrue(label, misreadCounts[x] <= testResult.getMaxMisreads()); assertTrue("Try harder, " + label, - tryHaderMisreadCounts[x] <= testResult.getMaxTryHarderMisreads()); + tryHarderMisreadCounts[x] <= testResult.getMaxTryHarderMisreads()); } } } diff --git a/core/src/test/java/com/google/zxing/common/AbstractNegativeBlackBoxTestCase.java b/core/src/test/java/com/google/zxing/common/AbstractNegativeBlackBoxTestCase.java index 3ce4e7c19..0f258519a 100644 --- a/core/src/test/java/com/google/zxing/common/AbstractNegativeBlackBoxTestCase.java +++ b/core/src/test/java/com/google/zxing/common/AbstractNegativeBlackBoxTestCase.java @@ -126,7 +126,7 @@ public abstract class AbstractNegativeBlackBoxTestCase extends AbstractBlackBoxT * * @param image The image to test * @param rotationInDegrees The amount of rotation to apply - * @return true if nothing found, false if a non-existant barcode was detected + * @return true if nothing found, false if a non-existent barcode was detected */ private boolean checkForFalsePositives(BufferedImage image, float rotationInDegrees) { BufferedImage rotatedImage = rotateImage(image, rotationInDegrees); |
