mirror of
https://github.com/zxing/zxing.git
synced 2024-11-09 20:44:03 -08:00
Small code improvements from inspections
This commit is contained in:
parent
d897ad7f72
commit
a81dda90ba
|
@ -43,8 +43,6 @@ import com.google.zxing.client.android.clipboard.ClipboardInterface;
|
|||
*/
|
||||
public final class ShareActivity extends Activity {
|
||||
|
||||
private static final String TAG = ShareActivity.class.getSimpleName();
|
||||
|
||||
private static final int PICK_BOOKMARK = 0;
|
||||
private static final int PICK_CONTACT = 1;
|
||||
private static final int PICK_APP = 2;
|
||||
|
@ -96,7 +94,7 @@ public final class ShareActivity extends Activity {
|
|||
public boolean onKey(View view, int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
String text = ((TextView) view).getText().toString();
|
||||
if (text != null && !text.isEmpty()) {
|
||||
if (!text.isEmpty()) {
|
||||
launchSearch(text);
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
package com.google.zxing.client.result;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents a parsed result that encodes extended product information as encoded
|
||||
|
@ -98,48 +99,39 @@ public final class ExpandedProductParsedResult extends ParsedResult {
|
|||
|
||||
ExpandedProductParsedResult other = (ExpandedProductParsedResult) o;
|
||||
|
||||
return equalsOrNull(productID, other.productID)
|
||||
&& equalsOrNull(sscc, other.sscc)
|
||||
&& equalsOrNull(lotNumber, other.lotNumber)
|
||||
&& equalsOrNull(productionDate, other.productionDate)
|
||||
&& equalsOrNull(bestBeforeDate, other.bestBeforeDate)
|
||||
&& equalsOrNull(expirationDate, other.expirationDate)
|
||||
&& equalsOrNull(weight, other.weight)
|
||||
&& equalsOrNull(weightType, other.weightType)
|
||||
&& equalsOrNull(weightIncrement, other.weightIncrement)
|
||||
&& equalsOrNull(price, other.price)
|
||||
&& equalsOrNull(priceIncrement, other.priceIncrement)
|
||||
&& equalsOrNull(priceCurrency, other.priceCurrency)
|
||||
&& equalsOrNull(uncommonAIs, other.uncommonAIs);
|
||||
}
|
||||
|
||||
private static boolean equalsOrNull(Object o1, Object o2) {
|
||||
return o1 == null ? o2 == null : o1.equals(o2);
|
||||
return Objects.equals(productID, other.productID)
|
||||
&& Objects.equals(sscc, other.sscc)
|
||||
&& Objects.equals(lotNumber, other.lotNumber)
|
||||
&& Objects.equals(productionDate, other.productionDate)
|
||||
&& Objects.equals(bestBeforeDate, other.bestBeforeDate)
|
||||
&& Objects.equals(expirationDate, other.expirationDate)
|
||||
&& Objects.equals(weight, other.weight)
|
||||
&& Objects.equals(weightType, other.weightType)
|
||||
&& Objects.equals(weightIncrement, other.weightIncrement)
|
||||
&& Objects.equals(price, other.price)
|
||||
&& Objects.equals(priceIncrement, other.priceIncrement)
|
||||
&& Objects.equals(priceCurrency, other.priceCurrency)
|
||||
&& Objects.equals(uncommonAIs, other.uncommonAIs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash ^= hashNotNull(productID);
|
||||
hash ^= hashNotNull(sscc);
|
||||
hash ^= hashNotNull(lotNumber);
|
||||
hash ^= hashNotNull(productionDate);
|
||||
hash ^= hashNotNull(bestBeforeDate);
|
||||
hash ^= hashNotNull(expirationDate);
|
||||
hash ^= hashNotNull(weight);
|
||||
hash ^= hashNotNull(weightType);
|
||||
hash ^= hashNotNull(weightIncrement);
|
||||
hash ^= hashNotNull(price);
|
||||
hash ^= hashNotNull(priceIncrement);
|
||||
hash ^= hashNotNull(priceCurrency);
|
||||
hash ^= hashNotNull(uncommonAIs);
|
||||
int hash = Objects.hashCode(productID);
|
||||
hash ^= Objects.hashCode(sscc);
|
||||
hash ^= Objects.hashCode(lotNumber);
|
||||
hash ^= Objects.hashCode(productionDate);
|
||||
hash ^= Objects.hashCode(bestBeforeDate);
|
||||
hash ^= Objects.hashCode(expirationDate);
|
||||
hash ^= Objects.hashCode(weight);
|
||||
hash ^= Objects.hashCode(weightType);
|
||||
hash ^= Objects.hashCode(weightIncrement);
|
||||
hash ^= Objects.hashCode(price);
|
||||
hash ^= Objects.hashCode(priceIncrement);
|
||||
hash ^= Objects.hashCode(priceCurrency);
|
||||
hash ^= Objects.hashCode(uncommonAIs);
|
||||
return hash;
|
||||
}
|
||||
|
||||
private static int hashNotNull(Object o) {
|
||||
return o == null ? 0 : o.hashCode();
|
||||
}
|
||||
|
||||
public String getRawText() {
|
||||
return rawText;
|
||||
}
|
||||
|
|
|
@ -96,8 +96,6 @@ public final class DataMatrixReader implements Reader {
|
|||
* which contains only an unrotated, unskewed, image of a code, with some white border
|
||||
* around it. This is a specialized method that works exceptionally fast in this special
|
||||
* case.
|
||||
*
|
||||
* @see com.google.zxing.qrcode.QRCodeReader#extractPureBits(BitMatrix)
|
||||
*/
|
||||
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {
|
||||
|
||||
|
@ -158,4 +156,4 @@ public final class DataMatrixReader implements Reader {
|
|||
return moduleSize;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,9 +82,6 @@ public final class MaxiCodeReader implements Reader {
|
|||
* which contains only an unrotated, unskewed, image of a code, with some white border
|
||||
* around it. This is a specialized method that works exceptionally fast in this special
|
||||
* case.
|
||||
*
|
||||
* @see com.google.zxing.datamatrix.DataMatrixReader#extractPureBits(BitMatrix)
|
||||
* @see com.google.zxing.qrcode.QRCodeReader#extractPureBits(BitMatrix)
|
||||
*/
|
||||
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ final class MultiFinderPatternFinder extends FinderPatternFinder {
|
|||
|
||||
/**
|
||||
* @return the 3 best {@link FinderPattern}s from our list of candidates. The "best" are
|
||||
* those that have been detected at least {@link #CENTER_QUORUM} times, and whose module
|
||||
* those that have been detected at least 2 times, and whose module
|
||||
* size differs from the average among those patterns the least
|
||||
* @throws NotFoundException if 3 such finder patterns do not exist
|
||||
*/
|
||||
|
|
|
@ -29,28 +29,23 @@ package com.google.zxing.oned.rss.expanded;
|
|||
import com.google.zxing.oned.rss.DataCharacter;
|
||||
import com.google.zxing.oned.rss.FinderPattern;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
|
||||
*/
|
||||
final class ExpandedPair {
|
||||
|
||||
private final boolean mayBeLast;
|
||||
private final DataCharacter leftChar;
|
||||
private final DataCharacter rightChar;
|
||||
private final FinderPattern finderPattern;
|
||||
|
||||
ExpandedPair(DataCharacter leftChar,
|
||||
DataCharacter rightChar,
|
||||
FinderPattern finderPattern,
|
||||
boolean mayBeLast) {
|
||||
FinderPattern finderPattern) {
|
||||
this.leftChar = leftChar;
|
||||
this.rightChar = rightChar;
|
||||
this.finderPattern = finderPattern;
|
||||
this.mayBeLast = mayBeLast;
|
||||
}
|
||||
|
||||
boolean mayBeLast() {
|
||||
return this.mayBeLast;
|
||||
}
|
||||
|
||||
DataCharacter getLeftChar() {
|
||||
|
@ -82,23 +77,14 @@ final class ExpandedPair {
|
|||
return false;
|
||||
}
|
||||
ExpandedPair that = (ExpandedPair) o;
|
||||
return
|
||||
equalsOrNull(leftChar, that.leftChar) &&
|
||||
equalsOrNull(rightChar, that.rightChar) &&
|
||||
equalsOrNull(finderPattern, that.finderPattern);
|
||||
}
|
||||
|
||||
private static boolean equalsOrNull(Object o1, Object o2) {
|
||||
return o1 == null ? o2 == null : o1.equals(o2);
|
||||
return Objects.equals(leftChar, that.leftChar) &&
|
||||
Objects.equals(rightChar, that.rightChar) &&
|
||||
Objects.equals(finderPattern, that.finderPattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hashNotNull(leftChar) ^ hashNotNull(rightChar) ^ hashNotNull(finderPattern);
|
||||
}
|
||||
|
||||
private static int hashNotNull(Object o) {
|
||||
return o == null ? 0 : o.hashCode();
|
||||
return Objects.hashCode(leftChar) ^ Objects.hashCode(rightChar) ^ Objects.hashCode(finderPattern);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -452,7 +452,7 @@ public final class RSSExpandedReader extends AbstractRSSReader {
|
|||
} catch (NotFoundException ignored) {
|
||||
rightChar = null;
|
||||
}
|
||||
return new ExpandedPair(leftChar, rightChar, pattern, true);
|
||||
return new ExpandedPair(leftChar, rightChar, pattern);
|
||||
}
|
||||
|
||||
private void findNextPair(BitArray row, List<ExpandedPair> previousPairs, int forcedOffset)
|
||||
|
|
|
@ -18,7 +18,6 @@ package com.google.zxing.pdf417.decoder.ec;
|
|||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
* @see com.google.zxing.common.reedsolomon.GenericGFPoly
|
||||
*/
|
||||
final class ModulusPoly {
|
||||
|
||||
|
|
|
@ -112,8 +112,6 @@ public class QRCodeReader implements Reader {
|
|||
* which contains only an unrotated, unskewed, image of a code, with some white border
|
||||
* around it. This is a specialized method that works exceptionally fast in this special
|
||||
* case.
|
||||
*
|
||||
* @see com.google.zxing.datamatrix.DataMatrixReader#extractPureBits(BitMatrix)
|
||||
*/
|
||||
private static BitMatrix extractPureBits(BitMatrix image) throws NotFoundException {
|
||||
|
||||
|
|
|
@ -612,7 +612,7 @@ public class FinderPatternFinder {
|
|||
for (FinderPattern center : possibleCenters) {
|
||||
float size = center.getEstimatedModuleSize();
|
||||
totalModuleSize += size;
|
||||
square += size * size;
|
||||
square += (double) size * size;
|
||||
}
|
||||
double average = totalModuleSize / startSize;
|
||||
float stdDev = (float) Math.sqrt(square / startSize - average * average);
|
||||
|
|
|
@ -75,6 +75,7 @@ public final class SymbolInfoTestCase extends Assert {
|
|||
Dimension fixedSize = new Dimension(26, 26);
|
||||
info = SymbolInfo.lookup(35,
|
||||
SymbolShapeHint.FORCE_NONE, fixedSize, fixedSize, false);
|
||||
assertNotNull(info);
|
||||
assertEquals(26, info.getSymbolWidth());
|
||||
assertEquals(26, info.getSymbolHeight());
|
||||
|
||||
|
@ -87,16 +88,19 @@ public final class SymbolInfoTestCase extends Assert {
|
|||
|
||||
info = SymbolInfo.lookup(35,
|
||||
SymbolShapeHint.FORCE_NONE, minSize, maxSize, false);
|
||||
assertNotNull(info);
|
||||
assertEquals(26, info.getSymbolWidth());
|
||||
assertEquals(26, info.getSymbolHeight());
|
||||
|
||||
info = SymbolInfo.lookup(40,
|
||||
SymbolShapeHint.FORCE_NONE, minSize, maxSize, false);
|
||||
assertNotNull(info);
|
||||
assertEquals(26, info.getSymbolWidth());
|
||||
assertEquals(26, info.getSymbolHeight());
|
||||
|
||||
info = SymbolInfo.lookup(45,
|
||||
SymbolShapeHint.FORCE_NONE, minSize, maxSize, false);
|
||||
assertNotNull(info);
|
||||
assertEquals(32, info.getSymbolWidth());
|
||||
assertEquals(32, info.getSymbolHeight());
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ public final class Code93WriterTestCase extends Assert {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testConvertToExtended() throws Exception {
|
||||
public void testConvertToExtended() {
|
||||
// non-extended chars are not changed.
|
||||
String src = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%";
|
||||
String dst = Code93Writer.convertToExtended(src);
|
||||
|
|
|
@ -76,7 +76,7 @@ public final class BitArrayBuilderTest extends Assert {
|
|||
rightChar = null;
|
||||
}
|
||||
|
||||
ExpandedPair expandedPair = new ExpandedPair(leftChar, rightChar, null, true);
|
||||
ExpandedPair expandedPair = new ExpandedPair(leftChar, rightChar, null);
|
||||
pairs.add(expandedPair);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,13 +30,11 @@ public final class ErrorCorrectionLevelTestCase extends Assert {
|
|||
assertSame(ErrorCorrectionLevel.L, ErrorCorrectionLevel.forBits(1));
|
||||
assertSame(ErrorCorrectionLevel.H, ErrorCorrectionLevel.forBits(2));
|
||||
assertSame(ErrorCorrectionLevel.Q, ErrorCorrectionLevel.forBits(3));
|
||||
try {
|
||||
ErrorCorrectionLevel.forBits(4);
|
||||
fail("Should have thrown an exception");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
// good
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testBadECLevel() {
|
||||
ErrorCorrectionLevel.forBits(4);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,12 +31,11 @@ public final class ModeTestCase extends Assert {
|
|||
assertSame(Mode.ALPHANUMERIC, Mode.forBits(0x02));
|
||||
assertSame(Mode.BYTE, Mode.forBits(0x04));
|
||||
assertSame(Mode.KANJI, Mode.forBits(0x08));
|
||||
try {
|
||||
Mode.forBits(0x10);
|
||||
fail("Should have thrown an exception");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
// good
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testBadMode() {
|
||||
Mode.forBits(0x10);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -50,4 +49,4 @@ public final class ModeTestCase extends Assert {
|
|||
assertEquals(8, Mode.KANJI.getCharacterCountBits(Version.getVersionForNumber(8)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,14 +24,13 @@ import org.junit.Test;
|
|||
*/
|
||||
public final class VersionTestCase extends Assert {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testBadVersion() {
|
||||
Version.getVersionForNumber(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVersionForNumber() {
|
||||
try {
|
||||
Version.getVersionForNumber(0);
|
||||
fail("Should have thrown an exception");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
// good
|
||||
}
|
||||
for (int i = 1; i <= 40; i++) {
|
||||
checkVersion(Version.getVersionForNumber(i), i, 4 * i + 17);
|
||||
}
|
||||
|
@ -76,4 +75,4 @@ public final class VersionTestCase extends Assert {
|
|||
assertEquals(expectedVersion, version.getVersionNumber());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ public final class CalendarEventGenerator implements GeneratorSource {
|
|||
private final TextBox timePicker2 = new TextBox();
|
||||
private final CheckBox summerTime = new CheckBox();
|
||||
private final ListBox timeZones = new ListBox();
|
||||
private Date timePicker1PreviousDate = null;
|
||||
private Date timePicker1PreviousDate;
|
||||
private final TextBox location = new TextBox();
|
||||
private final TextBox description = new TextBox();
|
||||
|
||||
|
|
Loading…
Reference in a new issue