Fix typos; avoid use of java.util.Date; other small improvements from inspection; deprecate some accidentally-public methods

This commit is contained in:
Sean Owen 2016-11-29 12:16:07 +00:00
parent 64eb07747e
commit 0dfda08078
No known key found for this signature in database
GPG key ID: F6CE9695C9318406
30 changed files with 165 additions and 158 deletions

View file

@ -67,7 +67,6 @@ import android.widget.Toast;
import java.io.IOException;
import java.text.DateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.EnumSet;
import java.util.Map;
@ -557,7 +556,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
TextView timeTextView = (TextView) findViewById(R.id.time_text_view);
timeTextView.setText(formatter.format(new Date(rawResult.getTimestamp())));
timeTextView.setText(formatter.format(rawResult.getTimestamp()));
TextView metaTextView = (TextView) findViewById(R.id.meta_text_view);

View file

@ -41,7 +41,6 @@ import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@ -299,8 +298,7 @@ public final class HistoryManager {
// Add timestamp again, formatted
long timestamp = cursor.getLong(3);
historyText.append('"').append(massageHistoryField(
format.format(new Date(timestamp)))).append("\",");
historyText.append('"').append(massageHistoryField(format.format(timestamp))).append("\",");
// Above we're preserving the old ordering of columns which had formatted data in position 5

View file

@ -30,7 +30,6 @@ import android.text.style.StyleSpan;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
/**
@ -151,15 +150,15 @@ public final class AddressBookResultHandler extends ResultHandler {
}
}
private static Date parseDate(String s) {
private static long parseDate(String s) {
for (DateFormat currentFormat : DATE_FORMATS) {
try {
return currentFormat.parse(s);
return currentFormat.parse(s).getTime();
} catch (ParseException e) {
// continue
}
}
return null;
return -1L;
}
// Overriden so we can hyphenate phone numbers, format birthdays, and bold the name.
@ -193,9 +192,9 @@ public final class AddressBookResultHandler extends ResultHandler {
String birthday = result.getBirthday();
if (birthday != null && !birthday.isEmpty()) {
Date date = parseDate(birthday);
if (date != null) {
ParsedResult.maybeAppend(DateFormat.getDateInstance(DateFormat.MEDIUM).format(date.getTime()), contents);
long date = parseDate(birthday);
if (date >= 0L) {
ParsedResult.maybeAppend(DateFormat.getDateInstance(DateFormat.MEDIUM).format(date), contents);
}
}
ParsedResult.maybeAppend(result.getNote(), contents);

View file

@ -26,7 +26,6 @@ import android.app.Activity;
import android.content.Intent;
import java.text.DateFormat;
import java.util.Date;
/**
* Handles calendar entries encoded in QR Codes.
@ -72,9 +71,9 @@ public final class CalendarResultHandler extends ResultHandler {
}
addCalendarEvent(calendarResult.getSummary(),
calendarResult.getStart(),
calendarResult.getStartTimestamp(),
calendarResult.isStartAllDay(),
calendarResult.getEnd(),
calendarResult.getEndTimestamp(),
calendarResult.getLocation(),
description,
calendarResult.getAttendees());
@ -88,37 +87,33 @@ public final class CalendarResultHandler extends ResultHandler {
* @param summary A description of the event
* @param start The start time
* @param allDay if true, event is considered to be all day starting from start time
* @param end The end time (optional)
* @param end The end time (optional; can be < 0 if not specified)
* @param location a text description of the event location
* @param description a text description of the event itself
* @param attendees attendees to invite
*/
private void addCalendarEvent(String summary,
Date start,
long start,
boolean allDay,
Date end,
long end,
String location,
String description,
String[] attendees) {
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType("vnd.android.cursor.item/event");
long startMilliseconds = start.getTime();
intent.putExtra("beginTime", startMilliseconds);
intent.putExtra("beginTime", start);
if (allDay) {
intent.putExtra("allDay", true);
}
long endMilliseconds;
if (end == null) {
if (end < 0L) {
if (allDay) {
// + 1 day
endMilliseconds = startMilliseconds + 24 * 60 * 60 * 1000;
end = start + 24 * 60 * 60 * 1000;
} else {
endMilliseconds = startMilliseconds;
end = start;
}
} else {
endMilliseconds = end.getTime();
}
intent.putExtra("endTime", endMilliseconds);
intent.putExtra("endTime", end);
intent.putExtra("title", summary);
intent.putExtra("eventLocation", location);
intent.putExtra("description", description);
@ -147,17 +142,17 @@ public final class CalendarResultHandler extends ResultHandler {
ParsedResult.maybeAppend(calResult.getSummary(), result);
Date start = calResult.getStart();
long start = calResult.getStartTimestamp();
ParsedResult.maybeAppend(format(calResult.isStartAllDay(), start), result);
Date end = calResult.getEnd();
if (end != null) {
if (calResult.isEndAllDay() && !start.equals(end)) {
long end = calResult.getEndTimestamp();
if (end >= 0L) {
if (calResult.isEndAllDay() && start != end) {
// Show only year/month/day
// if it's all-day and this is the end date, it's exclusive, so show the user
// that it ends on the day before to make more intuitive sense.
// But don't do it if the event already (incorrectly?) specifies the same start/end
end = new Date(end.getTime() - 24 * 60 * 60 * 1000);
end -= 24 * 60 * 60 * 1000;
}
ParsedResult.maybeAppend(format(calResult.isEndAllDay(), end), result);
}
@ -169,8 +164,8 @@ public final class CalendarResultHandler extends ResultHandler {
return result.toString();
}
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

View file

@ -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

View file

@ -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 {
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
Date date;
if (when.length() == 16 && when.charAt(15) == 'Z') {
date = buildDateTimeFormat().parse(when.substring(0, 15));
long milliseconds = parseDateTimeString(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;
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();
}
}

View file

@ -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();

View file

@ -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) {

View file

@ -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);

View file

@ -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++;

View file

@ -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++;

View file

@ -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++;

View file

@ -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;
}

View file

@ -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++;

View file

@ -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;

View file

@ -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++;

View file

@ -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++;

View file

@ -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) {

View file

@ -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;
}

View file

@ -61,7 +61,7 @@ final class BarcodeValue {
return PDF417Common.toIntArray(result);
}
public Integer getConfidence(int value) {
Integer getConfidence(int value) {
return values.get(value);
}

View file

@ -249,7 +249,7 @@ final class DetectionResult {
return barcodeMetadata.getErrorCorrectionLevel();
}
public void setBoundingBox(BoundingBox boundingBox) {
void setBoundingBox(BoundingBox boundingBox) {
this.boundingBox = boundingBox;
}

View file

@ -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,11 +288,10 @@ public final class Detector {
isWhite = !isWhite;
}
}
if (counterPosition == patternLength - 1) {
if (patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) {
if (counterPosition == patternLength - 1 &&
patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) {
return new int[] {patternStart, x - 1};
}
}
return null;
}

View file

@ -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
*/

View file

@ -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();
}

View file

@ -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,16 +459,11 @@ 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;
}
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.
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);
@ -476,5 +471,6 @@ final class MatrixUtil {
}
}
}
}
}

View file

@ -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());

View file

@ -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());
}
}
}

View file

@ -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);

View file

@ -250,7 +250,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -428,7 +428,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.5.1</version>
<version>3.6</version>
<inherited>false</inherited>
</plugin>
<plugin>

View file

@ -57,7 +57,7 @@
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.0.RC1</version>
<version>9.4.0.RC2</version>
</plugin>
</plugins>
</build>