1. Extract Method, introduce explain value

2. QrSegmenetAdvanced.java
3. THis class had many function. So, declare more method.
pull/90/head
minsu4107 5 years ago
parent ce24efed3c
commit 750c8ba7ae

@ -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

Loading…
Cancel
Save