Skip to content

Commit

Permalink
fix some more code issues
Browse files Browse the repository at this point in the history
  • Loading branch information
SingingBush committed Jul 19, 2024
1 parent aad175e commit f488f18
Show file tree
Hide file tree
Showing 12 changed files with 178 additions and 180 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ jobs:
ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit
fetch-depth: 0 # a full history is required for pull request analysis

- name: Set up JDK 17
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
java-version: 11
cache: maven

- name: Setup Cache for SonarCloud packages
Expand All @@ -110,23 +110,21 @@ jobs:
restore-keys: ${{ runner.os }}-sonar

## todo: use same artifacts from the build job
- name: Maven Install
run: mvn -B install jacoco:report

## Automatic Analysis is turned off on sonarcloud.io
- name: Maven Sonar
run: mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
- name: Maven JaCoCo report & Sonar
run: mvn -B install jacoco:report org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- name: Copy aggregate JaCoCo Report (for Qodana)
shell: bash
run: |
ls -lha aggregate-report/target/site/jacoco-aggregate/
mkdir -p .qodana/code-coverage/
cp -r aggregate-report/target/site/jacoco-aggregate/* .qodana/code-coverage/
# potentially Qodana could be it's own workflow (recommended in the docs)
# potentially Qodana could be its own workflow (recommended in the docs)
- name: Qodana Scan
uses: JetBrains/[email protected]
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private int widthAt(char ch, int index) throws IllegalArgumentException {
*/
protected void encodeChar(ClassicBarcodeLogicHandler logic, char ch) {
ch = Character.toLowerCase(ch);
logic.startBarGroup(BarGroup.MSG_CHARACTER, new Character(ch).toString());
logic.startBarGroup(BarGroup.MSG_CHARACTER, String.valueOf(ch));
for (byte i = 0; i < 7; i++) {
final int width = widthAt(ch, i);
final boolean black = ((i % 2) == 0);
Expand All @@ -155,10 +155,8 @@ protected void encodeChar(ClassicBarcodeLogicHandler logic, char ch) {
}

private void handleChecksum(StringBuffer sb) {
if ((getChecksumMode() == ChecksumMode.CP_ADD)
|| (getChecksumMode() == ChecksumMode.CP_CHECK)) {
throw new UnsupportedOperationException(
"No checksums are currently supported for Codabar symbols");
if ((getChecksumMode() == ChecksumMode.CP_ADD) || (getChecksumMode() == ChecksumMode.CP_CHECK)) {
throw new UnsupportedOperationException("No checksums are currently supported for Codabar symbols");
} else if (getChecksumMode() == ChecksumMode.CP_IGNORE) {
return;
} else if (getChecksumMode() == ChecksumMode.CP_AUTO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private int widthAt(char ch, int index) {
* @param c the character to encode
*/
protected void encodeChar(ClassicBarcodeLogicHandler logic, char c) {
logic.startBarGroup(BarGroup.MSG_CHARACTER, new Character(c).toString());
logic.startBarGroup(BarGroup.MSG_CHARACTER, String.valueOf(c));
for (byte i = 0; i < 9; i++) {
int width = widthAt(c, i);
boolean black = (i % 2 == 0);
Expand Down Expand Up @@ -327,7 +327,7 @@ public void generateBarcodeLogic(ClassicBarcodeLogicHandler logic, String msg) {
logic.startBarcode(sb.toString(), displayMsg);

//Start character
logic.startBarGroup(BarGroup.START_CHARACTER, new Character(STARTSTOP).toString());
logic.startBarGroup(BarGroup.START_CHARACTER, String.valueOf(STARTSTOP));
encodeChar(logic, STARTSTOP);
logic.endBarGroup();

Expand All @@ -344,7 +344,7 @@ public void generateBarcodeLogic(ClassicBarcodeLogicHandler logic, String msg) {
addIntercharacterGap(logic);

//Start character
logic.startBarGroup(BarGroup.STOP_CHARACTER, new Character(STARTSTOP).toString());
logic.startBarGroup(BarGroup.STOP_CHARACTER, String.valueOf(STARTSTOP));
encodeChar(logic, STARTSTOP);
logic.endBarGroup();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 2006 Jeremias Maerki.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -21,7 +21,7 @@

/**
* Provides a base class for "four-state" barcodes.
*
*
* @author Jeremias Maerki
* @version $Id: AbstractFourStateLogicImpl.java,v 1.2 2008-05-13 13:00:43 jmaerki Exp $
*/
Expand All @@ -47,7 +47,7 @@ public ChecksumMode getChecksumMode() {
}

/**
* Calculates the checksum for a message to be encoded as an
* Calculates the checksum for a message to be encoded as an
* one of the foru-state barcode symbologies.
* @param msg message to calculate the check digit for
* @return char the check digit
Expand All @@ -70,34 +70,36 @@ public boolean validateChecksum(String msg) {
* Checks if a character is an ignored character (such as a '-' (dash)).
* @param c character to check
* @return True if the character is ignored
* @deprecated for removal as there's no need for this method
*/
@Deprecated
public static boolean isIgnoredChar(char c) {
return false;
}

/**
* Turns the given message into a normalize representation. Some subclasses may update/add
* parentheses around the message and/or handle the checksum as necessary.
* @param msg the message
* @return the normalized message to be encoded
*/
protected abstract String normalizeMessage(String msg);

/**
* Does the high-level encoding of the message into codewords.
* @param msg the message
* @return an array of Strings with codewords
*/
protected abstract String[] encodeHighLevel(String msg);

/**
* Encodes a single character.
* @param logic the logic handler to receive generated events
* @param c the character to encode
* @param codeword the codeword belonging to the character
*/
protected void encodeCodeword(ClassicBarcodeLogicHandler logic, char c, String codeword) {
logic.startBarGroup(BarGroup.MSG_CHARACTER, new Character(c).toString());
logic.startBarGroup(BarGroup.MSG_CHARACTER, String.valueOf(c));
for (int i = 0, count = codeword.length(); i < count; i++) {
int height = Integer.parseInt(codeword.substring(i, i + 1));
logic.addBar(true, height);
Expand All @@ -115,7 +117,7 @@ public void generateBarcodeLogic(ClassicBarcodeLogicHandler logic, String msg) {
String[] encodedMsg = encodeHighLevel(normalizedMsg);

logic.startBarcode(msg, normalizedMsg);

// encode message
for (int i = 0; i < encodedMsg.length; i++) {
final char ch = normalizedMsg.charAt(i);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 2003,2004 Jeremias Maerki.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -21,13 +21,13 @@

/**
* Implements the United States Postal Service Postnet barcode.
*
*
* @author Chris Dolphy
* @version $Id: POSTNETLogicImpl.java,v 1.3 2006-11-07 16:42:17 jmaerki Exp $
*/
public class POSTNETLogicImpl {

private static final byte[][] CHARSET =
private static final byte[][] CHARSET =
{{2, 2, 1, 1, 1}, //0
{1, 1, 1, 2, 2}, //1
{1, 1, 2, 1, 2}, //2
Expand Down Expand Up @@ -64,7 +64,7 @@ public ChecksumMode getChecksumMode() {
}

/**
* Calculates the checksum for a message to be encoded as an
* Calculates the checksum for a message to be encoded as an
* POSTNET barcode.
* @param msg message to calculate the check digit for
* @return char the check digit
Expand Down Expand Up @@ -98,7 +98,7 @@ public static boolean validateChecksum(String msg) {
private static boolean isValidChar(char ch) {
return Character.isDigit(ch) || isIgnoredChar(ch);
}

/**
* Checks if a character is an ignored character (such as a '-' (dash)).
* @param c character to check
Expand All @@ -107,7 +107,7 @@ private static boolean isValidChar(char ch) {
public static boolean isIgnoredChar(char c) {
return c == DASH;
}

/**
* Removes ignored character from a valid POSTNET message.
* @param msg valid POSTNET message
Expand Down Expand Up @@ -146,7 +146,7 @@ protected void encodeChar(ClassicBarcodeLogicHandler logic, char c) {
if (isIgnoredChar(c)) {
return; // allow dash, but don't encode
}
logic.startBarGroup(BarGroup.MSG_CHARACTER, new Character(c).toString());
logic.startBarGroup(BarGroup.MSG_CHARACTER, String.valueOf(c));
for (byte i = 0; i < 5; i++) {
int height = heightAt(c, i);
logic.addBar(true, height);
Expand All @@ -158,7 +158,7 @@ protected void encodeChar(ClassicBarcodeLogicHandler logic, char c) {
private void addIntercharacterGap(ClassicBarcodeLogicHandler logic) {
logic.addBar(false, -1); //-1 is special
}

private String handleChecksum(StringBuffer sb) {
if (getChecksumMode() == ChecksumMode.CP_ADD) {
if (displayChecksum) {
Expand All @@ -171,9 +171,9 @@ private String handleChecksum(StringBuffer sb) {
}
} else if (getChecksumMode() == ChecksumMode.CP_CHECK) {
if (!validateChecksum(sb.toString())) {
throw new IllegalArgumentException("Message '"
throw new IllegalArgumentException("Message '"
+ sb.toString()
+ "' has a bad checksum. Expected: "
+ "' has a bad checksum. Expected: "
+ calcChecksum(sb.substring(0, sb.length() - 1)));
}
if (displayChecksum) {
Expand Down Expand Up @@ -201,7 +201,7 @@ public void generateBarcodeLogic(ClassicBarcodeLogicHandler logic, String msg) {
String formattedMsg = handleChecksum(sb);

logic.startBarcode(sb.toString(), formattedMsg);

// start frame bar
logic.addBar(true, 2);
addIntercharacterGap(logic);
Expand All @@ -211,7 +211,7 @@ public void generateBarcodeLogic(ClassicBarcodeLogicHandler logic, String msg) {
final char ch = sb.charAt(i);
if (!isValidChar(ch)) {
throw new IllegalArgumentException("Invalid character: " + ch);
}
}
encodeChar(logic, ch);
}

Expand All @@ -221,5 +221,4 @@ public void generateBarcodeLogic(ClassicBarcodeLogicHandler logic, String msg) {
logic.endBarcode();
}


}
Loading

0 comments on commit f488f18

Please sign in to comment.