Skip to content

Commit

Permalink
Let the IDE do its trivial cleanups without any other changes, to red…
Browse files Browse the repository at this point in the history
…uce the noise in future commits (except in DataMatrix).

 - Remove unused imports
 - Add missing @OverRide annotations
 - Remove unnecessary casts
 - Remove trailing whitespace
  • Loading branch information
gredler committed Mar 13, 2015
1 parent ff3727b commit 224a97f
Show file tree
Hide file tree
Showing 54 changed files with 1,962 additions and 1,904 deletions.
5 changes: 3 additions & 2 deletions src/main/java/uk/org/okapibarcode/OkapiBarcode.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

package uk.org.okapibarcode;

import uk.org.okapibarcode.gui.*;
import uk.org.okapibarcode.gui.OkapiUI;

/**
*
* @author Robin Stuart <rstuart114@gmail.com>
Expand All @@ -16,5 +17,5 @@ public static void main(String[] args) {
OkapiUI okapiUi = new OkapiUI();
okapiUi.setVisible(true);
}

}
30 changes: 15 additions & 15 deletions src/main/java/uk/org/okapibarcode/backend/AddOn.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,46 @@
public class AddOn{
private String content;
private String dest;

private String[] EANsetA = {
"3211", "2221", "2122", "1411", "1132", "1231", "1114", "1312", "1213",
"3211", "2221", "2122", "1411", "1132", "1231", "1114", "1312", "1213",
"3112"
};
private String[] EANsetB = {
"1123", "1222", "2212", "1141", "2311", "1321", "4111", "2131", "3121",
"1123", "1222", "2212", "1141", "2311", "1321", "4111", "2131", "3121",
"2113"
};

private String[] EAN2Parity = {
"AA", "AB", "BA", "BB"
};
private String[] EAN5Parity = {
"BBAAA", "BABAA", "BAABA", "BAAAB", "ABBAA", "AABBA", "AAABB", "ABABA",
"BBAAA", "BABAA", "BAABA", "BAAAB", "ABBAA", "AABBA", "AAABB", "ABABA",
"ABAAB", "AABAB"
};

public String calcAddOn(String input) {
dest = "";
content = input;

if (!(content.matches("[0-9]{1,5}"))) {
return "";
}

if (content.length() > 2) {
ean5();
} else {
ean2();
}

return dest;
}

private void ean2() {
String parity;
String accumulator = "";
int i, code_value;

if (!(content.matches("[0-9]+?"))) {
return;
}
Expand All @@ -73,8 +73,8 @@ private void ean2() {
}
accumulator += content;

code_value = (int)(((accumulator.charAt(0) - '0') * 10)
+ (accumulator.charAt(1) - '0'));
code_value = ((accumulator.charAt(0) - '0') * 10)
+ (accumulator.charAt(1) - '0');
parity = EAN2Parity[code_value % 4];

dest = "112"; /* Start */
Expand All @@ -94,7 +94,7 @@ private void ean5() {
String parity;
String accumulator = "";
int i, parity_sum;

if (!(content.matches("[0-9]+?"))) {
return;
}
Expand All @@ -107,9 +107,9 @@ private void ean5() {
parity_sum = 0;
for (i = 0; i < 5; i++) {
if ((i % 2) == 0) {
parity_sum += 3 * (int)(accumulator.charAt(i) - '0');
parity_sum += 3 * (accumulator.charAt(i) - '0');
} else {
parity_sum += 9 * (int)(accumulator.charAt(i) - '0');
parity_sum += 9 * (accumulator.charAt(i) - '0');
}
}

Expand Down
72 changes: 36 additions & 36 deletions src/main/java/uk/org/okapibarcode/backend/AustraliaPost.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,39 @@ public class AustraliaPost extends Symbol{
"210", "211", "212", "213", "220", "221", "222", "223", "230", "231", "232", "233", "300",
"301", "302", "303", "310", "311", "312", "313", "320", "321", "322", "323", "330", "331",
"332", "333"};

private enum ausMode {AUSPOST, AUSREPLY, AUSROUTE, AUSREDIRECT};

private ausMode mode;

public AustraliaPost() {
mode = ausMode.AUSPOST;
}

public void setPostMode() {
mode = ausMode.AUSPOST;
}

public void setReplyMode() {
mode = ausMode.AUSREPLY;
}

public void setRouteMode() {
mode = ausMode.AUSROUTE;
}

public void setRedirectMode() {
mode = ausMode.AUSREDIRECT;
}

@Override
public boolean encode() {
String formatControlCode = "00";
String deliveryPointId;
String barStateValues;
String zeroPaddedInput = "";
int i;

switch(mode) {
case AUSPOST:
switch(content.length()) {
Expand All @@ -97,7 +97,7 @@ public boolean encode() {
if (!(content.matches("[0-9]+?"))) {
error_msg = "Invalid characters in data";
return false;
}
}
break;
default: error_msg = "Auspost input is wrong length";
return false;
Expand Down Expand Up @@ -126,46 +126,46 @@ public boolean encode() {
} else {
formatControlCode = "92";
}
break;
break;
}

encodeInfo += "FCC: " + formatControlCode + '\n';

if(mode != ausMode.AUSPOST) {
for (i = content.length(); i < 8; i++) {
zeroPaddedInput += "0";
}
}
zeroPaddedInput += content;

if (!(content.matches("[0-9A-Za-z #]+?"))) {
error_msg = "Invalid characters in data";
return false;
}

/* Verify that the first 8 characters are numbers */
deliveryPointId = zeroPaddedInput.substring(0, 8);

if (!(deliveryPointId.matches("[0-9]+?"))) {
error_msg = "Invalid characters in DPID";
return false;
}

encodeInfo += "DPID: " + deliveryPointId + '\n';

/* Start */
barStateValues = "13";

/* Encode the FCC */
for(i = 0; i < 2; i++) {
barStateValues += nEncodingTable[formatControlCode.charAt(i) - '0'];
}

/* Delivery Point Identifier (DPID) */
for(i = 0; i < 8; i++) {
barStateValues += nEncodingTable[deliveryPointId.charAt(i) - '0'];
}

/* Customer Information */
switch(zeroPaddedInput.length()) {
case 13:
Expand All @@ -181,7 +181,7 @@ public boolean encode() {
}
break;
}

/* Filler bar */
switch(barStateValues.length()) {
case 22:
Expand All @@ -190,15 +190,15 @@ public boolean encode() {
barStateValues += "3";
break;
}

/* Reed Solomon error correction */
barStateValues += calcReedSolomon(barStateValues);

/* Stop character */
barStateValues += "13";

encodeInfo += "Total length: " + barStateValues.length() + '\n';

readable = "";
pattern = new String[1];
pattern[0] = barStateValues;
Expand All @@ -208,43 +208,43 @@ public boolean encode() {
plotSymbol();
return true;
}

private String calcReedSolomon(String oldBarStateValues) {
ReedSolomon rs = new ReedSolomon();
String newBarStateValues = "";

/* Adds Reed-Solomon error correction to auspost */

int barStateCount;
int tripleValueCount = 0;
int[] tripleValue = new int[31];

for(barStateCount = 2; barStateCount < oldBarStateValues.length(); barStateCount += 3, tripleValueCount++) {
tripleValue[tripleValueCount] = barStateToDecimal(oldBarStateValues.charAt(barStateCount), 4)
+ barStateToDecimal(oldBarStateValues.charAt(barStateCount + 1), 2)
+ barStateToDecimal(oldBarStateValues.charAt(barStateCount + 2), 0);
}

rs.init_gf(0x43);
rs.init_code(4, 1);
rs.encode(tripleValueCount, tripleValue);

for(barStateCount = 4; barStateCount > 0; barStateCount--) {
newBarStateValues += barValueTable[rs.getResult(barStateCount - 1)];
}

return newBarStateValues;
}

private int barStateToDecimal (char oldBarStateValues, int shift) {
return (oldBarStateValues - '0') << shift;
}

@Override
public void plotSymbol() {
int xBlock;
int x, y, w, h;

rect.clear();
x = 0;
w = 1;
Expand All @@ -269,7 +269,7 @@ public void plotSymbol() {
h = 2;
break;
}

Rectangle thisrect = new Rectangle(x, y, w, h);
rect.add(thisrect);

Expand Down
Loading

0 comments on commit 224a97f

Please sign in to comment.