@ Nonnull public static String getExpandedMessage ( @ Nonnull final String sMsg ) { final char cCheck = sMsg . length ( ) == 8 ? sMsg . charAt ( 7 ) : ' ' ; final String sUpce = sMsg . substring ( 0 , 0 + 7 ) ; final byte nNumberSystem = _extractNumberSystem ( sUpce ) ; if ( nNumberSystem != 0 && nNumberSystem != 1 ) throw new IllegalArgumentException ( "Invalid UPC-E message: " + sMsg ) ; final StringBuilder aSB = new StringBuilder ( ) ; aSB . append ( Byte . toString ( nNumberSystem ) ) ; final byte nMode = StringParser . parseByte ( sUpce . substring ( 6 , 6 + 1 ) , ( byte ) - 1 ) ; if ( nMode >= 0 && nMode <= 2 ) { aSB . append ( sUpce . substring ( 1 , 1 + 2 ) ) ; aSB . append ( Byte . toString ( nMode ) ) ; aSB . append ( "0000" ) ; aSB . append ( sUpce . substring ( 3 , 3 + 3 ) ) ; } else if ( nMode == 3 ) { aSB . append ( sUpce . substring ( 1 , 1 + 3 ) ) ; aSB . append ( "00000" ) ; aSB . append ( sUpce . substring ( 4 , 4 + 2 ) ) ; } else if ( nMode == 4 ) { aSB . append ( sUpce . substring ( 1 , 1 + 4 ) ) ; aSB . append ( "00000" ) ; aSB . append ( sUpce . substring ( 5 , 5 + 1 ) ) ; } else if ( nMode >= 5 && nMode <= 9 ) { aSB . append ( sUpce . substring ( 1 , 1 + 5 ) ) ; aSB . append ( "0000" ) ; aSB . append ( Byte . toString ( nMode ) ) ; } else { // Shouldn't happen throw new IllegalArgumentException ( "Internal error" ) ; } final String sUpcaFinished = aSB . toString ( ) ; final char cExpectedCheck = calcChecksumChar ( sUpcaFinished , sUpcaFinished . length ( ) ) ; if ( cCheck != ' ' && cCheck != cExpectedCheck ) throw new IllegalArgumentException ( "Invalid checksum. Expected " + cExpectedCheck + " but was " + cCheck ) ; return sUpcaFinished + cExpectedCheck ; }
Expands an UPC - E message to an UPC - A message .