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