BarcodeMSI extends Barcode1D { public static int getChecksum(String text) { if (text == null) { throw new IllegalArgumentException("Valid code required to generate checksum for MSI barcode"); } int[] digits = new int[text.length()]; for (int x = 0; x < text.length(); x++) { digits[x] = (int)(text.charAt(x) - '0'); if (digits[x] < 0 || digits[x] > 9) { throw new IllegalArgumentException("The character " + text.charAt(x) + " is illegal in MSI bar codes."); } } int sum = 0; int length = digits.length; for (int i = 0; i < length; i++) { int digit = digits[length - i - 1]; if (i % 2 == 0) { digit *= 2; } sum += digit > 9 ? digit - 9 : digit; } return (sum * 9) % 10; } BarcodeMSI(PdfDocument document);  BarcodeMSI(PdfDocument document, PdfFont font); @Override Rectangle getBarcodeSize(); @Override Rectangle placeBarcode(PdfCanvas canvas, Color barColor, Color textColor); @Override Image createAwtImage(java.awt.Color foreground, java.awt.Color background); static byte[] getBarsMSI(String text); static int getChecksum(String text);  }
@Test public void barcode04Test() { String code = "0987654321"; int expectedChecksum = 7; int checksum = BarcodeMSI.getChecksum(code); Assert.assertEquals(checksum, expectedChecksum); }