29
29
*
30
30
* @author Dietmar Bürkle, Jeremias Maerki (generateBarcodeLogic)
31
31
*/
32
- public class EAN128LogicImpl { //extends Code128LogicImpl{
32
+ public class EAN128LogicImpl {
33
33
private static final byte MAX_LENGTH = 48 ; // Max according to EAN128 specification.
34
34
35
- private static final byte TYPENumTestCheckDigit = 4 ;
36
- private static final byte TYPENumReplaceCheckDigit = 5 ;
37
- private static final byte TYPENumAddCheckDigit = 6 ;
35
+ // private static final byte TYPENumTestCheckDigit = 4;
36
+ // private static final byte TYPENumReplaceCheckDigit = 5;
37
+ // private static final byte TYPENumAddCheckDigit = 6;
38
38
39
39
40
40
private EAN128AI [] ais = null ;
41
41
42
- //GroupSeparator not Code128LogicImpl.FNC_1;
43
- private char groupSeparator = EAN128Bean .DEFAULT_GROUP_SEPARATOR ;
42
+ private char groupSeparator ;
44
43
45
44
private char checkDigitMarker = EAN128Bean .DEFAULT_CHECK_DIGIT_MARKER ;
46
45
private boolean omitBrackets = false ;
@@ -54,15 +53,14 @@ public class EAN128LogicImpl { //extends Code128LogicImpl{
54
53
private boolean checksumADD = true ;
55
54
private boolean checksumCHECK = true ;
56
55
57
- public EAN128LogicImpl (ChecksumMode mode , String template , char fnc1 ) {
56
+ public EAN128LogicImpl (ChecksumMode mode , String template , char groupSeparator ) {
58
57
setChecksumMode (mode );
59
58
setTemplate (template );
60
- this .groupSeparator = fnc1 ;
59
+ this .groupSeparator = groupSeparator ;
61
60
}
62
61
63
62
public EAN128LogicImpl (ChecksumMode mode , String template ) {
64
- setChecksumMode (mode );
65
- setTemplate (template );
63
+ this (mode , template , EAN128Bean .DEFAULT_GROUP_SEPARATOR );
66
64
}
67
65
68
66
protected void setMessage (@ Nullable String msg ) {
@@ -117,8 +115,8 @@ public void generateBarcodeLogic(ClassicBarcodeLogicHandler logic, String msg) {
117
115
118
116
final Code128LogicImpl c128 = new Code128LogicImpl ();
119
117
logic .startBarcode (msg , getHumanReadableMsg ());
120
- for (int i = 0 ; i < encodedMsg . length ; i ++ ) {
121
- c128 .encodeChar (logic , encodedMsg [ i ] );
118
+ for (int i : encodedMsg ) {
119
+ c128 .encodeChar (logic , i );
122
120
}
123
121
124
122
//Calculate checksum
@@ -283,22 +281,20 @@ private boolean isGroupSeparator(char ch) {
283
281
private void checkType (@ NotNull EAN128AI ai , byte idx , @ NotNull String msg , int start , int end , int cdStart ) {
284
282
byte type = ai .type [idx ];
285
283
if (type == EAN128AI .TYPEError ) {
286
- throw getException ("This AI is not allowed by configuration! ("
287
- + ai .toString () + ")" );
288
-
284
+ throw getException ("This AI is not allowed by configuration! (" + ai .toString () + ")" );
289
285
} else if (type == EAN128AI .TYPEAlpha ) {
290
286
for (int i = end - 1 ; i >= start ; i --) {
291
287
if (msg .charAt (i ) > 128 || Character .isDigit (msg .charAt (i ))) {
292
- throw getException ("Character \ ' " + msg .charAt (i )
293
- + "\ ' must be a valid ASCII byte but not number!" ,
288
+ throw getException ("Character '" + msg .charAt (i )
289
+ + "' must be a valid ASCII byte but not number!" ,
294
290
msg .substring (start , i ));
295
291
}
296
292
}
297
293
} else if (type == EAN128AI .TYPEAlphaNum ) {
298
294
for (int i = end - 1 ; i >= start ; i --) {
299
295
if (msg .charAt (i ) > 128 ) {
300
- throw getException ("Character \ ' " + msg .charAt (i )
301
- + "\ ' must be a valid ASCII byte!" ,
296
+ throw getException ("Character '" + msg .charAt (i )
297
+ + "' must be a valid ASCII byte!" ,
302
298
msg .substring (start , i ));
303
299
}
304
300
}
@@ -310,16 +306,16 @@ private void checkType(@NotNull EAN128AI ai, byte idx, @NotNull String msg, int
310
306
cd2 = cd1 ;
311
307
}
312
308
if (cd1 != cd2 ) {
313
- throw getException ("Checkdigit is wrong! Correct is " + cd1 + " but I found " + cd2 + "!" );
309
+ throw getException ("Check digit is wrong! Correct is " + cd1 + " but I found " + cd2 + "!" );
314
310
}
315
311
humanReadableMsg .append (cd1 );
316
312
code128Msg .append (cd1 );
317
313
return ;
318
314
}
319
315
for (int i = end - 1 ; i >= start ; i --) {
320
316
if (!Character .isDigit (msg .charAt (i ))) {
321
- throw getException ("Character \ ' " + msg .charAt (i )
322
- + "\ ' must be a Digit!" ,
317
+ throw getException ("Character '" + msg .charAt (i )
318
+ + "' must be a Digit!" ,
323
319
msg .substring (start , i ));
324
320
}
325
321
}
@@ -363,7 +359,7 @@ private IllegalArgumentException getException(String text, @Nullable String msgO
363
359
if (msgOk == null ) {
364
360
msgOk = "" ;
365
361
}
366
- if (humanReadableMsg .length () > 1 || msgOk .length () > 0 ) {
362
+ if (humanReadableMsg .length () > 1 || ! msgOk .isEmpty () ) {
367
363
text = text + " Accepted start of Message: \" "
368
364
+ humanReadableMsg .toString () + msgOk + "\" " ;
369
365
}
0 commit comments