Simplified small pieces of code.

pull/134/head
Project Nayuki 6 years ago
parent b3949f6fc4
commit 4cddfddb66

@ -215,13 +215,10 @@ public final class QrCode {
size + brd * 2)) size + brd * 2))
.append("\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n") .append("\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n")
.append("\t<path d=\""); .append("\t<path d=\"");
boolean head = true;
for (int y = 0; y < size; y++) { for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) { for (int x = 0; x < size; x++) {
if (getModule(x, y)) { if (getModule(x, y)) {
if (head) if (x != 0 || y != 0)
head = false;
else
sb.append(" "); sb.append(" ");
sb.append(String.format("M%d,%dh1v1h-1z", x + brd, y + brd)); sb.append(String.format("M%d,%dh1v1h-1z", x + brd, y + brd));
} }
@ -451,8 +448,6 @@ public final class QrCode {
// QR Code of the given version number and error correction level, with remainder bits discarded. // QR Code of the given version number and error correction level, with remainder bits discarded.
// This stateless pure function could be implemented as a (40*4)-cell lookup table. // This stateless pure function could be implemented as a (40*4)-cell lookup table.
static int getNumDataCodewords(int ver, Ecc ecl) { static int getNumDataCodewords(int ver, Ecc ecl) {
if (ver < MIN_VERSION || ver > MAX_VERSION)
throw new IllegalArgumentException("Version number out of range");
return QrTemplate.getNumRawDataModules(ver) / 8 return QrTemplate.getNumRawDataModules(ver) / 8
- ECC_CODEWORDS_PER_BLOCK[ecl.ordinal()][ver] - ECC_CODEWORDS_PER_BLOCK[ecl.ordinal()][ver]
* NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal()][ver]; * NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal()][ver];

@ -168,9 +168,6 @@ public final class QrSegment {
// Package-private helper function. // Package-private helper function.
static int getTotalBits(List<QrSegment> segs, int version) { static int getTotalBits(List<QrSegment> segs, int version) {
Objects.requireNonNull(segs); Objects.requireNonNull(segs);
if (version < 1 || version > 40)
throw new IllegalArgumentException("Version number out of range");
long result = 0; long result = 0;
for (QrSegment seg : segs) { for (QrSegment seg : segs) {
Objects.requireNonNull(seg); Objects.requireNonNull(seg);
@ -235,10 +232,7 @@ public final class QrSegment {
/*-- Method --*/ /*-- Method --*/
int numCharCountBits(int ver) { int numCharCountBits(int ver) {
if ( 1 <= ver && ver <= 9) return numBitsCharCount[0]; return numBitsCharCount[(ver + 7) / 17];
else if (10 <= ver && ver <= 26) return numBitsCharCount[1];
else if (27 <= ver && ver <= 40) return numBitsCharCount[2];
else throw new IllegalArgumentException("Version number out of range");
} }
} }

Loading…
Cancel
Save