Skip to content

Commit d3ee83c

Browse files
committed
fix few more issues for Qodana
1 parent d05ae95 commit d3ee83c

File tree

8 files changed

+70
-87
lines changed

8 files changed

+70
-87
lines changed

barcode4j/src/main/java/org/krysalis/barcode4j/impl/code128/EAN128Bean.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class EAN128Bean extends Code128Bean {
4141

4242
private ChecksumMode checksumMode = ChecksumMode.CP_AUTO;
4343
private String template = null;
44-
private char groupSeparator = DEFAULT_GROUP_SEPARATOR; //GroupSeperator not Code128LogicImpl.FNC_1;
44+
private char groupSeparator = DEFAULT_GROUP_SEPARATOR;
4545
private char checkDigitMarker = DEFAULT_CHECK_DIGIT_MARKER;
4646
private boolean omitBrackets = false;
4747

barcode4j/src/main/java/org/krysalis/barcode4j/impl/code128/EAN128LogicImpl.java

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,17 @@
2929
*
3030
* @author Dietmar Bürkle, Jeremias Maerki (generateBarcodeLogic)
3131
*/
32-
public class EAN128LogicImpl { //extends Code128LogicImpl{
32+
public class EAN128LogicImpl {
3333
private static final byte MAX_LENGTH = 48; // Max according to EAN128 specification.
3434

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;
3838

3939

4040
private EAN128AI[] ais = null;
4141

42-
//GroupSeparator not Code128LogicImpl.FNC_1;
43-
private char groupSeparator = EAN128Bean.DEFAULT_GROUP_SEPARATOR;
42+
private char groupSeparator;
4443

4544
private char checkDigitMarker = EAN128Bean.DEFAULT_CHECK_DIGIT_MARKER;
4645
private boolean omitBrackets = false;
@@ -54,15 +53,14 @@ public class EAN128LogicImpl { //extends Code128LogicImpl{
5453
private boolean checksumADD = true;
5554
private boolean checksumCHECK = true;
5655

57-
public EAN128LogicImpl(ChecksumMode mode, String template, char fnc1) {
56+
public EAN128LogicImpl(ChecksumMode mode, String template, char groupSeparator) {
5857
setChecksumMode(mode);
5958
setTemplate(template);
60-
this.groupSeparator = fnc1;
59+
this.groupSeparator = groupSeparator;
6160
}
6261

6362
public EAN128LogicImpl(ChecksumMode mode, String template) {
64-
setChecksumMode(mode);
65-
setTemplate(template);
63+
this(mode, template, EAN128Bean.DEFAULT_GROUP_SEPARATOR);
6664
}
6765

6866
protected void setMessage(@Nullable String msg) {
@@ -117,8 +115,8 @@ public void generateBarcodeLogic(ClassicBarcodeLogicHandler logic, String msg) {
117115

118116
final Code128LogicImpl c128 = new Code128LogicImpl();
119117
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);
122120
}
123121

124122
//Calculate checksum
@@ -283,22 +281,20 @@ private boolean isGroupSeparator(char ch) {
283281
private void checkType(@NotNull EAN128AI ai, byte idx, @NotNull String msg, int start, int end, int cdStart) {
284282
byte type = ai.type[idx];
285283
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() + ")");
289285
} else if (type == EAN128AI.TYPEAlpha) {
290286
for (int i = end - 1; i >= start; i--) {
291287
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!",
294290
msg.substring(start, i));
295291
}
296292
}
297293
} else if (type == EAN128AI.TYPEAlphaNum) {
298294
for (int i = end - 1; i >= start; i--) {
299295
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!",
302298
msg.substring(start, i));
303299
}
304300
}
@@ -310,16 +306,16 @@ private void checkType(@NotNull EAN128AI ai, byte idx, @NotNull String msg, int
310306
cd2 = cd1;
311307
}
312308
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 + "!");
314310
}
315311
humanReadableMsg.append(cd1);
316312
code128Msg.append(cd1);
317313
return;
318314
}
319315
for (int i = end - 1; i >= start; i--) {
320316
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!",
323319
msg.substring(start, i));
324320
}
325321
}
@@ -363,7 +359,7 @@ private IllegalArgumentException getException(String text, @Nullable String msgO
363359
if (msgOk == null) {
364360
msgOk = "";
365361
}
366-
if (humanReadableMsg.length() > 1 || msgOk.length() > 0) {
362+
if (humanReadableMsg.length() > 1 || !msgOk.isEmpty()) {
367363
text = text + " Accepted start of Message: \""
368364
+ humanReadableMsg.toString() + msgOk + "\"";
369365
}

barcode4j/src/main/java/org/krysalis/barcode4j/impl/int2of5/Interleaved2Of5LogicImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ public static boolean validateChecksum(String msg) {
110110
private int widthAt(char ch, int index) {
111111
if (Character.isDigit(ch)) {
112112
int digit = Character.digit(ch, 10);
113-
int width = CHARSET[digit][index];
114-
return width;
113+
return CHARSET[digit][index];
115114
} else {
116115
throw new IllegalArgumentException("Invalid character '" + ch
117116
+ " (" + Character.getNumericValue(ch)
@@ -226,4 +225,4 @@ public void generateBarcodeLogic(ClassicBarcodeLogicHandler logic, String msg) {
226225
logic.endBarcode();
227226
}
228227

229-
}
228+
}

barcode4j/src/main/java/org/krysalis/barcode4j/impl/pdf417/PDF417LogicImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,16 @@ public static void generateBarcodeLogic(TwoDimBarcodeLogicHandler logic,
216216
+ msg.length() + " bytes)");
217217
}
218218

219-
StringBuffer sb = new StringBuffer(n);
219+
final StringBuilder sb = new StringBuilder(n);
220220
sb.append((char)n);
221221
sb.append(highLevel);
222222
for (int i = 0; i < pad; i++) {
223223
sb.append((char)900); //PAD characters
224224
}
225-
String dataCodewords = sb.toString();
225+
final String dataCodewords = sb.toString();
226226

227227
//3. step: Error correction
228-
String ec = PDF417ErrorCorrection.generateErrorCorrection(
229-
dataCodewords, errorCorrectionLevel);
228+
final String ec = PDF417ErrorCorrection.generateErrorCorrection(dataCodewords, errorCorrectionLevel);
230229
String fullCodewords = dataCodewords + ec;
231230

232231
//4. step: low-level encoding

barcode4j/src/main/java/org/krysalis/barcode4j/impl/postnet/POSTNETLogicImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static boolean isIgnoredChar(char c) {
114114
* @return the message but without ignored characters
115115
*/
116116
public static String removeIgnoredCharacters(final String msg) {
117-
StringBuffer sb = new StringBuffer(msg.length());
117+
final StringBuilder sb = new StringBuilder(msg.length());
118118
for (int i = 0; i < msg.length(); i++) {
119119
final char ch = msg.charAt(i);
120120
if (!isValidChar(ch)) {
@@ -130,8 +130,7 @@ public static String removeIgnoredCharacters(final String msg) {
130130
private int heightAt(char ch, int index) {
131131
int chidx = Character.digit(ch, 10);
132132
if (chidx >= 0) {
133-
int height = CHARSET[chidx][index];
134-
return height;
133+
return CHARSET[chidx][index];
135134
} else {
136135
throw new IllegalArgumentException("Invalid character: " + ch);
137136
}

0 commit comments

Comments
 (0)