mirror of
https://github.com/zxing/zxing.git
synced 2024-11-09 20:44:03 -08:00
A bunch of inspection changes, including some dead code removal and tightening visibility, removing unnecessary casts
This commit is contained in:
parent
78fbdc58fc
commit
2f11529aa3
|
@ -311,7 +311,7 @@ public final class CameraConfigurationUtils {
|
|||
Log.i(TAG, "Supported preview sizes: " + previewSizesString);
|
||||
}
|
||||
|
||||
double screenAspectRatio = (double) screenResolution.x / (double) screenResolution.y;
|
||||
double screenAspectRatio = screenResolution.x / (double) screenResolution.y;
|
||||
|
||||
// Remove sizes that are unsuitable
|
||||
Iterator<Camera.Size> it = supportedPreviewSizes.iterator();
|
||||
|
@ -327,7 +327,7 @@ public final class CameraConfigurationUtils {
|
|||
boolean isCandidatePortrait = realWidth < realHeight;
|
||||
int maybeFlippedWidth = isCandidatePortrait ? realHeight : realWidth;
|
||||
int maybeFlippedHeight = isCandidatePortrait ? realWidth : realHeight;
|
||||
double aspectRatio = (double) maybeFlippedWidth / (double) maybeFlippedHeight;
|
||||
double aspectRatio = maybeFlippedWidth / (double) maybeFlippedHeight;
|
||||
double distortion = Math.abs(aspectRatio - screenAspectRatio);
|
||||
if (distortion > MAX_ASPECT_DISTORTION) {
|
||||
it.remove();
|
||||
|
|
|
@ -82,14 +82,12 @@ public final class IntentResult {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder dialogText = new StringBuilder(100);
|
||||
dialogText.append("Format: ").append(formatName).append('\n');
|
||||
dialogText.append("Contents: ").append(contents).append('\n');
|
||||
int rawBytesLength = rawBytes == null ? 0 : rawBytes.length;
|
||||
dialogText.append("Raw bytes: (").append(rawBytesLength).append(" bytes)\n");
|
||||
dialogText.append("Orientation: ").append(orientation).append('\n');
|
||||
dialogText.append("EC level: ").append(errorCorrectionLevel).append('\n');
|
||||
return dialogText.toString();
|
||||
return "Format: " + formatName + '\n' +
|
||||
"Contents: " + contents + '\n' +
|
||||
"Raw bytes: (" + rawBytesLength + " bytes)\n" +
|
||||
"Orientation: " + orientation + '\n' +
|
||||
"EC level: " + errorCorrectionLevel + '\n';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ final class InactivityTimer {
|
|||
inactivityTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
public synchronized void onPause() {
|
||||
synchronized void onPause() {
|
||||
cancel();
|
||||
if (registered) {
|
||||
activity.unregisterReceiver(powerStatusReceiver);
|
||||
|
@ -62,7 +62,7 @@ final class InactivityTimer {
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized void onResume() {
|
||||
synchronized void onResume() {
|
||||
if (registered) {
|
||||
Log.w(TAG, "PowerStatusReceiver was already registered?");
|
||||
} else {
|
||||
|
|
|
@ -99,7 +99,7 @@ final class QRCodeEncoder {
|
|||
|
||||
// It would be nice if the string encoding lived in the core ZXing library,
|
||||
// but we use platform specific code like PhoneNumberUtils, so it can't.
|
||||
private boolean encodeContentsFromZXingIntent(Intent intent) {
|
||||
private void encodeContentsFromZXingIntent(Intent intent) {
|
||||
// Default to QR_CODE if no format given.
|
||||
String formatString = intent.getStringExtra(Intents.Encode.FORMAT);
|
||||
format = null;
|
||||
|
@ -112,11 +112,10 @@ final class QRCodeEncoder {
|
|||
}
|
||||
if (format == null || format == BarcodeFormat.QR_CODE) {
|
||||
String type = intent.getStringExtra(Intents.Encode.TYPE);
|
||||
if (type == null || type.isEmpty()) {
|
||||
return false;
|
||||
if (type != null && !type.isEmpty()) {
|
||||
this.format = BarcodeFormat.QR_CODE;
|
||||
encodeQRCodeContents(intent, type);
|
||||
}
|
||||
this.format = BarcodeFormat.QR_CODE;
|
||||
encodeQRCodeContents(intent, type);
|
||||
} else {
|
||||
String data = intent.getStringExtra(Intents.Encode.DATA);
|
||||
if (data != null && !data.isEmpty()) {
|
||||
|
@ -125,7 +124,6 @@ final class QRCodeEncoder {
|
|||
title = activity.getString(R.string.contents_text);
|
||||
}
|
||||
}
|
||||
return contents != null && !contents.isEmpty();
|
||||
}
|
||||
|
||||
// Handles send intents from multitude of Android applications
|
||||
|
|
|
@ -76,7 +76,7 @@ final class VCardContactEncoder extends ContactEncoder {
|
|||
return new String[] { newContents.toString(), newDisplayContents.toString() };
|
||||
}
|
||||
|
||||
static List<Map<String,Set<String>>> buildPhoneMetadata(Collection<String> phones, List<String> phoneTypes) {
|
||||
private static List<Map<String,Set<String>>> buildPhoneMetadata(Collection<String> phones, List<String> phoneTypes) {
|
||||
if (phoneTypes == null || phoneTypes.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -83,17 +83,14 @@ public final class AddressBookResultHandler extends ResultHandler {
|
|||
super(activity, result);
|
||||
AddressBookParsedResult addressResult = (AddressBookParsedResult) result;
|
||||
String[] addresses = addressResult.getAddresses();
|
||||
boolean hasAddress = addresses != null && addresses.length > 0 && addresses[0] != null && !addresses[0].isEmpty();
|
||||
String[] phoneNumbers = addressResult.getPhoneNumbers();
|
||||
boolean hasPhoneNumber = phoneNumbers != null && phoneNumbers.length > 0;
|
||||
String[] emails = addressResult.getEmails();
|
||||
boolean hasEmailAddress = emails != null && emails.length > 0;
|
||||
|
||||
fields = new boolean[MAX_BUTTON_COUNT];
|
||||
fields[0] = true; // Add contact is always available
|
||||
fields[1] = hasAddress;
|
||||
fields[2] = hasPhoneNumber;
|
||||
fields[3] = hasEmailAddress;
|
||||
fields[1] = addresses != null && addresses.length > 0 && addresses[0] != null && !addresses[0].isEmpty();
|
||||
fields[2] = phoneNumbers != null && phoneNumbers.length > 0;
|
||||
fields[3] = emails != null && emails.length > 0;
|
||||
|
||||
buttonCount = 0;
|
||||
for (int x = 0; x < MAX_BUTTON_COUNT; x++) {
|
||||
|
|
|
@ -349,7 +349,7 @@ public abstract class ResultHandler {
|
|||
sendSMSFromUri("smsto:" + phoneNumber, body);
|
||||
}
|
||||
|
||||
final void sendSMSFromUri(String uri, String body) {
|
||||
private void sendSMSFromUri(String uri, String body) {
|
||||
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
|
||||
putExtra(intent, "sms_body", body);
|
||||
// Exit the app once the SMS is sent
|
||||
|
@ -361,7 +361,7 @@ public abstract class ResultHandler {
|
|||
sendMMSFromUri("mmsto:" + phoneNumber, subject, body);
|
||||
}
|
||||
|
||||
final void sendMMSFromUri(String uri, String subject, String body) {
|
||||
private void sendMMSFromUri(String uri, String subject, String body) {
|
||||
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
|
||||
// The Messaging app needs to see a valid subject or else it will treat this an an SMS.
|
||||
if (subject == null || subject.isEmpty()) {
|
||||
|
|
|
@ -52,13 +52,8 @@ final class BenchmarkItem {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder(30);
|
||||
result.append(decoded ? "DECODED " + format + ": " : "FAILED: ");
|
||||
result.append(path);
|
||||
result.append(" (");
|
||||
result.append(getAverageTime());
|
||||
result.append(" us average)");
|
||||
return result.toString();
|
||||
return (decoded ? "DECODED " + format + ": " : "FAILED: ") + path +
|
||||
" (" + getAverageTime() + " us average)";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -96,10 +96,9 @@ public final class PlanarYUVLuminanceSource extends LuminanceSource {
|
|||
}
|
||||
|
||||
// Otherwise copy one cropped row at a time.
|
||||
byte[] yuv = yuvData;
|
||||
for (int y = 0; y < height; y++) {
|
||||
int outputOffset = y * width;
|
||||
System.arraycopy(yuv, inputOffset, matrix, outputOffset, width);
|
||||
System.arraycopy(yuvData, inputOffset, matrix, outputOffset, width);
|
||||
inputOffset += dataWidth;
|
||||
}
|
||||
return matrix;
|
||||
|
|
|
@ -109,10 +109,9 @@ public final class RGBLuminanceSource extends LuminanceSource {
|
|||
}
|
||||
|
||||
// Otherwise copy one cropped row at a time.
|
||||
byte[] rgb = luminances;
|
||||
for (int y = 0; y < height; y++) {
|
||||
int outputOffset = y * width;
|
||||
System.arraycopy(rgb, inputOffset, matrix, outputOffset, width);
|
||||
System.arraycopy(luminances, inputOffset, matrix, outputOffset, width);
|
||||
inputOffset += dataWidth;
|
||||
}
|
||||
return matrix;
|
||||
|
|
|
@ -58,13 +58,7 @@ public class ResultPoint {
|
|||
|
||||
@Override
|
||||
public final String toString() {
|
||||
StringBuilder result = new StringBuilder(25);
|
||||
result.append('(');
|
||||
result.append(x);
|
||||
result.append(',');
|
||||
result.append(y);
|
||||
result.append(')');
|
||||
return result.toString();
|
||||
return "(" + x + ',' + y + ')';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -220,7 +220,6 @@ public final class Decoder {
|
|||
throw FormatException.getFormatInstance();
|
||||
}
|
||||
int offset = rawbits.length % codewordSize;
|
||||
int numECCodewords = numCodewords - numDataCodewords;
|
||||
|
||||
int[] dataWords = new int[numCodewords];
|
||||
for (int i = 0; i < numCodewords; i++, offset += codewordSize) {
|
||||
|
@ -229,7 +228,7 @@ public final class Decoder {
|
|||
|
||||
try {
|
||||
ReedSolomonDecoder rsDecoder = new ReedSolomonDecoder(gf);
|
||||
rsDecoder.decode(dataWords, numECCodewords);
|
||||
rsDecoder.decode(dataWords, numCodewords - numDataCodewords);
|
||||
} catch (ReedSolomonException ex) {
|
||||
throw FormatException.getFormatInstance(ex);
|
||||
}
|
||||
|
@ -269,7 +268,7 @@ public final class Decoder {
|
|||
*
|
||||
* @return the array of bits
|
||||
*/
|
||||
boolean[] extractBits(BitMatrix matrix) {
|
||||
private boolean[] extractBits(BitMatrix matrix) {
|
||||
boolean compact = ddata.isCompact();
|
||||
int layers = ddata.getNbLayers();
|
||||
int baseMatrixSize = (compact ? 11 : 14) + layers * 4; // not including alignment lines
|
||||
|
|
|
@ -81,7 +81,7 @@ public final class AddressBookDoCoMoResultParser extends AbstractDoCoMoResultPar
|
|||
}
|
||||
|
||||
private static String parseName(String name) {
|
||||
int comma = name.indexOf((int) ',');
|
||||
int comma = name.indexOf(',');
|
||||
if (comma >= 0) {
|
||||
// Format may be last,first; switch it around
|
||||
return name.substring(comma + 1) + ' ' + name.substring(0, comma);
|
||||
|
|
|
@ -296,7 +296,7 @@ public final class BitArray implements Cloneable {
|
|||
int len = (size - 1) / 32;
|
||||
int oldBitsLen = len + 1;
|
||||
for (int i = 0; i < oldBitsLen; i++) {
|
||||
long x = (long) bits[i];
|
||||
long x = bits[i];
|
||||
x = ((x >> 1) & 0x55555555L) | ((x & 0x55555555L) << 1);
|
||||
x = ((x >> 2) & 0x33333333L) | ((x & 0x33333333L) << 2);
|
||||
x = ((x >> 4) & 0x0f0f0f0fL) | ((x & 0x0f0f0f0fL) << 4);
|
||||
|
|
|
@ -419,7 +419,7 @@ public final class BitMatrix implements Cloneable {
|
|||
* @return string representation of entire matrix utilizing given strings
|
||||
*/
|
||||
public String toString(String setString, String unsetString) {
|
||||
return toString(setString, unsetString, "\n");
|
||||
return buildToString(setString, unsetString, "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -431,6 +431,10 @@ public final class BitMatrix implements Cloneable {
|
|||
*/
|
||||
@Deprecated
|
||||
public String toString(String setString, String unsetString, String lineSeparator) {
|
||||
return buildToString(setString, unsetString, lineSeparator);
|
||||
}
|
||||
|
||||
private String buildToString(String setString, String unsetString, String lineSeparator) {
|
||||
StringBuilder result = new StringBuilder(height * (width + 1));
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
|
|
|
@ -55,7 +55,7 @@ public final class DefaultGridSampler extends GridSampler {
|
|||
float[] points = new float[2 * dimensionX];
|
||||
for (int y = 0; y < dimensionY; y++) {
|
||||
int max = points.length;
|
||||
float iValue = (float) y + 0.5f;
|
||||
float iValue = y + 0.5f;
|
||||
for (int x = 0; x < max; x += 2) {
|
||||
points[x] = (float) (x / 2) + 0.5f;
|
||||
points[x + 1] = iValue;
|
||||
|
|
|
@ -99,7 +99,6 @@ final class GenericGFPoly {
|
|||
// Just return the x^0 coefficient
|
||||
return getCoefficient(0);
|
||||
}
|
||||
int size = coefficients.length;
|
||||
if (a == 1) {
|
||||
// Just the sum of the coefficients
|
||||
int result = 0;
|
||||
|
@ -109,6 +108,7 @@ final class GenericGFPoly {
|
|||
return result;
|
||||
}
|
||||
int result = coefficients[0];
|
||||
int size = coefficients.length;
|
||||
for (int i = 1; i < size; i++) {
|
||||
result = GenericGF.addOrSubtract(field.multiply(a, result), coefficients[i]);
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ final class BitMatrixParser {
|
|||
* @param numColumns Number of columns in the mapping matrix
|
||||
* @return value of the given bit in the mapping matrix
|
||||
*/
|
||||
boolean readModule(int row, int column, int numRows, int numColumns) {
|
||||
private boolean readModule(int row, int column, int numRows, int numColumns) {
|
||||
// Adjust the row and column indices based on boundary wrapping
|
||||
if (row < 0) {
|
||||
row += numRows;
|
||||
|
@ -176,7 +176,7 @@ final class BitMatrixParser {
|
|||
* @param numColumns Number of columns in the mapping matrix
|
||||
* @return byte from the utah shape
|
||||
*/
|
||||
int readUtah(int row, int column, int numRows, int numColumns) {
|
||||
private int readUtah(int row, int column, int numRows, int numColumns) {
|
||||
int currentByte = 0;
|
||||
if (readModule(row - 2, column - 2, numRows, numColumns)) {
|
||||
currentByte |= 1;
|
||||
|
@ -221,7 +221,7 @@ final class BitMatrixParser {
|
|||
* @param numColumns Number of columns in the mapping matrix
|
||||
* @return byte from the Corner condition 1
|
||||
*/
|
||||
int readCorner1(int numRows, int numColumns) {
|
||||
private int readCorner1(int numRows, int numColumns) {
|
||||
int currentByte = 0;
|
||||
if (readModule(numRows - 1, 0, numRows, numColumns)) {
|
||||
currentByte |= 1;
|
||||
|
@ -266,7 +266,7 @@ final class BitMatrixParser {
|
|||
* @param numColumns Number of columns in the mapping matrix
|
||||
* @return byte from the Corner condition 2
|
||||
*/
|
||||
int readCorner2(int numRows, int numColumns) {
|
||||
private int readCorner2(int numRows, int numColumns) {
|
||||
int currentByte = 0;
|
||||
if (readModule(numRows - 3, 0, numRows, numColumns)) {
|
||||
currentByte |= 1;
|
||||
|
@ -311,7 +311,7 @@ final class BitMatrixParser {
|
|||
* @param numColumns Number of columns in the mapping matrix
|
||||
* @return byte from the Corner condition 3
|
||||
*/
|
||||
int readCorner3(int numRows, int numColumns) {
|
||||
private int readCorner3(int numRows, int numColumns) {
|
||||
int currentByte = 0;
|
||||
if (readModule(numRows - 1, 0, numRows, numColumns)) {
|
||||
currentByte |= 1;
|
||||
|
@ -356,7 +356,7 @@ final class BitMatrixParser {
|
|||
* @param numColumns Number of columns in the mapping matrix
|
||||
* @return byte from the Corner condition 4
|
||||
*/
|
||||
int readCorner4(int numRows, int numColumns) {
|
||||
private int readCorner4(int numRows, int numColumns) {
|
||||
int currentByte = 0;
|
||||
if (readModule(numRows - 3, 0, numRows, numColumns)) {
|
||||
currentByte |= 1;
|
||||
|
@ -399,7 +399,7 @@ final class BitMatrixParser {
|
|||
* @param bitMatrix Original {@link BitMatrix} with alignment patterns
|
||||
* @return BitMatrix that has the alignment patterns removed
|
||||
*/
|
||||
BitMatrix extractDataRegion(BitMatrix bitMatrix) {
|
||||
private BitMatrix extractDataRegion(BitMatrix bitMatrix) {
|
||||
int symbolSizeRows = version.getSymbolSizeRows();
|
||||
int symbolSizeColumns = version.getSymbolSizeColumns();
|
||||
|
||||
|
|
|
@ -80,8 +80,6 @@ public final class Decoder {
|
|||
// Separate into data blocks
|
||||
DataBlock[] dataBlocks = DataBlock.getDataBlocks(codewords, version);
|
||||
|
||||
int dataBlocksCount = dataBlocks.length;
|
||||
|
||||
// Count total number of data bytes
|
||||
int totalBytes = 0;
|
||||
for (DataBlock db : dataBlocks) {
|
||||
|
@ -89,6 +87,7 @@ public final class Decoder {
|
|||
}
|
||||
byte[] resultBytes = new byte[totalBytes];
|
||||
|
||||
int dataBlocksCount = dataBlocks.length;
|
||||
// Error-correct and copy data blocks together into a stream of bytes
|
||||
for (int j = 0; j < dataBlocksCount; j++) {
|
||||
DataBlock dataBlock = dataBlocks[j];
|
||||
|
@ -120,9 +119,8 @@ public final class Decoder {
|
|||
for (int i = 0; i < numCodewords; i++) {
|
||||
codewordsInts[i] = codewordBytes[i] & 0xFF;
|
||||
}
|
||||
int numECCodewords = codewordBytes.length - numDataCodewords;
|
||||
try {
|
||||
rsDecoder.decode(codewordsInts, numECCodewords);
|
||||
rsDecoder.decode(codewordsInts, codewordBytes.length - numDataCodewords);
|
||||
} catch (ReedSolomonException ignored) {
|
||||
throw ChecksumException.getChecksumInstance();
|
||||
}
|
||||
|
|
|
@ -416,7 +416,7 @@ public final class Detector {
|
|||
return to;
|
||||
}
|
||||
|
||||
public int getTransitions() {
|
||||
int getTransitions() {
|
||||
return transitions;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,11 +59,11 @@ public class DefaultPlacement {
|
|||
return bits[row * numcols + col] == 1;
|
||||
}
|
||||
|
||||
final void setBit(int col, int row, boolean bit) {
|
||||
private void setBit(int col, int row, boolean bit) {
|
||||
bits[row * numcols + col] = (byte) (bit ? 1 : 0);
|
||||
}
|
||||
|
||||
final boolean hasBit(int col, int row) {
|
||||
private boolean hasBit(int col, int row) {
|
||||
return bits[row * numcols + col] >= 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -152,12 +152,11 @@ public class SymbolInfo {
|
|||
return null;
|
||||
}
|
||||
|
||||
final int getHorizontalDataRegions() {
|
||||
private int getHorizontalDataRegions() {
|
||||
switch (dataRegions) {
|
||||
case 1:
|
||||
return 1;
|
||||
case 2:
|
||||
return 2;
|
||||
case 4:
|
||||
return 2;
|
||||
case 16:
|
||||
|
@ -169,10 +168,9 @@ public class SymbolInfo {
|
|||
}
|
||||
}
|
||||
|
||||
final int getVerticalDataRegions() {
|
||||
private int getVerticalDataRegions() {
|
||||
switch (dataRegions) {
|
||||
case 1:
|
||||
return 1;
|
||||
case 2:
|
||||
return 1;
|
||||
case 4:
|
||||
|
@ -228,13 +226,11 @@ public class SymbolInfo {
|
|||
|
||||
@Override
|
||||
public final String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(rectangular ? "Rectangular Symbol:" : "Square Symbol:");
|
||||
sb.append(" data region ").append(matrixWidth).append('x').append(matrixHeight);
|
||||
sb.append(", symbol size ").append(getSymbolWidth()).append('x').append(getSymbolHeight());
|
||||
sb.append(", symbol data size ").append(getSymbolDataWidth()).append('x').append(getSymbolDataHeight());
|
||||
sb.append(", codewords ").append(dataCapacity).append('+').append(errorCodewords);
|
||||
return sb.toString();
|
||||
return (rectangular ? "Rectangular Symbol:" : "Square Symbol:") +
|
||||
" data region " + matrixWidth + 'x' + matrixHeight +
|
||||
", symbol size " + getSymbolWidth() + 'x' + getSymbolHeight() +
|
||||
", symbol data size " + getSymbolDataWidth() + 'x' + getSymbolDataHeight() +
|
||||
", codewords " + dataCapacity + '+' + errorCodewords;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -73,8 +73,7 @@ public final class MaxiCodeReader implements Reader {
|
|||
throw NotFoundException.getNotFoundInstance();
|
||||
}
|
||||
|
||||
ResultPoint[] points = NO_POINTS;
|
||||
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.MAXICODE);
|
||||
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), NO_POINTS, BarcodeFormat.MAXICODE);
|
||||
|
||||
String ecLevel = decoderResult.getECLevel();
|
||||
if (ecLevel != null) {
|
||||
|
|
|
@ -147,21 +147,21 @@ public final class CodaBarReader extends OneDReader {
|
|||
for (int i = 0; i < startOffset; i++) {
|
||||
runningCount += counters[i];
|
||||
}
|
||||
float left = (float) runningCount;
|
||||
float left = runningCount;
|
||||
for (int i = startOffset; i < nextStart - 1; i++) {
|
||||
runningCount += counters[i];
|
||||
}
|
||||
float right = (float) runningCount;
|
||||
float right = runningCount;
|
||||
return new Result(
|
||||
decodeRowResult.toString(),
|
||||
null,
|
||||
new ResultPoint[]{
|
||||
new ResultPoint(left, (float) rowNumber),
|
||||
new ResultPoint(right, (float) rowNumber)},
|
||||
new ResultPoint(left, rowNumber),
|
||||
new ResultPoint(right, rowNumber)},
|
||||
BarcodeFormat.CODABAR);
|
||||
}
|
||||
|
||||
void validatePattern(int start) throws NotFoundException {
|
||||
private void validatePattern(int start) throws NotFoundException {
|
||||
// First, sum up the total size of our four categories of stripe sizes;
|
||||
int[] sizes = {0, 0, 0, 0};
|
||||
int[] counts = {0, 0, 0, 0};
|
||||
|
|
|
@ -517,7 +517,7 @@ public final class Code128Reader extends OneDReader {
|
|||
}
|
||||
}
|
||||
|
||||
float left = (float) (startPatternInfo[1] + startPatternInfo[0]) / 2.0f;
|
||||
float left = (startPatternInfo[1] + startPatternInfo[0]) / 2.0f;
|
||||
float right = lastStart + lastPatternSize / 2.0f;
|
||||
|
||||
int rawCodesSize = rawCodes.size();
|
||||
|
@ -530,8 +530,8 @@ public final class Code128Reader extends OneDReader {
|
|||
result.toString(),
|
||||
rawBytes,
|
||||
new ResultPoint[]{
|
||||
new ResultPoint(left, (float) rowNumber),
|
||||
new ResultPoint(right, (float) rowNumber)},
|
||||
new ResultPoint(left, rowNumber),
|
||||
new ResultPoint(right, rowNumber)},
|
||||
BarcodeFormat.CODE_128);
|
||||
|
||||
}
|
||||
|
|
|
@ -165,14 +165,14 @@ public final class Code39Reader extends OneDReader {
|
|||
resultString = result.toString();
|
||||
}
|
||||
|
||||
float left = (float) (start[1] + start[0]) / 2.0f;
|
||||
float left = (start[1] + start[0]) / 2.0f;
|
||||
float right = lastStart + lastPatternSize / 2.0f;
|
||||
return new Result(
|
||||
resultString,
|
||||
null,
|
||||
new ResultPoint[]{
|
||||
new ResultPoint(left, (float) rowNumber),
|
||||
new ResultPoint(right, (float) rowNumber)},
|
||||
new ResultPoint(left, rowNumber),
|
||||
new ResultPoint(right, rowNumber)},
|
||||
BarcodeFormat.CODE_39);
|
||||
|
||||
}
|
||||
|
|
|
@ -116,14 +116,14 @@ public final class Code93Reader extends OneDReader {
|
|||
|
||||
String resultString = decodeExtended(result);
|
||||
|
||||
float left = (float) (start[1] + start[0]) / 2.0f;
|
||||
float left = (start[1] + start[0]) / 2.0f;
|
||||
float right = lastStart + lastPatternSize / 2.0f;
|
||||
return new Result(
|
||||
resultString,
|
||||
null,
|
||||
new ResultPoint[]{
|
||||
new ResultPoint(left, (float) rowNumber),
|
||||
new ResultPoint(right, (float) rowNumber)},
|
||||
new ResultPoint(left, rowNumber),
|
||||
new ResultPoint(right, rowNumber)},
|
||||
BarcodeFormat.CODE_93);
|
||||
|
||||
}
|
||||
|
@ -163,12 +163,12 @@ public final class Code93Reader extends OneDReader {
|
|||
}
|
||||
|
||||
private static int toPattern(int[] counters) {
|
||||
int max = counters.length;
|
||||
int sum = 0;
|
||||
for (int counter : counters) {
|
||||
sum += counter;
|
||||
}
|
||||
int pattern = 0;
|
||||
int max = counters.length;
|
||||
for (int i = 0; i < max; i++) {
|
||||
int scaled = Math.round(counters[i] * 9.0f / sum);
|
||||
if (scaled < 1 || scaled > 4) {
|
||||
|
|
|
@ -126,8 +126,8 @@ public final class ITFReader extends OneDReader {
|
|||
return new Result(
|
||||
resultString,
|
||||
null, // no natural byte representation for these barcodes
|
||||
new ResultPoint[] { new ResultPoint(startRange[1], (float) rowNumber),
|
||||
new ResultPoint(endRange[0], (float) rowNumber)},
|
||||
new ResultPoint[] { new ResultPoint(startRange[1], rowNumber),
|
||||
new ResultPoint(endRange[0], rowNumber)},
|
||||
BarcodeFormat.ITF);
|
||||
}
|
||||
|
||||
|
@ -180,7 +180,7 @@ public final class ITFReader extends OneDReader {
|
|||
* @return Array, containing index of start of 'start block' and end of
|
||||
* 'start block'
|
||||
*/
|
||||
int[] decodeStart(BitArray row) throws NotFoundException {
|
||||
private int[] decodeStart(BitArray row) throws NotFoundException {
|
||||
int endStart = skipWhiteSpace(row);
|
||||
int[] startPattern = findGuardPattern(row, endStart, START_PATTERN);
|
||||
|
||||
|
@ -252,7 +252,7 @@ public final class ITFReader extends OneDReader {
|
|||
* @return Array, containing index of start of 'end block' and end of 'end
|
||||
* block'
|
||||
*/
|
||||
int[] decodeEnd(BitArray row) throws NotFoundException {
|
||||
private int[] decodeEnd(BitArray row) throws NotFoundException {
|
||||
|
||||
// For convenience, reverse the row and then
|
||||
// search from 'the start' for the end block
|
||||
|
|
|
@ -47,8 +47,8 @@ final class UPCEANExtension2Support {
|
|||
new Result(resultString,
|
||||
null,
|
||||
new ResultPoint[] {
|
||||
new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, (float) rowNumber),
|
||||
new ResultPoint((float) end, (float) rowNumber),
|
||||
new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, rowNumber),
|
||||
new ResultPoint(end, rowNumber),
|
||||
},
|
||||
BarcodeFormat.UPC_EAN_EXTENSION);
|
||||
if (extensionData != null) {
|
||||
|
@ -57,7 +57,7 @@ final class UPCEANExtension2Support {
|
|||
return extensionResult;
|
||||
}
|
||||
|
||||
int decodeMiddle(BitArray row, int[] startRange, StringBuilder resultString) throws NotFoundException {
|
||||
private int decodeMiddle(BitArray row, int[] startRange, StringBuilder resultString) throws NotFoundException {
|
||||
int[] counters = decodeMiddleCounters;
|
||||
counters[0] = 0;
|
||||
counters[1] = 0;
|
||||
|
|
|
@ -51,8 +51,8 @@ final class UPCEANExtension5Support {
|
|||
new Result(resultString,
|
||||
null,
|
||||
new ResultPoint[] {
|
||||
new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, (float) rowNumber),
|
||||
new ResultPoint((float) end, (float) rowNumber),
|
||||
new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, rowNumber),
|
||||
new ResultPoint(end, rowNumber),
|
||||
},
|
||||
BarcodeFormat.UPC_EAN_EXTENSION);
|
||||
if (extensionData != null) {
|
||||
|
@ -61,7 +61,7 @@ final class UPCEANExtension5Support {
|
|||
return extensionResult;
|
||||
}
|
||||
|
||||
int decodeMiddle(BitArray row, int[] startRange, StringBuilder resultString) throws NotFoundException {
|
||||
private int decodeMiddle(BitArray row, int[] startRange, StringBuilder resultString) throws NotFoundException {
|
||||
int[] counters = decodeMiddleCounters;
|
||||
counters[0] = 0;
|
||||
counters[1] = 0;
|
||||
|
@ -104,11 +104,11 @@ final class UPCEANExtension5Support {
|
|||
int length = s.length();
|
||||
int sum = 0;
|
||||
for (int i = length - 2; i >= 0; i -= 2) {
|
||||
sum += (int) s.charAt(i) - (int) '0';
|
||||
sum += s.charAt(i) - '0';
|
||||
}
|
||||
sum *= 3;
|
||||
for (int i = length - 1; i >= 0; i -= 2) {
|
||||
sum += (int) s.charAt(i) - (int) '0';
|
||||
sum += s.charAt(i) - '0';
|
||||
}
|
||||
sum *= 3;
|
||||
return sum % 10;
|
||||
|
|
|
@ -196,14 +196,14 @@ public abstract class UPCEANReader extends OneDReader {
|
|||
throw ChecksumException.getChecksumInstance();
|
||||
}
|
||||
|
||||
float left = (float) (startGuardRange[1] + startGuardRange[0]) / 2.0f;
|
||||
float right = (float) (endRange[1] + endRange[0]) / 2.0f;
|
||||
float left = (startGuardRange[1] + startGuardRange[0]) / 2.0f;
|
||||
float right = (endRange[1] + endRange[0]) / 2.0f;
|
||||
BarcodeFormat format = getBarcodeFormat();
|
||||
Result decodeResult = new Result(resultString,
|
||||
null, // no natural byte representation for these barcodes
|
||||
new ResultPoint[]{
|
||||
new ResultPoint(left, (float) rowNumber),
|
||||
new ResultPoint(right, (float) rowNumber)},
|
||||
new ResultPoint(left, rowNumber),
|
||||
new ResultPoint(right, rowNumber)},
|
||||
format);
|
||||
|
||||
int extensionLength = 0;
|
||||
|
@ -268,7 +268,7 @@ public abstract class UPCEANReader extends OneDReader {
|
|||
|
||||
int sum = 0;
|
||||
for (int i = length - 2; i >= 0; i -= 2) {
|
||||
int digit = (int) s.charAt(i) - (int) '0';
|
||||
int digit = s.charAt(i) - '0';
|
||||
if (digit < 0 || digit > 9) {
|
||||
throw FormatException.getFormatInstance();
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ public abstract class UPCEANReader extends OneDReader {
|
|||
}
|
||||
sum *= 3;
|
||||
for (int i = length - 1; i >= 0; i -= 2) {
|
||||
int digit = (int) s.charAt(i) - (int) '0';
|
||||
int digit = s.charAt(i) - '0';
|
||||
if (digit < 0 || digit > 9) {
|
||||
throw FormatException.getFormatInstance();
|
||||
}
|
||||
|
@ -312,12 +312,12 @@ public abstract class UPCEANReader extends OneDReader {
|
|||
boolean whiteFirst,
|
||||
int[] pattern,
|
||||
int[] counters) throws NotFoundException {
|
||||
int patternLength = pattern.length;
|
||||
int width = row.getSize();
|
||||
boolean isWhite = whiteFirst;
|
||||
rowOffset = whiteFirst ? row.getNextUnset(rowOffset) : row.getNextSet(rowOffset);
|
||||
int counterPosition = 0;
|
||||
int patternStart = rowOffset;
|
||||
int patternLength = pattern.length;
|
||||
boolean isWhite = whiteFirst;
|
||||
for (int x = rowOffset; x < width; x++) {
|
||||
if (row.get(x) ^ isWhite) {
|
||||
counters[counterPosition]++;
|
||||
|
|
|
@ -120,7 +120,7 @@ public abstract class AbstractRSSReader extends OneDReader {
|
|||
protected static boolean isFinderPattern(int[] counters) {
|
||||
int firstTwoSum = counters[0] + counters[1];
|
||||
int sum = firstTwoSum + counters[2] + counters[3];
|
||||
float ratio = (float) firstTwoSum / (float) sum;
|
||||
float ratio = firstTwoSum / (float) sum;
|
||||
if (ratio >= MIN_FINDER_PATTERN_RATIO && ratio <= MAX_FINDER_PATTERN_RATIO) {
|
||||
// passes ratio test in spec, but see if the counts are unreasonable
|
||||
int minCounter = Integer.MAX_VALUE;
|
||||
|
|
|
@ -31,8 +31,8 @@ public final class FinderPattern {
|
|||
this.value = value;
|
||||
this.startEnd = startEnd;
|
||||
this.resultPoints = new ResultPoint[] {
|
||||
new ResultPoint((float) start, (float) rowNumber),
|
||||
new ResultPoint((float) end, (float) rowNumber),
|
||||
new ResultPoint(start, rowNumber),
|
||||
new ResultPoint(end, rowNumber),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -210,7 +210,7 @@ public final class RSS14Reader extends AbstractRSSReader {
|
|||
}
|
||||
|
||||
int numModules = outsideChar ? 16 : 15;
|
||||
float elementWidth = (float) MathUtils.sum(counters) / (float) numModules;
|
||||
float elementWidth = MathUtils.sum(counters) / (float) numModules;
|
||||
|
||||
int[] oddCounts = this.getOddCounts();
|
||||
int[] evenCounts = this.getEvenCounts();
|
||||
|
@ -218,7 +218,7 @@ public final class RSS14Reader extends AbstractRSSReader {
|
|||
float[] evenRoundingErrors = this.getEvenRoundingErrors();
|
||||
|
||||
for (int i = 0; i < counters.length; i++) {
|
||||
float value = (float) counters[i] / elementWidth;
|
||||
float value = counters[i] / elementWidth;
|
||||
int count = (int) (value + 0.5f); // Round
|
||||
if (count < 1) {
|
||||
count = 1;
|
||||
|
@ -358,9 +358,6 @@ public final class RSS14Reader extends AbstractRSSReader {
|
|||
|
||||
int oddSum = MathUtils.sum(getOddCounts());
|
||||
int evenSum = MathUtils.sum(getEvenCounts());
|
||||
int mismatch = oddSum + evenSum - numModules;
|
||||
boolean oddParityBad = (oddSum & 0x01) == (outsideChar ? 1 : 0);
|
||||
boolean evenParityBad = (evenSum & 0x01) == 1;
|
||||
|
||||
boolean incrementOdd = false;
|
||||
boolean decrementOdd = false;
|
||||
|
@ -391,6 +388,9 @@ public final class RSS14Reader extends AbstractRSSReader {
|
|||
}
|
||||
}
|
||||
|
||||
int mismatch = oddSum + evenSum - numModules;
|
||||
boolean oddParityBad = (oddSum & 0x01) == (outsideChar ? 1 : 0);
|
||||
boolean evenParityBad = (evenSum & 0x01) == 1;
|
||||
/*if (mismatch == 2) {
|
||||
if (!(oddParityBad && evenParityBad)) {
|
||||
throw ReaderException.getInstance();
|
||||
|
|
|
@ -64,13 +64,13 @@ public final class RSSUtils {
|
|||
*/
|
||||
|
||||
public static int getRSSvalue(int[] widths, int maxWidth, boolean noNarrow) {
|
||||
int elements = widths.length;
|
||||
int n = 0;
|
||||
for (int width : widths) {
|
||||
n += width;
|
||||
}
|
||||
int val = 0;
|
||||
int narrowMask = 0;
|
||||
int elements = widths.length;
|
||||
for (int bar = 0; bar < elements - 1; bar++) {
|
||||
int elmWidth;
|
||||
for (elmWidth = 1, narrowMask |= 1 << bar;
|
||||
|
@ -126,34 +126,4 @@ public final class RSSUtils {
|
|||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
static int[] elements(int[] eDist, int N, int K) {
|
||||
int[] widths = new int[eDist.length + 2];
|
||||
int twoK = 2 * K;
|
||||
widths[0] = 1;
|
||||
int i;
|
||||
int minEven = 10;
|
||||
int barSum = 1;
|
||||
for (i = 1; i < twoK - 2; i += 2) {
|
||||
widths[i] = eDist[i - 1] - widths[i - 1];
|
||||
widths[i + 1] = eDist[i] - widths[i];
|
||||
barSum += widths[i] + widths[i + 1];
|
||||
if (widths[i] < minEven) {
|
||||
minEven = widths[i];
|
||||
}
|
||||
}
|
||||
widths[twoK - 1] = N - barSum;
|
||||
if (widths[twoK - 1] < minEven) {
|
||||
minEven = widths[twoK - 1];
|
||||
}
|
||||
if (minEven > 1) {
|
||||
for (i = 0; i < twoK; i += 2) {
|
||||
widths[i] += minEven - 1;
|
||||
widths[i + 1] -= minEven - 1;
|
||||
}
|
||||
}
|
||||
return widths;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
@ -165,8 +165,7 @@ public final class RSSExpandedReader extends AbstractRSSReader {
|
|||
}
|
||||
|
||||
boolean tryStackedDecode = !this.rows.isEmpty();
|
||||
boolean wasReversed = false; // TODO: deal with reversed rows
|
||||
storeRow(rowNumber, wasReversed);
|
||||
storeRow(rowNumber, false); // TODO: deal with reversed rows
|
||||
if (tryStackedDecode) {
|
||||
// When the image is 180-rotated, then rows are sorted in wrong direction.
|
||||
// Try twice with both the directions.
|
||||
|
@ -455,8 +454,7 @@ public final class RSSExpandedReader extends AbstractRSSReader {
|
|||
} catch (NotFoundException ignored) {
|
||||
rightChar = null;
|
||||
}
|
||||
boolean mayBeLast = true;
|
||||
return new ExpandedPair(leftChar, rightChar, pattern, mayBeLast);
|
||||
return new ExpandedPair(leftChar, rightChar, pattern, true);
|
||||
}
|
||||
|
||||
private void findNextPair(BitArray row, List<ExpandedPair> previousPairs, int forcedOffset)
|
||||
|
@ -608,7 +606,7 @@ public final class RSSExpandedReader extends AbstractRSSReader {
|
|||
} //counters[] has the pixels of the module
|
||||
|
||||
int numModules = 17; //left and right data characters have all the same length
|
||||
float elementWidth = (float) MathUtils.sum(counters) / (float) numModules;
|
||||
float elementWidth = MathUtils.sum(counters) / (float) numModules;
|
||||
|
||||
// Sanity check: element width for pattern and the character should match
|
||||
float expectedElementWidth = (pattern.getStartEnd()[1] - pattern.getStartEnd()[0]) / 15.0f;
|
||||
|
@ -694,9 +692,6 @@ public final class RSSExpandedReader extends AbstractRSSReader {
|
|||
|
||||
int oddSum = MathUtils.sum(this.getOddCounts());
|
||||
int evenSum = MathUtils.sum(this.getEvenCounts());
|
||||
int mismatch = oddSum + evenSum - numModules;
|
||||
boolean oddParityBad = (oddSum & 0x01) == 1;
|
||||
boolean evenParityBad = (evenSum & 0x01) == 0;
|
||||
|
||||
boolean incrementOdd = false;
|
||||
boolean decrementOdd = false;
|
||||
|
@ -714,6 +709,9 @@ public final class RSSExpandedReader extends AbstractRSSReader {
|
|||
incrementEven = true;
|
||||
}
|
||||
|
||||
int mismatch = oddSum + evenSum - numModules;
|
||||
boolean oddParityBad = (oddSum & 0x01) == 1;
|
||||
boolean evenParityBad = (evenSum & 0x01) == 0;
|
||||
if (mismatch == 1) {
|
||||
if (oddParityBad) {
|
||||
if (evenParityBad) {
|
||||
|
|
|
@ -95,10 +95,9 @@ final class AI013x0x1xDecoder extends AI01weightDecoder {
|
|||
|
||||
@Override
|
||||
protected void addWeightCode(StringBuilder buf, int weight) {
|
||||
int lastAI = weight / 100000;
|
||||
buf.append('(');
|
||||
buf.append(this.firstAIdigits);
|
||||
buf.append(lastAI);
|
||||
buf.append(weight / 100000);
|
||||
buf.append(')');
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package com.google.zxing.pdf417.decoder;
|
||||
|
||||
import com.google.zxing.FormatException;
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.google.zxing.pdf417.PDF417Common;
|
||||
|
||||
|
@ -32,7 +31,7 @@ final class DetectionResultRowIndicatorColumn extends DetectionResultColumn {
|
|||
this.isLeft = isLeft;
|
||||
}
|
||||
|
||||
void setRowNumbers() {
|
||||
private void setRowNumbers() {
|
||||
for (Codeword codeword : getCodewords()) {
|
||||
if (codeword != null) {
|
||||
codeword.setRowNumberAsRowIndicatorColumn();
|
||||
|
@ -44,7 +43,7 @@ final class DetectionResultRowIndicatorColumn extends DetectionResultColumn {
|
|||
// TODO maybe we should add missing codewords to store the correct row number to make
|
||||
// finding row numbers for other columns easier
|
||||
// use row height count to make detection of invalid row numbers more reliable
|
||||
int adjustCompleteIndicatorColumnRowNumbers(BarcodeMetadata barcodeMetadata) {
|
||||
void adjustCompleteIndicatorColumnRowNumbers(BarcodeMetadata barcodeMetadata) {
|
||||
Codeword[] codewords = getCodewords();
|
||||
setRowNumbers();
|
||||
removeIncorrectCodewords(codewords, barcodeMetadata);
|
||||
|
@ -108,10 +107,10 @@ final class DetectionResultRowIndicatorColumn extends DetectionResultColumn {
|
|||
}
|
||||
}
|
||||
}
|
||||
return (int) (averageRowHeight + 0.5);
|
||||
//return (int) (averageRowHeight + 0.5);
|
||||
}
|
||||
|
||||
int[] getRowHeights() throws FormatException {
|
||||
int[] getRowHeights() {
|
||||
BarcodeMetadata barcodeMetadata = getBarcodeMetadata();
|
||||
if (barcodeMetadata == null) {
|
||||
return null;
|
||||
|
@ -134,7 +133,7 @@ final class DetectionResultRowIndicatorColumn extends DetectionResultColumn {
|
|||
// TODO maybe we should add missing codewords to store the correct row number to make
|
||||
// finding row numbers for other columns easier
|
||||
// use row height count to make detection of invalid row numbers more reliable
|
||||
int adjustIncompleteIndicatorColumnRowNumbers(BarcodeMetadata barcodeMetadata) {
|
||||
private void adjustIncompleteIndicatorColumnRowNumbers(BarcodeMetadata barcodeMetadata) {
|
||||
BoundingBox boundingBox = getBoundingBox();
|
||||
ResultPoint top = isLeft ? boundingBox.getTopLeft() : boundingBox.getTopRight();
|
||||
ResultPoint bottom = isLeft ? boundingBox.getBottomLeft() : boundingBox.getBottomRight();
|
||||
|
@ -170,7 +169,7 @@ final class DetectionResultRowIndicatorColumn extends DetectionResultColumn {
|
|||
currentRowHeight = 1;
|
||||
}
|
||||
}
|
||||
return (int) (averageRowHeight + 0.5);
|
||||
//return (int) (averageRowHeight + 0.5);
|
||||
}
|
||||
|
||||
BarcodeMetadata getBarcodeMetadata() {
|
||||
|
|
|
@ -126,7 +126,7 @@ public final class PDF417ScanningDecoder {
|
|||
|
||||
private static DetectionResult merge(DetectionResultRowIndicatorColumn leftRowIndicatorColumn,
|
||||
DetectionResultRowIndicatorColumn rightRowIndicatorColumn)
|
||||
throws NotFoundException, FormatException {
|
||||
throws NotFoundException {
|
||||
if (leftRowIndicatorColumn == null && rightRowIndicatorColumn == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ public final class PDF417ScanningDecoder {
|
|||
}
|
||||
|
||||
private static BoundingBox adjustBoundingBox(DetectionResultRowIndicatorColumn rowIndicatorColumn)
|
||||
throws NotFoundException, FormatException {
|
||||
throws NotFoundException {
|
||||
if (rowIndicatorColumn == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -431,7 +431,7 @@ public final class PDF417ScanningDecoder {
|
|||
startColumn = endColumn - codewordBitCount;
|
||||
}
|
||||
// TODO implement check for width and correction of black and white bars
|
||||
// use start (and maybe stop pattern) to determine if blackbars are wider than white bars. If so, adjust.
|
||||
// use start (and maybe stop pattern) to determine if black bars are wider than white bars. If so, adjust.
|
||||
// should probably done only for codewords with a lot more than 17 bits.
|
||||
// The following fixes 10-1.png, which has wide black bars and small white bars
|
||||
// for (int i = 0; i < moduleBitCount.length; i++) {
|
||||
|
|
|
@ -85,7 +85,6 @@ final class ModulusPoly {
|
|||
// Just return the x^0 coefficient
|
||||
return getCoefficient(0);
|
||||
}
|
||||
int size = coefficients.length;
|
||||
if (a == 1) {
|
||||
// Just the sum of the coefficients
|
||||
int result = 0;
|
||||
|
@ -95,6 +94,7 @@ final class ModulusPoly {
|
|||
return result;
|
||||
}
|
||||
int result = coefficients[0];
|
||||
int size = coefficients.length;
|
||||
for (int i = 1; i < size; i++) {
|
||||
result = field.add(field.multiply(a, result), coefficients[i]);
|
||||
}
|
||||
|
|
|
@ -259,8 +259,6 @@ public final class Detector {
|
|||
int[] pattern,
|
||||
int[] counters) {
|
||||
Arrays.fill(counters, 0, counters.length, 0);
|
||||
int patternLength = pattern.length;
|
||||
boolean isWhite = whiteFirst;
|
||||
int patternStart = column;
|
||||
int pixelDrift = 0;
|
||||
|
||||
|
@ -270,6 +268,8 @@ public final class Detector {
|
|||
}
|
||||
int x = patternStart;
|
||||
int counterPosition = 0;
|
||||
int patternLength = pattern.length;
|
||||
boolean isWhite = whiteFirst;
|
||||
for (; x < width; x++) {
|
||||
boolean pixel = matrix.get(x, row);
|
||||
if (pixel ^ isWhite) {
|
||||
|
|
|
@ -49,7 +49,7 @@ final class BarcodeRow {
|
|||
* @param x The location in the bar
|
||||
* @param black Black if true, white if false;
|
||||
*/
|
||||
void set(int x, boolean black) {
|
||||
private void set(int x, boolean black) {
|
||||
row[x] = (byte) (black ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -672,11 +672,10 @@ public final class PDF417 {
|
|||
|
||||
//3. step: Error correction
|
||||
String ec = PDF417ErrorCorrection.generateErrorCorrection(dataCodewords, errorCorrectionLevel);
|
||||
String fullCodewords = dataCodewords + ec;
|
||||
|
||||
//4. step: low-level encoding
|
||||
barcodeMatrix = new BarcodeMatrix(rows, cols);
|
||||
encodeLowLevel(fullCodewords, cols, rows, errorCorrectionLevel, barcodeMatrix);
|
||||
encodeLowLevel(dataCodewords + ec, cols, rows, errorCorrectionLevel, barcodeMatrix);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,9 +31,7 @@ import com.google.zxing.common.BitMatrix;
|
|||
*/
|
||||
enum DataMask {
|
||||
|
||||
/**
|
||||
* See ISO 18004:2006 6.8.1
|
||||
*/
|
||||
// See ISO 18004:2006 6.8.1
|
||||
|
||||
/**
|
||||
* 000: mask bits for which (x + y) mod 2 == 0
|
||||
|
|
|
@ -187,9 +187,8 @@ public final class Decoder {
|
|||
for (int i = 0; i < numCodewords; i++) {
|
||||
codewordsInts[i] = codewordBytes[i] & 0xFF;
|
||||
}
|
||||
int numECCodewords = codewordBytes.length - numDataCodewords;
|
||||
try {
|
||||
rsDecoder.decode(codewordsInts, numECCodewords);
|
||||
rsDecoder.decode(codewordsInts, codewordBytes.length - numDataCodewords);
|
||||
} catch (ReedSolomonException ignored) {
|
||||
throw ChecksumException.getChecksumInstance();
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ final class FormatInformation {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (errorCorrectionLevel.ordinal() << 3) | (int) dataMask;
|
||||
return (errorCorrectionLevel.ordinal() << 3) | dataMask;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -158,7 +158,7 @@ final class AlignmentPatternFinder {
|
|||
* figures the location of the center of this black/white/black run.
|
||||
*/
|
||||
private static float centerFromEnd(int[] stateCount, int end) {
|
||||
return (float) (end - stateCount[2]) - stateCount[1] / 2.0f;
|
||||
return (end - stateCount[2]) - stateCount[1] / 2.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -257,7 +257,7 @@ final class AlignmentPatternFinder {
|
|||
float centerJ = centerFromEnd(stateCount, j);
|
||||
float centerI = crossCheckVertical(i, (int) centerJ, 2 * stateCount[1], stateCountTotal);
|
||||
if (!Float.isNaN(centerI)) {
|
||||
float estimatedModuleSize = (float) (stateCount[0] + stateCount[1] + stateCount[2]) / 3.0f;
|
||||
float estimatedModuleSize = (stateCount[0] + stateCount[1] + stateCount[2]) / 3.0f;
|
||||
for (AlignmentPattern center : possibleCenters) {
|
||||
// Look for about the same center and module size:
|
||||
if (center.aboutEquals(estimatedModuleSize, centerI, centerJ)) {
|
||||
|
|
|
@ -108,7 +108,7 @@ public class Detector {
|
|||
|
||||
// Estimate that alignment pattern is closer by 3 modules
|
||||
// from "bottom right" to known top left location
|
||||
float correctionToTopLeft = 1.0f - 3.0f / (float) modulesBetweenFPCenters;
|
||||
float correctionToTopLeft = 1.0f - 3.0f / modulesBetweenFPCenters;
|
||||
int estAlignmentX = (int) (topLeft.getX() + correctionToTopLeft * (bottomRightX - topLeft.getX()));
|
||||
int estAlignmentY = (int) (topLeft.getY() + correctionToTopLeft * (bottomRightY - topLeft.getY()));
|
||||
|
||||
|
@ -118,7 +118,7 @@ public class Detector {
|
|||
alignmentPattern = findAlignmentInRegion(moduleSize,
|
||||
estAlignmentX,
|
||||
estAlignmentY,
|
||||
(float) i);
|
||||
i);
|
||||
break;
|
||||
} catch (NotFoundException re) {
|
||||
// try next round
|
||||
|
@ -146,7 +146,7 @@ public class Detector {
|
|||
ResultPoint bottomLeft,
|
||||
ResultPoint alignmentPattern,
|
||||
int dimension) {
|
||||
float dimMinusThree = (float) dimension - 3.5f;
|
||||
float dimMinusThree = dimension - 3.5f;
|
||||
float bottomRightX;
|
||||
float bottomRightY;
|
||||
float sourceBottomRightX;
|
||||
|
@ -271,20 +271,20 @@ public class Detector {
|
|||
float scale = 1.0f;
|
||||
int otherToX = fromX - (toX - fromX);
|
||||
if (otherToX < 0) {
|
||||
scale = (float) fromX / (float) (fromX - otherToX);
|
||||
scale = fromX / (float) (fromX - otherToX);
|
||||
otherToX = 0;
|
||||
} else if (otherToX >= image.getWidth()) {
|
||||
scale = (float) (image.getWidth() - 1 - fromX) / (float) (otherToX - fromX);
|
||||
scale = (image.getWidth() - 1 - fromX) / (float) (otherToX - fromX);
|
||||
otherToX = image.getWidth() - 1;
|
||||
}
|
||||
int otherToY = (int) (fromY - (toY - fromY) * scale);
|
||||
|
||||
scale = 1.0f;
|
||||
if (otherToY < 0) {
|
||||
scale = (float) fromY / (float) (fromY - otherToY);
|
||||
scale = fromY / (float) (fromY - otherToY);
|
||||
otherToY = 0;
|
||||
} else if (otherToY >= image.getHeight()) {
|
||||
scale = (float) (image.getHeight() - 1 - fromY) / (float) (otherToY - fromY);
|
||||
scale = (image.getHeight() - 1 - fromY) / (float) (otherToY - fromY);
|
||||
otherToY = image.getHeight() - 1;
|
||||
}
|
||||
otherToX = (int) (fromX + (otherToX - fromX) * scale);
|
||||
|
|
|
@ -188,7 +188,7 @@ public class FinderPatternFinder {
|
|||
* figures the location of the center of this run.
|
||||
*/
|
||||
private static float centerFromEnd(int[] stateCount, int end) {
|
||||
return (float) (end - stateCount[4] - stateCount[3]) - stateCount[2] / 2.0f;
|
||||
return (end - stateCount[4] - stateCount[3]) - stateCount[2] / 2.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -494,7 +494,7 @@ public class FinderPatternFinder {
|
|||
centerJ = crossCheckHorizontal((int) centerJ, (int) centerI, stateCount[2], stateCountTotal);
|
||||
if (!Float.isNaN(centerJ) &&
|
||||
(!pureBarcode || crossCheckDiagonal((int) centerI, (int) centerJ, stateCount[2], stateCountTotal))) {
|
||||
float estimatedModuleSize = (float) stateCountTotal / 7.0f;
|
||||
float estimatedModuleSize = stateCountTotal / 7.0f;
|
||||
boolean found = false;
|
||||
for (int index = 0; index < possibleCenters.size(); index++) {
|
||||
FinderPattern center = possibleCenters.get(index);
|
||||
|
@ -571,7 +571,7 @@ public class FinderPatternFinder {
|
|||
// and that we need to keep looking. We detect this by asking if the estimated module sizes
|
||||
// vary too much. We arbitrarily say that when the total deviation from average exceeds
|
||||
// 5% of the total module size estimates, it's too much.
|
||||
float average = totalModuleSize / (float) max;
|
||||
float average = totalModuleSize / max;
|
||||
float totalDeviation = 0.0f;
|
||||
for (FinderPattern pattern : possibleCenters) {
|
||||
totalDeviation += Math.abs(pattern.getEstimatedModuleSize() - average);
|
||||
|
@ -603,7 +603,7 @@ public class FinderPatternFinder {
|
|||
totalModuleSize += size;
|
||||
square += size * size;
|
||||
}
|
||||
float average = totalModuleSize / (float) startSize;
|
||||
float average = totalModuleSize / startSize;
|
||||
float stdDev = (float) Math.sqrt(square / startSize - average * average);
|
||||
|
||||
Collections.sort(possibleCenters, new FurthestFromAverageComparator(average));
|
||||
|
@ -627,7 +627,7 @@ public class FinderPatternFinder {
|
|||
totalModuleSize += possibleCenter.getEstimatedModuleSize();
|
||||
}
|
||||
|
||||
float average = totalModuleSize / (float) possibleCenters.size();
|
||||
float average = totalModuleSize / possibleCenters.size();
|
||||
|
||||
Collections.sort(possibleCenters, new CenterComparator(average));
|
||||
|
||||
|
|
|
@ -1,117 +0,0 @@
|
|||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing;
|
||||
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
import com.google.zxing.common.SummaryResults;
|
||||
import com.google.zxing.datamatrix.DataMatrixBlackBox1TestCase;
|
||||
import com.google.zxing.datamatrix.DataMatrixBlackBox2TestCase;
|
||||
import com.google.zxing.oned.Code128BlackBox1TestCase;
|
||||
import com.google.zxing.oned.Code128BlackBox2TestCase;
|
||||
import com.google.zxing.oned.Code128BlackBox3TestCase;
|
||||
import com.google.zxing.oned.Code39BlackBox1TestCase;
|
||||
import com.google.zxing.oned.Code39BlackBox3TestCase;
|
||||
import com.google.zxing.oned.Code39ExtendedBlackBox2TestCase;
|
||||
import com.google.zxing.oned.EAN13BlackBox1TestCase;
|
||||
import com.google.zxing.oned.EAN13BlackBox2TestCase;
|
||||
import com.google.zxing.oned.EAN13BlackBox3TestCase;
|
||||
import com.google.zxing.oned.EAN13BlackBox4TestCase;
|
||||
import com.google.zxing.oned.EAN8BlackBox1TestCase;
|
||||
import com.google.zxing.oned.ITFBlackBox1TestCase;
|
||||
import com.google.zxing.oned.ITFBlackBox2TestCase;
|
||||
import com.google.zxing.oned.UPCABlackBox1TestCase;
|
||||
import com.google.zxing.oned.UPCABlackBox2TestCase;
|
||||
import com.google.zxing.oned.UPCABlackBox3ReflectiveTestCase;
|
||||
import com.google.zxing.oned.UPCABlackBox4TestCase;
|
||||
import com.google.zxing.oned.UPCABlackBox5TestCase;
|
||||
import com.google.zxing.oned.UPCEBlackBox1TestCase;
|
||||
import com.google.zxing.oned.UPCEBlackBox2TestCase;
|
||||
import com.google.zxing.oned.UPCEBlackBox3ReflectiveTestCase;
|
||||
import com.google.zxing.pdf417.PDF417BlackBox1TestCase;
|
||||
import com.google.zxing.pdf417.PDF417BlackBox2TestCase;
|
||||
import com.google.zxing.qrcode.QRCodeBlackBox1TestCase;
|
||||
import com.google.zxing.qrcode.QRCodeBlackBox2TestCase;
|
||||
import com.google.zxing.qrcode.QRCodeBlackBox3TestCase;
|
||||
import com.google.zxing.qrcode.QRCodeBlackBox4TestCase;
|
||||
import com.google.zxing.qrcode.QRCodeBlackBox5TestCase;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* This is a quick and dirty way to get totals across all the positive black box tests. It is
|
||||
* necessary because we spawn multiple processes when using the standard test-blackbox Ant target.
|
||||
* It would be a shame to change that because it does help with performance. Perhaps we can find a
|
||||
* way to unify these in the future.
|
||||
*
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public final class AllPositiveBlackBoxTester {
|
||||
|
||||
private static final Logger log = Logger.getLogger(AllPositiveBlackBoxTester.class.getSimpleName());
|
||||
|
||||
// This list has to be manually kept up to date. I don't know any automatic way to include every
|
||||
// subclass of AbstractBlackBoxTestCase, and furthermore to exclude subclasses of
|
||||
// AbstractNegativeBlackBoxTestCase which derives from it.
|
||||
private static final AbstractBlackBoxTestCase[] TESTS = {
|
||||
new DataMatrixBlackBox1TestCase(),
|
||||
new DataMatrixBlackBox2TestCase(),
|
||||
new Code128BlackBox1TestCase(),
|
||||
new Code128BlackBox2TestCase(),
|
||||
new Code128BlackBox3TestCase(),
|
||||
new Code39BlackBox1TestCase(),
|
||||
new Code39ExtendedBlackBox2TestCase(),
|
||||
new Code39BlackBox3TestCase(),
|
||||
new EAN13BlackBox1TestCase(),
|
||||
new EAN13BlackBox2TestCase(),
|
||||
new EAN13BlackBox3TestCase(),
|
||||
new EAN13BlackBox4TestCase(),
|
||||
new EAN8BlackBox1TestCase(),
|
||||
new ITFBlackBox1TestCase(),
|
||||
new ITFBlackBox2TestCase(),
|
||||
new UPCABlackBox1TestCase(),
|
||||
new UPCABlackBox2TestCase(),
|
||||
new UPCABlackBox3ReflectiveTestCase(),
|
||||
new UPCABlackBox4TestCase(),
|
||||
new UPCABlackBox5TestCase(),
|
||||
new UPCEBlackBox1TestCase(),
|
||||
new UPCEBlackBox2TestCase(),
|
||||
new UPCEBlackBox3ReflectiveTestCase(),
|
||||
new PDF417BlackBox1TestCase(),
|
||||
new PDF417BlackBox2TestCase(),
|
||||
new QRCodeBlackBox1TestCase(),
|
||||
new QRCodeBlackBox2TestCase(),
|
||||
new QRCodeBlackBox3TestCase(),
|
||||
new QRCodeBlackBox4TestCase(),
|
||||
new QRCodeBlackBox5TestCase()
|
||||
};
|
||||
|
||||
private AllPositiveBlackBoxTester() {
|
||||
System.setProperty("java.util.logging.SimpleFormatter.format", "%4$s: %5$s%6$s%n");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
long start = System.currentTimeMillis();
|
||||
SummaryResults results = new SummaryResults();
|
||||
|
||||
for (AbstractBlackBoxTestCase test : TESTS) {
|
||||
results.add(test.testBlackBoxCountingResults(false));
|
||||
}
|
||||
|
||||
log.info(results.toString());
|
||||
log.info(String.format("Total time: %d ms", System.currentTimeMillis() - start));
|
||||
}
|
||||
}
|
|
@ -34,7 +34,6 @@ public final class DecoderTest extends Assert {
|
|||
* at com.google.zxing.aztec.decoder.Decoder.correctBits(Decoder.java:231)
|
||||
* at com.google.zxing.aztec.decoder.Decoder.decode(Decoder.java:77)
|
||||
* at com.google.zxing.aztec.decoder.DecoderTest.testDecodeBug1(DecoderTest.java:66)</pre>
|
||||
* @throws FormatException
|
||||
*/
|
||||
@Test(expected = FormatException.class)
|
||||
public void testDecodeTooManyErrors() throws FormatException {
|
||||
|
|
|
@ -101,7 +101,9 @@ public final class DetectorTest extends Assert {
|
|||
try {
|
||||
new Detector(makeLarger(copy, 3)).detect(false);
|
||||
fail("Should not reach here");
|
||||
} catch (NotFoundException expected) { }
|
||||
} catch (NotFoundException expected) {
|
||||
// continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -400,12 +400,16 @@ public final class EncoderTest extends Assert {
|
|||
try {
|
||||
Encoder.encode(alphabet, 25, 33);
|
||||
fail("Encode should have failed. No such thing as 33 layers");
|
||||
} catch (IllegalArgumentException expected) {}
|
||||
} catch (IllegalArgumentException expected) {
|
||||
// continue
|
||||
}
|
||||
|
||||
try {
|
||||
Encoder.encode(alphabet, 25, -1);
|
||||
fail("Encode should have failed. Text can't fit in 1-layer compact");
|
||||
} catch (IllegalArgumentException expected) {}
|
||||
} catch (IllegalArgumentException expected) {
|
||||
// continue
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -419,7 +423,9 @@ public final class EncoderTest extends Assert {
|
|||
try {
|
||||
Encoder.encode(data, 0, -4);
|
||||
fail("Encode should have failed. Text can't fit in 1-layer compact");
|
||||
} catch (IllegalArgumentException expected) {}
|
||||
} catch (IllegalArgumentException expected) {
|
||||
// continue
|
||||
}
|
||||
|
||||
// If we just try to encode it normally, it will go to a non-compact 4 layer
|
||||
AztecCode aztecCode = Encoder.encode(data, 0, Encoder.DEFAULT_AZTEC_LAYERS);
|
||||
|
|
|
@ -128,7 +128,7 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
|
|||
testBlackBoxCountingResults(true);
|
||||
}
|
||||
|
||||
public final SummaryResults testBlackBoxCountingResults(boolean assertOnFailure) throws IOException {
|
||||
private void testBlackBoxCountingResults(boolean assertOnFailure) throws IOException {
|
||||
assertFalse(testResults.isEmpty());
|
||||
|
||||
List<Path> imageFiles = getImageFiles();
|
||||
|
@ -246,7 +246,6 @@ public abstract class AbstractBlackBoxTestCase extends Assert {
|
|||
tryHaderMisreadCounts[x] <= testResult.getMaxTryHarderMisreads());
|
||||
}
|
||||
}
|
||||
return new SummaryResults(totalFound, totalMustPass, totalTests);
|
||||
}
|
||||
|
||||
private boolean decode(BinaryBitmap source,
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.common;
|
||||
|
||||
public final class SummaryResults {
|
||||
|
||||
private int totalFound;
|
||||
private int totalMustPass;
|
||||
private int totalTests;
|
||||
|
||||
public SummaryResults() {
|
||||
totalFound = 0;
|
||||
totalMustPass = 0;
|
||||
totalTests = 0;
|
||||
}
|
||||
|
||||
public SummaryResults(int found, int mustPass, int total) {
|
||||
totalFound = found;
|
||||
totalMustPass = mustPass;
|
||||
totalTests = total;
|
||||
}
|
||||
|
||||
public void add(SummaryResults other) {
|
||||
totalFound += other.totalFound;
|
||||
totalMustPass += other.totalMustPass;
|
||||
totalTests += other.totalTests;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "\nSUMMARY RESULTS:\n Decoded " + totalFound + " images out of " + totalTests +
|
||||
" (" + (totalFound * 100 / totalTests) + "%, " + totalMustPass + " required)";
|
||||
}
|
||||
|
||||
}
|
|
@ -21,7 +21,6 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.ReaderException;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.Writer;
|
||||
import com.google.zxing.WriterException;
|
||||
|
@ -86,7 +85,7 @@ public class Code128WriterTestCase extends Assert {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testRoundtrip() throws WriterException, ReaderException {
|
||||
public void testRoundtrip() throws Exception {
|
||||
String toEncode = "\u00f1" + "10958" + "\u00f1" + "17160526";
|
||||
String expected = "1095817160526";
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ import com.google.zxing.Result;
|
|||
import com.google.zxing.ResultMetadataType;
|
||||
import com.google.zxing.common.AbstractBlackBoxTestCase;
|
||||
import com.google.zxing.common.HybridBinarizer;
|
||||
import com.google.zxing.common.SummaryResults;
|
||||
import com.google.zxing.common.TestResult;
|
||||
|
||||
import com.google.zxing.multi.MultipleBarcodeReader;
|
||||
|
@ -74,7 +73,7 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
|
|||
testPDF417BlackBoxCountingResults(true);
|
||||
}
|
||||
|
||||
private SummaryResults testPDF417BlackBoxCountingResults(boolean assertOnFailure) throws IOException {
|
||||
private void testPDF417BlackBoxCountingResults(boolean assertOnFailure) throws IOException {
|
||||
assertFalse(testResults.isEmpty());
|
||||
|
||||
Map<String,List<Path>> imageFiles = getImageFileLists();
|
||||
|
@ -174,7 +173,6 @@ public final class PDF417BlackBox4TestCase extends AbstractBlackBoxTestCase {
|
|||
assertTrue("Try harder, " + label, tryHarderCounts[x] >= testResult.getTryHarderCount());
|
||||
}
|
||||
}
|
||||
return new SummaryResults(totalFound, totalMustPass, totalTests);
|
||||
}
|
||||
|
||||
private static PDF417ResultMetadata getMeta(Result result) {
|
||||
|
|
|
@ -173,7 +173,7 @@ final class DecodeWorker implements Callable<Integer> {
|
|||
output.write('\n');
|
||||
}
|
||||
}
|
||||
System.out.println(output.toString());
|
||||
System.out.println(output);
|
||||
}
|
||||
|
||||
return results;
|
||||
|
|
|
@ -193,14 +193,7 @@ public final class CalendarEventGenerator implements GeneratorSource {
|
|||
String dates = getDateTimeFields();
|
||||
String location = getLocationField();
|
||||
String description = getDescriptionField();
|
||||
StringBuilder output = new StringBuilder();
|
||||
output.append("BEGIN:VEVENT\r\n");
|
||||
output.append(eventName);
|
||||
output.append(dates);
|
||||
output.append(location);
|
||||
output.append(description);
|
||||
output.append("END:VEVENT\r\n");
|
||||
return output.toString();
|
||||
return "BEGIN:VEVENT\r\n" + eventName + dates + location + description + "END:VEVENT\r\n";
|
||||
}
|
||||
|
||||
private String getEventNameField() throws GeneratorException {
|
||||
|
@ -257,14 +250,8 @@ public final class CalendarEventGenerator implements GeneratorSource {
|
|||
// Specify end date as +1 day since it's exclusive
|
||||
Date date2PlusDay = new Date(date2.getTime() + 24 * 60 * 60 * 1000);
|
||||
DateTimeFormat isoFormatter = DateTimeFormat.getFormat("yyyyMMdd");
|
||||
StringBuilder output = new StringBuilder();
|
||||
output.append("DTSTART;VALUE=DATE:");
|
||||
output.append(isoFormatter.format(date1));
|
||||
output.append("\r\n");
|
||||
output.append("DTEND;VALUE=DATE:");
|
||||
output.append(isoFormatter.format(date2PlusDay));
|
||||
output.append("\r\n");
|
||||
return output.toString();
|
||||
return "DTSTART;VALUE=DATE:" + isoFormatter.format(date1) + "\r\n" +
|
||||
"DTEND;VALUE=DATE:" + isoFormatter.format(date2PlusDay) + "\r\n";
|
||||
}
|
||||
|
||||
private String getDateTimeValues() throws GeneratorException {
|
||||
|
@ -286,14 +273,8 @@ public final class CalendarEventGenerator implements GeneratorSource {
|
|||
throw new GeneratorException("Ending date/time cannot be before starting date/time.");
|
||||
}
|
||||
DateTimeFormat isoFormatter = DateTimeFormat.getFormat("yyyyMMdd'T'HHmmss'Z'");
|
||||
StringBuilder output = new StringBuilder();
|
||||
output.append("DTSTART:");
|
||||
output.append(isoFormatter.format(dateTime1));
|
||||
output.append("\r\n");
|
||||
output.append("DTEND:");
|
||||
output.append(isoFormatter.format(dateTime2));
|
||||
output.append("\r\n");
|
||||
return output.toString();
|
||||
return "DTSTART:" + isoFormatter.format(dateTime1) + "\r\n" +
|
||||
"DTEND:" + isoFormatter.format(dateTime2) + "\r\n";
|
||||
}
|
||||
|
||||
private static Date mergeDateAndTime(Date date, Date time) {
|
||||
|
|
|
@ -199,13 +199,11 @@ public final class Generator implements EntryPoint {
|
|||
}
|
||||
|
||||
private static String getUrl(int sizeX, int sizeY, String ecLevel, String encoding, String content) {
|
||||
StringBuilder result = new StringBuilder(100);
|
||||
result.append("https://zxing.org/w/chart?cht=qr");
|
||||
result.append("&chs=").append(sizeX).append('x').append(sizeY);
|
||||
result.append("&chld=").append(ecLevel);
|
||||
result.append("&choe=").append(encoding);
|
||||
result.append("&chl=").append(URL.encodeQueryString(content));
|
||||
return result.toString();
|
||||
return "https://zxing.org/w/chart?cht=qr" +
|
||||
"&chs=" + sizeX + 'x' + sizeY +
|
||||
"&chld=" + ecLevel +
|
||||
"&choe=" + encoding +
|
||||
"&chl=" + URL.encodeQueryString(content);
|
||||
}
|
||||
|
||||
private void generate() {
|
||||
|
|
|
@ -51,12 +51,11 @@ public final class DoSFilter implements Filter {
|
|||
private static final int MAX_ACCESSES_PER_IP_PER_TIME = 10;
|
||||
private static final int MAX_RECENT_ACCESS_MAP_SIZE = 100_000;
|
||||
|
||||
private Map<String,AtomicInteger> numRecentAccesses;
|
||||
private Set<String> bannedIPAddresses;
|
||||
private final Map<String,AtomicInteger> numRecentAccesses;
|
||||
private final Set<String> bannedIPAddresses;
|
||||
private Timer timer;
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) {
|
||||
public DoSFilter() {
|
||||
numRecentAccesses = Collections.synchronizedMap(new LinkedHashMap<String,AtomicInteger>() {
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry<String,AtomicInteger> eldest) {
|
||||
|
@ -64,6 +63,10 @@ public final class DoSFilter implements Filter {
|
|||
}
|
||||
});
|
||||
bannedIPAddresses = Collections.synchronizedSet(new HashSet<String>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) {
|
||||
timer = new Timer("DoSFilter reset timer");
|
||||
timer.scheduleAtFixedRate(
|
||||
new TimerTask() {
|
||||
|
@ -110,20 +113,20 @@ public final class DoSFilter implements Filter {
|
|||
}
|
||||
|
||||
private int getCount(String remoteIPAddress) {
|
||||
synchronized (numRecentAccesses) {
|
||||
AtomicInteger count = numRecentAccesses.get(remoteIPAddress);
|
||||
if (count == null) {
|
||||
numRecentAccesses.put(remoteIPAddress, new AtomicInteger(1));
|
||||
return 1;
|
||||
} else {
|
||||
return count.incrementAndGet();
|
||||
}
|
||||
AtomicInteger count = numRecentAccesses.get(remoteIPAddress);
|
||||
if (count == null) {
|
||||
numRecentAccesses.put(remoteIPAddress, new AtomicInteger(1));
|
||||
return 1;
|
||||
} else {
|
||||
return count.incrementAndGet();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
timer.cancel();
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
body {background-color:#e9eef3;margin:0;padding:0;padding-top:10px;text-align:center}
|
||||
body {background-color:#e9eef3;margin:0;padding:10px 0 0 0;text-align:center}
|
||||
body,th,td,p{font-family:Arial,sans-serif}
|
||||
div#main{width:800px;text-align:left;border:0;padding:0;margin:0 auto}
|
||||
td{vertical-align:top}
|
||||
|
|
Loading…
Reference in a new issue