Minor code inspection: Use Math.min, Arrays.fill. No point in keeping opts from J2ME days

This commit is contained in:
Sean Owen 2019-07-29 14:36:16 -05:00
parent 1cc5cbe961
commit 4e110ecdbb
15 changed files with 26 additions and 40 deletions

View file

@ -68,7 +68,7 @@ public final class CameraManager {
this.configManager = new CameraConfigurationManager(context);
previewCallback = new PreviewCallback(configManager);
}
/**
* Opens the camera driver and initializes the hardware parameters.
*
@ -231,16 +231,13 @@ public final class CameraManager {
}
return framingRect;
}
private static int findDesiredDimensionInRange(int resolution, int hardMin, int hardMax) {
int dim = 5 * resolution / 8; // Target 5/8 of each dimension
if (dim < hardMin) {
return hardMin;
}
if (dim > hardMax) {
return hardMax;
}
return dim;
return Math.min(dim, hardMax);
}
/**
@ -271,7 +268,7 @@ public final class CameraManager {
return framingRectInPreview;
}
/**
* Allows third party apps to specify the camera ID, rather than determine
* it automatically based on available cameras and their orientation.
@ -281,7 +278,7 @@ public final class CameraManager {
public synchronized void setManualCameraId(int cameraId) {
requestedCameraId = cameraId;
}
/**
* Allows third party apps to specify the scanning rectangle dimensions, rather than determine
* them automatically based on screen resolution.

View file

@ -112,7 +112,7 @@ public final class EncodeActivity extends Activity {
return false;
}
}
private void share() {
QRCodeEncoder encoder = qrCodeEncoder;
if (encoder == null) { // Odd
@ -184,7 +184,7 @@ public final class EncodeActivity extends Activity {
display.getSize(displaySize);
int width = displaySize.x;
int height = displaySize.y;
int smallerDimension = width < height ? width : height;
int smallerDimension = Math.min(width, height);
smallerDimension = smallerDimension * 7 / 8;
Intent intent = getIntent();

View file

@ -107,7 +107,7 @@ public final class BitArray implements Cloneable {
currentBits = bits[bitsOffset];
}
int result = (bitsOffset * 32) + Integer.numberOfTrailingZeros(currentBits);
return result > size ? size : result;
return Math.min(result, size);
}
/**
@ -130,7 +130,7 @@ public final class BitArray implements Cloneable {
currentBits = ~bits[bitsOffset];
}
int result = (bitsOffset * 32) + Integer.numberOfTrailingZeros(currentBits);
return result > size ? size : result;
return Math.min(result, size);
}
/**

View file

@ -69,7 +69,7 @@ public final class BitSource {
// First, read remainder from current byte
if (bitOffset > 0) {
int bitsLeft = 8 - bitOffset;
int toRead = numBits < bitsLeft ? numBits : bitsLeft;
int toRead = Math.min(numBits, bitsLeft);
int bitsToNotRead = bitsLeft - toRead;
int mask = (0xFF >> (8 - toRead)) << bitsToNotRead;
result = (bytes[byteOffset] & mask) >> bitsToNotRead;

View file

@ -131,7 +131,7 @@ public final class HybridBinarizer extends GlobalHistogramBinarizer {
}
private static int cap(int value, int max) {
return value < 2 ? 2 : value > max ? max : value;
return value < 2 ? 2 : Math.min(value, max);
}
/**

View file

@ -85,7 +85,7 @@ public final class QRCodeMultiReader extends QRCodeReader implements MultipleBar
}
results.add(result);
} catch (ReaderException re) {
// ignore and continue
// ignore and continue
}
}
if (results.isEmpty()) {

View file

@ -126,8 +126,8 @@ final class MultiFinderPatternFinder extends FinderPatternFinder {
* Note: we allow each point to be used for more than one code region: this might seem
* counterintuitive at first, but the performance penalty is not that big. At this point,
* we cannot make a good quality decision whether the three finders actually represent
* a QR code, or are just by chance layouted so it looks like there might be a QR code there.
* So, if the layout seems right, lets have the decoder try to decode.
* a QR code, or are just by chance laid out so it looks like there might be a QR code there.
* So, if the layout seems right, lets have the decoder try to decode.
*/
List<FinderPattern[]> results = new ArrayList<>(); // holder for the results

View file

