From 9a7a01c9a6b6fb76744eacb2e6fab11eccedfabd Mon Sep 17 00:00:00 2001 From: minsu4107 <32637512+minsu4107@users.noreply.github.com> Date: Sun, 24 May 2020 16:24:44 +0900 Subject: [PATCH 1/3] test commit --- java/src/main/java/io/nayuki/qrcodegen/QrCode.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/java/src/main/java/io/nayuki/qrcodegen/QrCode.java b/java/src/main/java/io/nayuki/qrcodegen/QrCode.java index ea0196c..58c4534 100644 --- a/java/src/main/java/io/nayuki/qrcodegen/QrCode.java +++ b/java/src/main/java/io/nayuki/qrcodegen/QrCode.java @@ -198,8 +198,6 @@ public final class QrCode { return new QrCode(version, ecl, dataCodewords, mask); } - - /*---- Instance fields ----*/ // Public immutable scalar parameters: From ce24efed3ccacc18570a16b5a1ac728c116a3fef Mon Sep 17 00:00:00 2001 From: minsu4107 <32637512+minsu4107@users.noreply.github.com> Date: Mon, 25 May 2020 08:40:17 +0900 Subject: [PATCH 2/3] 1. Extract Method 2. QrSegmenetAdvanced 3. THis class's 'if condition' is so complex, changed more intelligiblement. --- .../io/nayuki/qrcodegen/QrSegmentAdvanced.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/java/src/main/java/io/nayuki/qrcodegen/QrSegmentAdvanced.java b/java/src/main/java/io/nayuki/qrcodegen/QrSegmentAdvanced.java index 1efe7b5..3230d9b 100644 --- a/java/src/main/java/io/nayuki/qrcodegen/QrSegmentAdvanced.java +++ b/java/src/main/java/io/nayuki/qrcodegen/QrSegmentAdvanced.java @@ -64,14 +64,14 @@ public final class QrSegmentAdvanced { // Check arguments Objects.requireNonNull(text); Objects.requireNonNull(ecl); - if (!(QrCode.MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= QrCode.MAX_VERSION)) + if (not_Valid_Version(minVersion, maxVersion)) throw new IllegalArgumentException("Invalid value"); // Iterate through version numbers, and make tentative segments List segs = null; int[] codePoints = toCodePoints(text); for (int version = minVersion; ; version++) { - if (version == minVersion || version == 10 || version == 27) + if (is_valid_version(minVersion, version)) segs = makeSegmentsOptimally(codePoints, version); assert segs != null; @@ -88,6 +88,16 @@ public final class QrSegmentAdvanced { } } } + + + private static boolean is_valid_version(int minVersion, int version) { + return version == minVersion || version == 10 || version == 27; + } + + + private static boolean not_Valid_Version(int minVersion, int maxVersion) { + return !(QrCode.MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= QrCode.MAX_VERSION); + } // Returns a new list of segments that is optimal for the given text at the given version number. @@ -277,8 +287,7 @@ public final class QrSegmentAdvanced { */ public static boolean isEncodableAsKanji(String text) { Objects.requireNonNull(text); - return text.chars().allMatch( - c -> isKanji((char)c)); + return text.chars().allMatch(c -> isKanji((char)c)); } From 750c8ba7aedb55c1a7b1ed6439dac731ac6a5240 Mon Sep 17 00:00:00 2001 From: minsu4107 <32637512+minsu4107@users.noreply.github.com> Date: Mon, 25 May 2020 14:34:59 +0900 Subject: [PATCH 3/3] 1. Extract Method, introduce explain value 2. QrSegmenetAdvanced.java 3. THis class had many function. So, declare more method. --- .../nayuki/qrcodegen/QrSegmentAdvanced.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/java/src/main/java/io/nayuki/qrcodegen/QrSegmentAdvanced.java b/java/src/main/java/io/nayuki/qrcodegen/QrSegmentAdvanced.java index 3230d9b..6480897 100644 --- a/java/src/main/java/io/nayuki/qrcodegen/QrSegmentAdvanced.java +++ b/java/src/main/java/io/nayuki/qrcodegen/QrSegmentAdvanced.java @@ -133,22 +133,22 @@ public final class QrSegmentAdvanced { // Calculate costs using dynamic programming for (int i = 0; i < codePoints.length; i++) { - int c = codePoints[i]; + int cPoint = codePoints[i]; int[] curCosts = new int[numModes]; { // Always extend a byte mode segment - curCosts[0] = prevCosts[0] + countUtf8Bytes(c) * 8 * 6; + curCosts[0] = prevCosts[0] + countUtf8Bytes(cPoint) * 8 * 6; charModes[i][0] = modeTypes[0]; } // Extend a segment if possible - if (QrSegment.ALPHANUMERIC_CHARSET.indexOf(c) != -1) { // Is alphanumeric + if (is_alphanumeric(cPoint)) { // Is alphanumeric curCosts[1] = prevCosts[1] + 33; // 5.5 bits per alphanumeric char charModes[i][1] = modeTypes[1]; } - if ('0' <= c && c <= '9') { // Is numeric + if (is_numeric(cPoint)) { // Is numeric curCosts[2] = prevCosts[2] + 20; // 3.33 bits per digit charModes[i][2] = modeTypes[2]; } - if (isKanji(c)) { + if (isKanji(cPoint)) { curCosts[3] = prevCosts[3] + 78; // 13 bits per Shift JIS char charModes[i][3] = modeTypes[3]; } @@ -157,7 +157,8 @@ public final class QrSegmentAdvanced { for (int j = 0; j < numModes; j++) { // To mode for (int k = 0; k < numModes; k++) { // From mode int newCost = (curCosts[k] + 5) / 6 * 6 + headCosts[j]; - if (charModes[i][k] != null && (charModes[i][j] == null || newCost < curCosts[j])) { + boolean is_notNull_or_lower = charModes[i][k] != null && (charModes[i][j] == null || newCost < curCosts[j]); + if (is_notNull_or_lower) { curCosts[j] = newCost; charModes[i][j] = modeTypes[k]; } @@ -189,6 +190,16 @@ public final class QrSegmentAdvanced { } return result; } + + + private static boolean is_numeric(int c) { + return '0' <= c && c <= '9'; + } + + + private static boolean is_alphanumeric(int c) { + return QrSegment.ALPHANUMERIC_CHARSET.indexOf(c) != -1; + } // Returns a new list of segments based on the given text and modes, such that