Skip to content
Permalink
Browse files

Minor code inspection: Use Math.min, Arrays.fill. No point in keeping…

… opts from J2ME days
  • Loading branch information...
srowen committed Jul 29, 2019
1 parent 1cc5cbe commit 4e110ecdbb1fcf689e2058e3aea1e8a8cbe2e822
@@ -68,7 +68,7 @@ public CameraManager(Context context) {
this.configManager = new CameraConfigurationManager(context);
previewCallback = new PreviewCallback(configManager);
}

/**
* Opens the camera driver and initializes the hardware parameters.
*
@@ -231,16 +231,13 @@ public synchronized Rect getFramingRect() {
}
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 synchronized Rect getFramingRectInPreview() {
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 synchronized Rect getFramingRectInPreview() {
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.
@@ -112,7 +112,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
return false;
}
}

private void share() {
QRCodeEncoder encoder = qrCodeEncoder;
if (encoder == null) { // Odd
@@ -184,7 +184,7 @@ protected void onResume() {
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();
@@ -107,7 +107,7 @@ public int getNextSet(int from) {
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 int getNextUnset(int from) {
currentBits = ~bits[bitsOffset];
}
int result = (bitsOffset * 32) + Integer.numberOfTrailingZeros(currentBits);
return result > size ? size : result;
return Math.min(result, size);
}

/**
@@ -69,7 +69,7 @@ public int readBits(int numBits) {
// 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;
@@ -131,7 +131,7 @@ private static void calculateThresholdForBlock(byte[] luminances,
}

private static int cap(int value, int max) {
return value < 2 ? 2 : value > max ? max : value;
return value < 2 ? 2 : Math.min(value, max);
}

/**
@@ -85,7 +85,7 @@
}
results.add(result);
} catch (ReaderException re) {
// ignore and continue
// ignore and continue
}
}
if (results.isEmpty()) {
@@ -126,8 +126,8 @@ public int compare(FinderPattern center1, FinderPattern center2) {
* 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
@@ -230,7 +230,7 @@ private void validateQuietZone(BitArray row, int startPattern) throws NotFoundEx
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)) {
@@ -52,7 +52,7 @@ public BitMatrix encode(String contents,
BarcodeFormat format,
int width,
int height,
Map<EncodeHintType,?> hints) throws WriterException {
Map<EncodeHintType,?> hints) {
if (contents.isEmpty()) {
throw new IllegalArgumentException("Found empty contents");
}
@@ -77,9 +77,8 @@
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);
@@ -25,6 +25,7 @@
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 @@ private DataCharacter decodeDataCharacter(BitArray row, FinderPattern pattern, b
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);
@@ -40,6 +40,7 @@
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 @@ DataCharacter decodeDataCharacter(BitArray row,
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);
@@ -60,7 +60,7 @@ public BitMatrix encode(String contents,

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 @@ private static BitMatrix bitMatrixFromEncoder(PDF417 encoder,

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 =
@@ -237,9 +237,7 @@ protected static boolean foundPatternDiagonal(int[] stateCount) {
}

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 @@ protected final void shiftCounts2(int[] stateCount) {
* 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
@@ -101,7 +101,7 @@ public static QRCode encode(String content,

// 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);
}

0 comments on commit 4e110ec

Please sign in to comment.
You can’t perform that action at this time.