From 4cddfddb66202a9f24d6a3ba13f0307644711c60 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Tue, 28 Aug 2018 21:44:28 +0000 Subject: [PATCH] Simplified small pieces of code. --- src/io/nayuki/fastqrcodegen/QrCode.java | 7 +------ src/io/nayuki/fastqrcodegen/QrSegment.java | 8 +------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/io/nayuki/fastqrcodegen/QrCode.java b/src/io/nayuki/fastqrcodegen/QrCode.java index c54d718..9935c91 100644 --- a/src/io/nayuki/fastqrcodegen/QrCode.java +++ b/src/io/nayuki/fastqrcodegen/QrCode.java @@ -215,13 +215,10 @@ public final class QrCode { size + brd * 2)) .append("\t\n") .append("\t MAX_VERSION) - throw new IllegalArgumentException("Version number out of range"); return QrTemplate.getNumRawDataModules(ver) / 8 - ECC_CODEWORDS_PER_BLOCK[ecl.ordinal()][ver] * NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal()][ver]; diff --git a/src/io/nayuki/fastqrcodegen/QrSegment.java b/src/io/nayuki/fastqrcodegen/QrSegment.java index ea48ce1..9f363f2 100644 --- a/src/io/nayuki/fastqrcodegen/QrSegment.java +++ b/src/io/nayuki/fastqrcodegen/QrSegment.java @@ -168,9 +168,6 @@ public final class QrSegment { // Package-private helper function. static int getTotalBits(List segs, int version) { Objects.requireNonNull(segs); - if (version < 1 || version > 40) - throw new IllegalArgumentException("Version number out of range"); - long result = 0; for (QrSegment seg : segs) { Objects.requireNonNull(seg); @@ -235,10 +232,7 @@ public final class QrSegment { /*-- Method --*/ int numCharCountBits(int ver) { - if ( 1 <= ver && ver <= 9) return numBitsCharCount[0]; - 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"); + return numBitsCharCount[(ver + 7) / 17]; } }