Simplified some logic in Java QrSegmentAdvanced using Java SE 8 streams and lambdas.
This commit is contained in:
parent
18ff8dc0e5
commit
46b6425838
|
@ -234,12 +234,12 @@ public final class QrSegmentAdvanced {
|
||||||
public static QrSegment makeKanji(String text) {
|
public static QrSegment makeKanji(String text) {
|
||||||
Objects.requireNonNull(text);
|
Objects.requireNonNull(text);
|
||||||
BitBuffer bb = new BitBuffer();
|
BitBuffer bb = new BitBuffer();
|
||||||
for (int i = 0; i < text.length(); i++) {
|
text.chars().forEachOrdered(c -> {
|
||||||
int val = UNICODE_TO_QR_KANJI[text.charAt(i)];
|
int val = UNICODE_TO_QR_KANJI[c];
|
||||||
if (val == -1)
|
if (val == -1)
|
||||||
throw new IllegalArgumentException("String contains non-kanji-mode characters");
|
throw new IllegalArgumentException("String contains non-kanji-mode characters");
|
||||||
bb.appendBits(val, 13);
|
bb.appendBits(val, 13);
|
||||||
}
|
});
|
||||||
return new QrSegment(Mode.KANJI, text.length(), bb);
|
return new QrSegment(Mode.KANJI, text.length(), bb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,11 +256,8 @@ public final class QrSegmentAdvanced {
|
||||||
*/
|
*/
|
||||||
public static boolean isEncodableAsKanji(String text) {
|
public static boolean isEncodableAsKanji(String text) {
|
||||||
Objects.requireNonNull(text);
|
Objects.requireNonNull(text);
|
||||||
for (int i = 0; i < text.length(); i++) {
|
return text.chars().allMatch(
|
||||||
if (!isKanji(text.charAt(i)))
|
c -> isKanji((char)c));
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue