mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Fix Codacy warnings
This commit is contained in:
parent
eaa34c3b7e
commit
3c64fa1e62
|
@ -430,7 +430,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
|
|||
|
||||
@Override
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
||||
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -92,8 +92,7 @@ public final class HttpHelper {
|
|||
case XML:
|
||||
contentTypes = "application/xml,text/*,*/*";
|
||||
break;
|
||||
case TEXT:
|
||||
default:
|
||||
default: // Includes TEXT
|
||||
contentTypes = "text/*,*/*";
|
||||
}
|
||||
return downloadViaHttp(uri, contentTypes, maxChars);
|
||||
|
|
|
@ -173,18 +173,16 @@ public final class CameraManager {
|
|||
*/
|
||||
public synchronized void setTorch(boolean newSetting) {
|
||||
OpenCamera theCamera = camera;
|
||||
if (theCamera != null) {
|
||||
if (newSetting != configManager.getTorchState(theCamera.getCamera())) {
|
||||
boolean wasAutoFocusManager = autoFocusManager != null;
|
||||
if (wasAutoFocusManager) {
|
||||
autoFocusManager.stop();
|
||||
autoFocusManager = null;
|
||||
}
|
||||
configManager.setTorch(theCamera.getCamera(), newSetting);
|
||||
if (wasAutoFocusManager) {
|
||||
autoFocusManager = new AutoFocusManager(context, theCamera.getCamera());
|
||||
autoFocusManager.start();
|
||||
}
|
||||
if (theCamera != null && newSetting != configManager.getTorchState(theCamera.getCamera())) {
|
||||
boolean wasAutoFocusManager = autoFocusManager != null;
|
||||
if (wasAutoFocusManager) {
|
||||
autoFocusManager.stop();
|
||||
autoFocusManager = null;
|
||||
}
|
||||
configManager.setTorch(theCamera.getCamera(), newSetting);
|
||||
if (wasAutoFocusManager) {
|
||||
autoFocusManager = new AutoFocusManager(context, theCamera.getCamera());
|
||||
autoFocusManager.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,12 +27,12 @@ public final class OpenCameraInterface {
|
|||
|
||||
private static final String TAG = OpenCameraInterface.class.getName();
|
||||
|
||||
private OpenCameraInterface() {
|
||||
}
|
||||
|
||||
/** For {@link #open(int)}, means no preference for which camera to open. */
|
||||
public static final int NO_REQUESTED_CAMERA = -1;
|
||||
|
||||
private OpenCameraInterface() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the requested camera with {@link Camera#open(int)}, if one exists.
|
||||
*
|
||||
|
|
|
@ -46,6 +46,11 @@ public abstract class SupplementalInfoRetriever extends AsyncTask<Object,Object,
|
|||
|
||||
private static final String TAG = "SupplementalInfo";
|
||||
|
||||
private final WeakReference<TextView> textViewRef;
|
||||
private final WeakReference<HistoryManager> historyManagerRef;
|
||||
private final Collection<Spannable> newContents;
|
||||
private final Collection<String[]> newHistories;
|
||||
|
||||
public static void maybeInvokeRetrieval(TextView textView,
|
||||
ParsedResult result,
|
||||
HistoryManager historyManager,
|
||||
|
@ -78,11 +83,6 @@ public abstract class SupplementalInfoRetriever extends AsyncTask<Object,Object,
|
|||
}
|
||||
}
|
||||
|
||||
private final WeakReference<TextView> textViewRef;
|
||||
private final WeakReference<HistoryManager> historyManagerRef;
|
||||
private final Collection<Spannable> newContents;
|
||||
private final Collection<String[]> newHistories;
|
||||
|
||||
SupplementalInfoRetriever(TextView textView, HistoryManager historyManager) {
|
||||
textViewRef = new WeakReference<>(textView);
|
||||
historyManagerRef = new WeakReference<>(historyManager);
|
||||
|
|
|
@ -59,20 +59,15 @@ public final class StringUtils {
|
|||
boolean canBeShiftJIS = true;
|
||||
boolean canBeUTF8 = true;
|
||||
int utf8BytesLeft = 0;
|
||||
//int utf8LowChars = 0;
|
||||
int utf2BytesChars = 0;
|
||||
int utf3BytesChars = 0;
|
||||
int utf4BytesChars = 0;
|
||||
int sjisBytesLeft = 0;
|
||||
//int sjisLowChars = 0;
|
||||
int sjisKatakanaChars = 0;
|
||||
//int sjisDoubleBytesChars = 0;
|
||||
int sjisCurKatakanaWordLength = 0;
|
||||
int sjisCurDoubleBytesWordLength = 0;
|
||||
int sjisMaxKatakanaWordLength = 0;
|
||||
int sjisMaxDoubleBytesWordLength = 0;
|
||||
//int isoLowChars = 0;
|
||||
//int isoHighChars = 0;
|
||||
int isoHighOther = 0;
|
||||
|
||||
boolean utf8bom = bytes.length > 3 &&
|
||||
|
@ -115,24 +110,16 @@ public final class StringUtils {
|
|||
}
|
||||
}
|
||||
}
|
||||
} //else {
|
||||
//utf8LowChars++;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
// ISO-8859-1 stuff
|
||||
if (canBeISO88591) {
|
||||
if (value > 0x7F && value < 0xA0) {
|
||||
canBeISO88591 = false;
|
||||
} else if (value > 0x9F) {
|
||||
if (value < 0xC0 || value == 0xD7 || value == 0xF7) {
|
||||
isoHighOther++;
|
||||
} //else {
|
||||
//isoHighChars++;
|
||||
//}
|
||||
} //else {
|
||||
//isoLowChars++;
|
||||
//}
|
||||
} else if (value > 0x9F && (value < 0xC0 || value == 0xD7 || value == 0xF7)) {
|
||||
isoHighOther++;
|
||||
}
|
||||
}
|
||||
|
||||
// Shift_JIS stuff
|
||||
|
|
|
@ -42,11 +42,8 @@ class C40Encoder implements Encoder {
|
|||
if (!context.hasMoreCharacters()) {
|
||||
//Avoid having a single C40 value in the last triplet
|
||||
StringBuilder removed = new StringBuilder();
|
||||
if ((buffer.length() % 3) == 2) {
|
||||
if (available < 2 || available > 2) {
|
||||
lastCharSize = backtrackOneCharacter(context, buffer, removed,
|
||||
lastCharSize);
|
||||
}
|
||||
if ((buffer.length() % 3) == 2 && (available < 2 || available > 2)) {
|
||||
lastCharSize = backtrackOneCharacter(context, buffer, removed, lastCharSize);
|
||||
}
|
||||
while ((buffer.length() % 3) == 1
|
||||
&& ((lastCharSize <= 3 && available != 1) || lastCharSize > 3)) {
|
||||
|
|
|
@ -188,10 +188,8 @@ public final class HighLevelEncoder {
|
|||
int len = context.getCodewordCount();
|
||||
context.updateSymbolInfo();
|
||||
int capacity = context.getSymbolInfo().getDataCapacity();
|
||||
if (len < capacity) {
|
||||
if (encodingMode != ASCII_ENCODATION && encodingMode != BASE256_ENCODATION) {
|
||||
context.writeCodeword('\u00fe'); //Unlatch (254)
|
||||
}
|
||||
if (len < capacity && encodingMode != ASCII_ENCODATION && encodingMode != BASE256_ENCODATION) {
|
||||
context.writeCodeword('\u00fe'); //Unlatch (254)
|
||||
}
|
||||
//Padding
|
||||
StringBuilder codewords = context.getCodewords();
|
||||
|
|
|
@ -63,15 +63,6 @@ public class SymbolInfo {
|
|||
|
||||
private static SymbolInfo[] symbols = PROD_SYMBOLS;
|
||||
|
||||
/**
|
||||
* Overrides the symbol info set used by this class. Used for testing purposes.
|
||||
*
|
||||
* @param override the symbol info set to use
|
||||
*/
|
||||
public static void overrideSymbolSet(SymbolInfo[] override) {
|
||||
symbols = override;
|
||||
}
|
||||
|
||||
private final boolean rectangular;
|
||||
private final int dataCapacity;
|
||||
private final int errorCodewords;
|
||||
|
@ -81,6 +72,15 @@ public class SymbolInfo {
|
|||
private final int rsBlockData;
|
||||
private final int rsBlockError;
|
||||
|
||||
/**
|
||||
* Overrides the symbol info set used by this class. Used for testing purposes.
|
||||
*
|
||||
* @param override the symbol info set to use
|
||||
*/
|
||||
public static void overrideSymbolSet(SymbolInfo[] override) {
|
||||
symbols = override;
|
||||
}
|
||||
|
||||
public SymbolInfo(boolean rectangular, int dataCapacity, int errorCodewords,
|
||||
int matrixWidth, int matrixHeight, int dataRegions) {
|
||||
this(rectangular, dataCapacity, errorCodewords, matrixWidth, matrixHeight, dataRegions,
|
||||
|
|
|
@ -73,42 +73,41 @@ public final class MultiFormatUPCEANReader extends OneDReader {
|
|||
// Compute this location once and reuse it on multiple implementations
|
||||
int[] startGuardPattern = UPCEANReader.findStartGuardPattern(row);
|
||||
for (UPCEANReader reader : readers) {
|
||||
Result result;
|
||||
try {
|
||||
result = reader.decodeRow(rowNumber, row, startGuardPattern, hints);
|
||||
Result result = reader.decodeRow(rowNumber, row, startGuardPattern, hints);
|
||||
// Special case: a 12-digit code encoded in UPC-A is identical to a "0"
|
||||
// followed by those 12 digits encoded as EAN-13. Each will recognize such a code,
|
||||
// UPC-A as a 12-digit string and EAN-13 as a 13-digit string starting with "0".
|
||||
// Individually these are correct and their readers will both read such a code
|
||||
// and correctly call it EAN-13, or UPC-A, respectively.
|
||||
//
|
||||
// In this case, if we've been looking for both types, we'd like to call it
|
||||
// a UPC-A code. But for efficiency we only run the EAN-13 decoder to also read
|
||||
// UPC-A. So we special case it here, and convert an EAN-13 result to a UPC-A
|
||||
// result if appropriate.
|
||||
//
|
||||
// But, don't return UPC-A if UPC-A was not a requested format!
|
||||
boolean ean13MayBeUPCA =
|
||||
result.getBarcodeFormat() == BarcodeFormat.EAN_13 &&
|
||||
result.getText().charAt(0) == '0';
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<BarcodeFormat> possibleFormats =
|
||||
hints == null ? null : (Collection<BarcodeFormat>) hints.get(DecodeHintType.POSSIBLE_FORMATS);
|
||||
boolean canReturnUPCA = possibleFormats == null || possibleFormats.contains(BarcodeFormat.UPC_A);
|
||||
|
||||
if (ean13MayBeUPCA && canReturnUPCA) {
|
||||
// Transfer the metdata across
|
||||
Result resultUPCA = new Result(result.getText().substring(1),
|
||||
result.getRawBytes(),
|
||||
result.getResultPoints(),
|
||||
BarcodeFormat.UPC_A);
|
||||
resultUPCA.putAllMetadata(result.getResultMetadata());
|
||||
return resultUPCA;
|
||||
}
|
||||
return result;
|
||||
} catch (ReaderException ignored) {
|
||||
continue;
|
||||
// continue
|
||||
}
|
||||
// Special case: a 12-digit code encoded in UPC-A is identical to a "0"
|
||||
// followed by those 12 digits encoded as EAN-13. Each will recognize such a code,
|
||||
// UPC-A as a 12-digit string and EAN-13 as a 13-digit string starting with "0".
|
||||
// Individually these are correct and their readers will both read such a code
|
||||
// and correctly call it EAN-13, or UPC-A, respectively.
|
||||
//
|
||||
// In this case, if we've been looking for both types, we'd like to call it
|
||||
// a UPC-A code. But for efficiency we only run the EAN-13 decoder to also read
|
||||
// UPC-A. So we special case it here, and convert an EAN-13 result to a UPC-A
|
||||
// result if appropriate.
|
||||
//
|
||||
// But, don't return UPC-A if UPC-A was not a requested format!
|
||||
boolean ean13MayBeUPCA =
|
||||
result.getBarcodeFormat() == BarcodeFormat.EAN_13 &&
|
||||
result.getText().charAt(0) == '0';
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<BarcodeFormat> possibleFormats =
|
||||
hints == null ? null : (Collection<BarcodeFormat>) hints.get(DecodeHintType.POSSIBLE_FORMATS);
|
||||
boolean canReturnUPCA = possibleFormats == null || possibleFormats.contains(BarcodeFormat.UPC_A);
|
||||
|
||||
if (ean13MayBeUPCA && canReturnUPCA) {
|
||||
// Transfer the metdata across
|
||||
Result resultUPCA = new Result(result.getText().substring(1),
|
||||
result.getRawBytes(),
|
||||
result.getResultPoints(),
|
||||
BarcodeFormat.UPC_A);
|
||||
resultUPCA.putAllMetadata(result.getResultMetadata());
|
||||
return resultUPCA;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
throw NotFoundException.getNotFoundInstance();
|
||||
|
|
|
@ -75,10 +75,8 @@ public final class RSS14Reader extends AbstractRSSReader {
|
|||
for (Pair left : possibleLeftPairs) {
|
||||
if (left.getCount() > 1) {
|
||||
for (Pair right : possibleRightPairs) {
|
||||
if (right.getCount() > 1) {
|
||||
if (checkChecksum(left, right)) {
|
||||
return constructResult(left, right);
|
||||
}
|
||||
if (right.getCount() > 1 && checkChecksum(left, right)) {
|
||||
return constructResult(left, right);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -607,18 +607,13 @@ final class DecodedBitStreamParser {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (count % MAX_NUMERIC_CODEWORDS == 0 ||
|
||||
code == NUMERIC_COMPACTION_MODE_LATCH ||
|
||||
end) {
|
||||
if ((count % MAX_NUMERIC_CODEWORDS == 0 || code == NUMERIC_COMPACTION_MODE_LATCH || end) && count > 0) {
|
||||
// Re-invoking Numeric Compaction mode (by using codeword 902
|
||||
// while in Numeric Compaction mode) serves to terminate the
|
||||
// current Numeric Compaction mode grouping as described in 5.4.4.2,
|
||||
// and then to start a new one grouping.
|
||||
if (count > 0) {
|
||||
String s = decodeBase900toBase10(numericCodewords, count);
|
||||
result.append(s);
|
||||
count = 0;
|
||||
}
|
||||
result.append(decodeBase900toBase10(numericCodewords, count));
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
return codeIndex;
|
||||
|
|
|
@ -27,10 +27,6 @@ import com.google.zxing.qrcode.decoder.Version;
|
|||
*/
|
||||
final class MatrixUtil {
|
||||
|
||||
private MatrixUtil() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
private static final int[][] POSITION_DETECTION_PATTERN = {
|
||||
{1, 1, 1, 1, 1, 1, 1},
|
||||
{1, 0, 0, 0, 0, 0, 1},
|
||||
|
@ -119,6 +115,10 @@ final class MatrixUtil {
|
|||
private static final int TYPE_INFO_POLY = 0x537;
|
||||
private static final int TYPE_INFO_MASK_PATTERN = 0x5412;
|
||||
|
||||
private MatrixUtil() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
// Set all cells to -1. -1 means that the cell is empty (not set yet).
|
||||
//
|
||||
// JAVAPORT: We shouldn't need to do this at all. The code should be rewritten to begin encoding
|
||||
|
|
|
@ -45,6 +45,8 @@ public abstract class AbstractNegativeBlackBoxTestCase extends AbstractBlackBoxT
|
|||
|
||||
private static final Logger log = Logger.getLogger(AbstractNegativeBlackBoxTestCase.class.getSimpleName());
|
||||
|
||||
private final List<TestResult> testResults;
|
||||
|
||||
private static final class TestResult {
|
||||
private final int falsePositivesAllowed;
|
||||
private final float rotation;
|
||||
|
@ -54,17 +56,15 @@ public abstract class AbstractNegativeBlackBoxTestCase extends AbstractBlackBoxT
|
|||
this.rotation = rotation;
|
||||
}
|
||||
|
||||
public int getFalsePositivesAllowed() {
|
||||
int getFalsePositivesAllowed() {
|
||||
return falsePositivesAllowed;
|
||||
}
|
||||
|
||||
public float getRotation() {
|
||||
float getRotation() {
|
||||
return rotation;
|
||||
}
|
||||
}
|
||||
|
||||
private final List<TestResult> testResults;
|
||||
|
||||
// Use the multiformat reader to evaluate all decoders in the system.
|
||||
protected AbstractNegativeBlackBoxTestCase(String testBasePathSuffix) {
|
||||
super(testBasePathSuffix, new MultiFormatReader(), null);
|
||||
|
|
|
@ -44,7 +44,7 @@ public class Code128WriterTestCase extends Assert {
|
|||
private Code128Reader reader;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
public void setUp() {
|
||||
writer = new Code128Writer();
|
||||
reader = new Code128Reader();
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ public final class MatrixToImageWriter {
|
|||
}
|
||||
|
||||
/**
|
||||
* As {@link #writeToFile(BitMatrix, String, File)}, but allows customization of the output.
|
||||
* As {@link #writeToPath(BitMatrix, String, Path)}, but allows customization of the output.
|
||||
*
|
||||
* @param matrix {@link BitMatrix} to write
|
||||
* @param format image format
|
||||
|
|
|
@ -56,7 +56,7 @@ public final class MatrixToImageWriterTestCase extends Assert {
|
|||
matrix.set(0, 1);
|
||||
matrix.set(1, 2);
|
||||
|
||||
BufferedImage newImage = null;
|
||||
BufferedImage newImage;
|
||||
Path tempFile = Files.createTempFile(null, "." + format);
|
||||
try {
|
||||
MatrixToImageWriter.writeToPath(matrix, format, tempFile, config);
|
||||
|
|
Loading…
Reference in a new issue