1. Extract Method

2. QrSegmenetAdvanced
3. THis class's 'if condition' is so complex, changed more
intelligiblement.
pull/90/head
minsu4107 5 years ago
parent 9a7a01c9a6
commit ce24efed3c

@ -64,14 +64,14 @@ public final class QrSegmentAdvanced {
// Check arguments // Check arguments
Objects.requireNonNull(text); Objects.requireNonNull(text);
Objects.requireNonNull(ecl); 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"); throw new IllegalArgumentException("Invalid value");
// Iterate through version numbers, and make tentative segments // Iterate through version numbers, and make tentative segments
List<QrSegment> segs = null; List<QrSegment> segs = null;
int[] codePoints = toCodePoints(text); int[] codePoints = toCodePoints(text);
for (int version = minVersion; ; version++) { for (int version = minVersion; ; version++) {
if (version == minVersion || version == 10 || version == 27) if (is_valid_version(minVersion, version))
segs = makeSegmentsOptimally(codePoints, version); segs = makeSegmentsOptimally(codePoints, version);
assert segs != null; assert segs != null;
@ -90,6 +90,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. // Returns a new list of segments that is optimal for the given text at the given version number.
private static List<QrSegment> makeSegmentsOptimally(int[] codePoints, int version) { private static List<QrSegment> makeSegmentsOptimally(int[] codePoints, int version) {
if (codePoints.length == 0) if (codePoints.length == 0)
@ -277,8 +287,7 @@ public final class QrSegmentAdvanced {
*/ */
public static boolean isEncodableAsKanji(String text) { public static boolean isEncodableAsKanji(String text) {
Objects.requireNonNull(text); Objects.requireNonNull(text);
return text.chars().allMatch( return text.chars().allMatch(c -> isKanji((char)c));
c -> isKanji((char)c));
} }

Loading…
Cancel
Save