"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "core/src/main/java/com/google/zxing/oned/rss/expanded/decoders/FieldParser.java" between
zxing-zxing-3.4.1.tar.gz and zxing-zxing-3.5.0.tar.gz

About: ZXing ("zebra crossing") is a multi-format 1D/2D barcode image processing library implemented in Java, with ports to other languages. Info: Project is in maintenance mode (no active development).

FieldParser.java  (zxing-zxing-3.4.1):FieldParser.java  (zxing-zxing-3.5.0)
skipping to change at line 31 skipping to change at line 31
* Mobile Dynamic Environments", led by Treelogic * Mobile Dynamic Environments", led by Treelogic
* ( http://www.treelogic.com/ ): * ( http://www.treelogic.com/ ):
* *
* http://www.piramidepse.com/ * http://www.piramidepse.com/
*/ */
package com.google.zxing.oned.rss.expanded.decoders; package com.google.zxing.oned.rss.expanded.decoders;
import com.google.zxing.NotFoundException; import com.google.zxing.NotFoundException;
import java.util.HashMap;
import java.util.Map;
/** /**
* @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es) * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
* @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.e s) * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.e s)
*/ */
final class FieldParser { final class FieldParser {
private static final Object VARIABLE_LENGTH = new Object(); private static final Map<String,DataLength> TWO_DIGIT_DATA_LENGTH = new HashMa
p<>();
static {
TWO_DIGIT_DATA_LENGTH.put("00", DataLength.fixed(18));
TWO_DIGIT_DATA_LENGTH.put("01", DataLength.fixed(14));
TWO_DIGIT_DATA_LENGTH.put("02", DataLength.fixed(14));
TWO_DIGIT_DATA_LENGTH.put("10", DataLength.variable(20));
TWO_DIGIT_DATA_LENGTH.put("11", DataLength.fixed(6));
TWO_DIGIT_DATA_LENGTH.put("12", DataLength.fixed(6));
TWO_DIGIT_DATA_LENGTH.put("13", DataLength.fixed(6));
TWO_DIGIT_DATA_LENGTH.put("15", DataLength.fixed(6));
TWO_DIGIT_DATA_LENGTH.put("17", DataLength.fixed(6));
TWO_DIGIT_DATA_LENGTH.put("20", DataLength.fixed(2));
TWO_DIGIT_DATA_LENGTH.put("21", DataLength.variable(20));
TWO_DIGIT_DATA_LENGTH.put("22", DataLength.variable(29));
TWO_DIGIT_DATA_LENGTH.put("30", DataLength.variable(8));
TWO_DIGIT_DATA_LENGTH.put("37", DataLength.variable(8));
//internal company codes
for (int i = 90; i <= 99; i++) {
TWO_DIGIT_DATA_LENGTH.put(String.valueOf(i), DataLength.variable(30));
}
}
private static final Object [][] TWO_DIGIT_DATA_LENGTH = { private static final Map<String,DataLength> THREE_DIGIT_DATA_LENGTH = new Hash
// "DIGITS", new Integer(LENGTH) Map<>();
// or static {
// "DIGITS", VARIABLE_LENGTH, new Integer(MAX_SIZE) THREE_DIGIT_DATA_LENGTH.put("240", DataLength.variable(30));
THREE_DIGIT_DATA_LENGTH.put("241", DataLength.variable(30));
{ "00", 18}, THREE_DIGIT_DATA_LENGTH.put("242", DataLength.variable(6));
{ "01", 14}, THREE_DIGIT_DATA_LENGTH.put("250", DataLength.variable(30));
{ "02", 14}, THREE_DIGIT_DATA_LENGTH.put("251", DataLength.variable(30));
THREE_DIGIT_DATA_LENGTH.put("253", DataLength.variable(17));
{ "10", VARIABLE_LENGTH, 20}, THREE_DIGIT_DATA_LENGTH.put("254", DataLength.variable(20));
{ "11", 6}, THREE_DIGIT_DATA_LENGTH.put("400", DataLength.variable(30));
{ "12", 6}, THREE_DIGIT_DATA_LENGTH.put("401", DataLength.variable(30));
{ "13", 6}, THREE_DIGIT_DATA_LENGTH.put("402", DataLength.fixed(17));
{ "15", 6}, THREE_DIGIT_DATA_LENGTH.put("403", DataLength.variable(30));
{ "17", 6}, THREE_DIGIT_DATA_LENGTH.put("410", DataLength.fixed(13));
THREE_DIGIT_DATA_LENGTH.put("411", DataLength.fixed(13));
{ "20", 2}, THREE_DIGIT_DATA_LENGTH.put("412", DataLength.fixed(13));
{ "21", VARIABLE_LENGTH, 20}, THREE_DIGIT_DATA_LENGTH.put("413", DataLength.fixed(13));
{ "22", VARIABLE_LENGTH, 29}, THREE_DIGIT_DATA_LENGTH.put("414", DataLength.fixed(13));
THREE_DIGIT_DATA_LENGTH.put("420", DataLength.variable(20));
THREE_DIGIT_DATA_LENGTH.put("421", DataLength.variable(15));
THREE_DIGIT_DATA_LENGTH.put("422", DataLength.fixed(3));
THREE_DIGIT_DATA_LENGTH.put("423", DataLength.variable(15));
THREE_DIGIT_DATA_LENGTH.put("424", DataLength.fixed(3));
THREE_DIGIT_DATA_LENGTH.put("425", DataLength.fixed(3));
THREE_DIGIT_DATA_LENGTH.put("426", DataLength.fixed(3));
}
{ "30", VARIABLE_LENGTH, 8}, private static final Map<String,DataLength> THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH
{ "37", VARIABLE_LENGTH, 8}, = new HashMap<>();
static {
for (int i = 310; i <= 316; i++) {
THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.put(String.valueOf(i), DataLength.fixed
(6));
}
for (int i = 320; i <= 336; i++) {
THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.put(String.valueOf(i), DataLength.fixed
(6));
}
for (int i = 340; i <= 357; i++) {
THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.put(String.valueOf(i), DataLength.fixed
(6));
}
for (int i = 360; i <= 369; i++) {
THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.put(String.valueOf(i), DataLength.fixed
(6));
}
THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.put("390", DataLength.variable(15));
THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.put("391", DataLength.variable(18));
THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.put("392", DataLength.variable(15));
THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.put("393", DataLength.variable(18));
THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH.put("703", DataLength.variable(30));
}
//internal company codes private static final Map<String,DataLength> FOUR_DIGIT_DATA_LENGTH = new HashM
{ "90", VARIABLE_LENGTH, 30}, ap<>();
{ "91", VARIABLE_LENGTH, 30}, static {
{ "92", VARIABLE_LENGTH, 30}, FOUR_DIGIT_DATA_LENGTH.put("7001", DataLength.fixed(13));
{ "93", VARIABLE_LENGTH, 30}, FOUR_DIGIT_DATA_LENGTH.put("7002", DataLength.variable(30));
{ "94", VARIABLE_LENGTH, 30}, FOUR_DIGIT_DATA_LENGTH.put("7003", DataLength.fixed(10));
{ "95", VARIABLE_LENGTH, 30}, FOUR_DIGIT_DATA_LENGTH.put("8001", DataLength.fixed(14));
{ "96", VARIABLE_LENGTH, 30}, FOUR_DIGIT_DATA_LENGTH.put("8002", DataLength.variable(20));
{ "97", VARIABLE_LENGTH, 30}, FOUR_DIGIT_DATA_LENGTH.put("8003", DataLength.variable(30));
{ "98", VARIABLE_LENGTH, 30}, FOUR_DIGIT_DATA_LENGTH.put("8004", DataLength.variable(30));
{ "99", VARIABLE_LENGTH, 30}, FOUR_DIGIT_DATA_LENGTH.put("8005", DataLength.fixed(6));
}; FOUR_DIGIT_DATA_LENGTH.put("8006", DataLength.fixed(18));
FOUR_DIGIT_DATA_LENGTH.put("8007", DataLength.variable(30));
private static final Object [][] THREE_DIGIT_DATA_LENGTH = { FOUR_DIGIT_DATA_LENGTH.put("8008", DataLength.variable(12));
// Same format as above FOUR_DIGIT_DATA_LENGTH.put("8018", DataLength.fixed(18));
FOUR_DIGIT_DATA_LENGTH.put("8020", DataLength.variable(25));
{ "240", VARIABLE_LENGTH, 30}, FOUR_DIGIT_DATA_LENGTH.put("8100", DataLength.fixed(6));
{ "241", VARIABLE_LENGTH, 30}, FOUR_DIGIT_DATA_LENGTH.put("8101", DataLength.fixed(10));
{ "242", VARIABLE_LENGTH, 6}, FOUR_DIGIT_DATA_LENGTH.put("8102", DataLength.fixed(2));
{ "250", VARIABLE_LENGTH, 30}, FOUR_DIGIT_DATA_LENGTH.put("8110", DataLength.variable(70));
{ "251", VARIABLE_LENGTH, 30}, FOUR_DIGIT_DATA_LENGTH.put("8200", DataLength.variable(70));
{ "253", VARIABLE_LENGTH, 17}, }
{ "254", VARIABLE_LENGTH, 20},
{ "400", VARIABLE_LENGTH, 30},
{ "401", VARIABLE_LENGTH, 30},
{ "402", 17},
{ "403", VARIABLE_LENGTH, 30},
{ "410", 13},
{ "411", 13},
{ "412", 13},
{ "413", 13},
{ "414", 13},
{ "420", VARIABLE_LENGTH, 20},
{ "421", VARIABLE_LENGTH, 15},
{ "422", 3},
{ "423", VARIABLE_LENGTH, 15},
{ "424", 3},
{ "425", 3},
{ "426", 3},
};
private static final Object [][] THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH = {
// Same format as above
{ "310", 6},
{ "311", 6},
{ "312", 6},
{ "313", 6},
{ "314", 6},
{ "315", 6},
{ "316", 6},
{ "320", 6},
{ "321", 6},
{ "322", 6},
{ "323", 6},
{ "324", 6},
{ "325", 6},
{ "326", 6},
{ "327", 6},
{ "328", 6},
{ "329", 6},
{ "330", 6},
{ "331", 6},
{ "332", 6},
{ "333", 6},
{ "334", 6},
{ "335", 6},
{ "336", 6},
{ "340", 6},
{ "341", 6},
{ "342", 6},
{ "343", 6},
{ "344", 6},
{ "345", 6},
{ "346", 6},
{ "347", 6},
{ "348", 6},
{ "349", 6},
{ "350", 6},
{ "351", 6},
{ "352", 6},
{ "353", 6},
{ "354", 6},
{ "355", 6},
{ "356", 6},
{ "357", 6},
{ "360", 6},
{ "361", 6},
{ "362", 6},
{ "363", 6},
{ "364", 6},
{ "365", 6},
{ "366", 6},
{ "367", 6},
{ "368", 6},
{ "369", 6},
{ "390", VARIABLE_LENGTH, 15},
{ "391", VARIABLE_LENGTH, 18},
{ "392", VARIABLE_LENGTH, 15},
{ "393", VARIABLE_LENGTH, 18},
{ "703", VARIABLE_LENGTH, 30},
};
private static final Object [][] FOUR_DIGIT_DATA_LENGTH = {
// Same format as above
{ "7001", 13},
{ "7002", VARIABLE_LENGTH, 30},
{ "7003", 10},
{ "8001", 14},
{ "8002", VARIABLE_LENGTH, 20},
{ "8003", VARIABLE_LENGTH, 30},
{ "8004", VARIABLE_LENGTH, 30},
{ "8005", 6},
{ "8006", 18},
{ "8007", VARIABLE_LENGTH, 30},
{ "8008", VARIABLE_LENGTH, 12},
{ "8018", 18},
{ "8020", VARIABLE_LENGTH, 25},
{ "8100", 6},
{ "8101", 10},
{ "8102", 2},
{ "8110", VARIABLE_LENGTH, 70},
{ "8200", VARIABLE_LENGTH, 70},
};
private FieldParser() { private FieldParser() {
} }
static String parseFieldsInGeneralPurpose(String rawInformation) throws NotFou ndException { static String parseFieldsInGeneralPurpose(String rawInformation) throws NotFou ndException {
if (rawInformation.isEmpty()) { if (rawInformation.isEmpty()) {
return null; return null;
} }
// Processing 2-digit AIs // Processing 2-digit AIs
if (rawInformation.length() < 2) { if (rawInformation.length() < 2) {
throw NotFoundException.getNotFoundInstance(); throw NotFoundException.getNotFoundInstance();
} }
String firstTwoDigits = rawInformation.substring(0, 2); DataLength twoDigitDataLength = TWO_DIGIT_DATA_LENGTH.get(rawInformation.sub
string(0, 2));
for (Object[] dataLength : TWO_DIGIT_DATA_LENGTH) { if (twoDigitDataLength != null) {
if (dataLength[0].equals(firstTwoDigits)) { if (twoDigitDataLength.variable) {
if (dataLength[1] == VARIABLE_LENGTH) { return processVariableAI(2, twoDigitDataLength.length, rawInformation);
return processVariableAI(2, (Integer) dataLength[2], rawInformation);
}
return processFixedAI(2, (Integer) dataLength[1], rawInformation);
} }
return processFixedAI(2, twoDigitDataLength.length, rawInformation);
} }
if (rawInformation.length() < 3) { if (rawInformation.length() < 3) {
throw NotFoundException.getNotFoundInstance(); throw NotFoundException.getNotFoundInstance();
} }
String firstThreeDigits = rawInformation.substring(0, 3); String firstThreeDigits = rawInformation.substring(0, 3);
DataLength threeDigitDataLength = THREE_DIGIT_DATA_LENGTH.get(firstThreeDigi
for (Object[] dataLength : THREE_DIGIT_DATA_LENGTH) { ts);
if (dataLength[0].equals(firstThreeDigits)) { if (threeDigitDataLength != null) {
if (dataLength[1] == VARIABLE_LENGTH) { if (threeDigitDataLength.variable) {
return processVariableAI(3, (Integer) dataLength[2], rawInformation); return processVariableAI(3, threeDigitDataLength.length, rawInformation)
} ;
return processFixedAI(3, (Integer) dataLength[1], rawInformation);
}
}
for (Object[] dataLength : THREE_DIGIT_PLUS_DIGIT_DATA_LENGTH) {
if (dataLength[0].equals(firstThreeDigits)) {
if (dataLength[1] == VARIABLE_LENGTH) {
return processVariableAI(4, (Integer) dataLength[2], rawInformation);
}
return processFixedAI(4, (Integer) dataLength[1], rawInformation);
} }
return processFixedAI(3, threeDigitDataLength.length, rawInformation);
} }
if (rawInformation.length() < 4) { if (rawInformation.length() < 4) {
throw NotFoundException.getNotFoundInstance(); throw NotFoundException.getNotFoundInstance();
} }
String firstFourDigits = rawInformation.substring(0, 4); DataLength threeDigitPlusDigitDataLength = THREE_DIGIT_PLUS_DIGIT_DATA_LENGT
H.get(firstThreeDigits);
if (threeDigitPlusDigitDataLength != null) {
if (threeDigitPlusDigitDataLength.variable) {
return processVariableAI(4, threeDigitPlusDigitDataLength.length, rawInf
ormation);
}
return processFixedAI(4, threeDigitPlusDigitDataLength.length, rawInformat
ion);
}
for (Object[] dataLength : FOUR_DIGIT_DATA_LENGTH) { DataLength firstFourDigitLength = FOUR_DIGIT_DATA_LENGTH.get(rawInformation.
if (dataLength[0].equals(firstFourDigits)) { substring(0, 4));
if (dataLength[1] == VARIABLE_LENGTH) { if (firstFourDigitLength != null) {
return processVariableAI(4, (Integer) dataLength[2], rawInformation); if (firstFourDigitLength.variable) {
} return processVariableAI(4, firstFourDigitLength.length, rawInformation)
return processFixedAI(4, (Integer) dataLength[1], rawInformation); ;
} }
return processFixedAI(4, firstFourDigitLength.length, rawInformation);
} }
throw NotFoundException.getNotFoundInstance(); throw NotFoundException.getNotFoundInstance();
} }
private static String processFixedAI(int aiSize, int fieldSize, String rawInfo rmation) throws NotFoundException { private static String processFixedAI(int aiSize, int fieldSize, String rawInfo rmation) throws NotFoundException {
if (rawInformation.length() < aiSize) { if (rawInformation.length() < aiSize) {
throw NotFoundException.getNotFoundInstance(); throw NotFoundException.getNotFoundInstance();
} }
skipping to change at line 285 skipping to change at line 218
private static String processVariableAI(int aiSize, int variableFieldSize, Str ing rawInformation) private static String processVariableAI(int aiSize, int variableFieldSize, Str ing rawInformation)
throws NotFoundException { throws NotFoundException {
String ai = rawInformation.substring(0, aiSize); String ai = rawInformation.substring(0, aiSize);
int maxSize = Math.min(rawInformation.length(), aiSize + variableFieldSize); int maxSize = Math.min(rawInformation.length(), aiSize + variableFieldSize);
String field = rawInformation.substring(aiSize, maxSize); String field = rawInformation.substring(aiSize, maxSize);
String remaining = rawInformation.substring(maxSize); String remaining = rawInformation.substring(maxSize);
String result = '(' + ai + ')' + field; String result = '(' + ai + ')' + field;
String parsedAI = parseFieldsInGeneralPurpose(remaining); String parsedAI = parseFieldsInGeneralPurpose(remaining);
return parsedAI == null ? result : result + parsedAI; return parsedAI == null ? result : result + parsedAI;
} }
private static final class DataLength {
final boolean variable;
final int length;
private DataLength(boolean variable, int length) {
this.variable = variable;
this.length = length;
}
static DataLength fixed(int length) {
return new DataLength(false, length);
}
static DataLength variable(int length) {
return new DataLength(true, length);
}
}
} }
 End of changes. 13 change blocks. 
180 lines changed or deleted 150 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)