@ -230,7 +230,7 @@ public final class ITFReader extends OneDReader {
int quietCount = this.narrowLineWidth * 10; // expect to find this many pixels of quiet zone
// if there are not so many pixel at all let's try as many as possible
quietCount = quietCount < startPattern ? quietCount : startPattern;
quietCount = Math.min(quietCount, startPattern);
for (int i = startPattern - 1; quietCount > 0 && i >= 0; i--) {
if (row.get(i)) {

View file

@ -52,7 +52,7 @@ public abstract class OneDimensionalCodeWriter implements Writer {
BarcodeFormat format,
int width,
int height,
Map<EncodeHintType,?> hints) throws WriterException {
Map<EncodeHintType,?> hints) {
if (contents.isEmpty()) {
throw new IllegalArgumentException("Found empty contents");
}

View file

@ -77,9 +77,8 @@ public final class UPCEWriter extends UPCEANWriter {
int checkDigit = Character.digit(contents.charAt(7), 10);
int parities = UPCEReader.NUMSYS_AND_CHECK_DIGIT_PATTERNS[firstDigit][checkDigit];
boolean[] result = new boolean[CODE_WIDTH];
int pos = 0;
pos += appendPattern(result, pos, UPCEANReader.START_END_PATTERN, true);
int pos = appendPattern(result, 0, UPCEANReader.START_END_PATTERN, true);
for (int i = 1; i <= 6; i++) {
int digit = Character.digit(contents.charAt(i), 10);

View file

@ -25,6 +25,7 @@ import com.google.zxing.ResultPointCallback;
import com.google.zxing.common.BitArray;
import com.google.zxing.common.detector.MathUtils;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@ -187,9 +188,7 @@ public final class RSS14Reader extends AbstractRSSReader {
throws NotFoundException {
int[] counters = getDataCharacterCounters();
for (int x = 0; x < counters.length; x++) {
counters[x] = 0;
}
Arrays.fill(counters, 0);
if (outsideChar) {
recordPatternInReverse(row, pattern.getStartEnd()[0], counters);

View file

@ -40,6 +40,7 @@ import com.google.zxing.oned.rss.FinderPattern;
import com.google.zxing.oned.rss.RSSUtils;
import com.google.zxing.oned.rss.expanded.decoders.AbstractExpandedDecoder;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@ -571,9 +572,7 @@ public final class RSSExpandedReader extends AbstractRSSReader {
boolean isOddPattern,
boolean leftChar) throws NotFoundException {
int[] counters = this.getDataCharacterCounters();
for (int x = 0; x < counters.length; x++) {
counters[x] = 0;
}
Arrays.fill(counters, 0);
if (leftChar) {
recordPatternInReverse(row, pattern.getStartEnd()[0], counters);

View file

@ -60,7 +60,7 @@ public final class PDF417Writer implements Writer {
if (hints != null) {
if (hints.containsKey(EncodeHintType.PDF417_COMPACT)) {
encoder.setCompact(Boolean.valueOf(hints.get(EncodeHintType.PDF417_COMPACT).toString()));
encoder.setCompact(Boolean.parseBoolean(hints.get(EncodeHintType.PDF417_COMPACT).toString()));
}
if (hints.containsKey(EncodeHintType.PDF417_COMPACTION)) {
encoder.setCompaction(Compaction.valueOf(hints.get(EncodeHintType.PDF417_COMPACTION).toString()));
@ -116,13 +116,7 @@ public final class PDF417Writer implements Writer {
int scaleX = width / originalScale[0].length;
int scaleY = height / originalScale.length;
int scale;
if (scaleX < scaleY) {
scale = scaleX;
} else {
scale = scaleY;
}
int scale = Math.min(scaleX, scaleY);
if (scale > 1) {
byte[][] scaledMatrix =

View file

@ -237,9 +237,7 @@ public class FinderPatternFinder {
}
protected final void clearCounts(int[] counts) {
for (int x = 0; x < counts.length; x++) {
counts[x] = 0;
}
Arrays.fill(counts, 0);
}
protected final void shiftCounts2(int[] stateCount) {
@ -254,7 +252,7 @@ public class FinderPatternFinder {
* After a vertical and horizontal scan finds a potential finder pattern, this method
* "cross-cross-cross-checks" by scanning down diagonally through the center of the possible
* finder pattern to see if the same proportion is detected.
*
*
* @param centerI row where a finder pattern was detected
* @param centerJ center of the section that appears to cross a finder pattern
* @return true if proportions are withing expected limits

View file

@ -101,7 +101,7 @@ public final class Encoder {
// Append the FNC1 mode header for GS1 formatted data if applicable
boolean hasGS1FormatHint = hints != null && hints.containsKey(EncodeHintType.GS1_FORMAT);
if (hasGS1FormatHint && Boolean.valueOf(hints.get(EncodeHintType.GS1_FORMAT).toString())) {
if (hasGS1FormatHint && Boolean.parseBoolean(hints.get(EncodeHintType.GS1_FORMAT).toString())) {
// GS1 formatted codes are prefixed with a FNC1 in first position mode header
appendModeInfo(Mode.FNC1_FIRST_POSITION, headerBits);
}