@ -34,7 +34,7 @@ import java.util.regex.Pattern;
* A segment of character / binary / control data in a QR Code symbol .
* Instances of this class are immutable .
* < p > The mid - level way to create a segment is to take the payload data and call a
* static factory function such as { @link QrSegment # makeNumeric ( String ) } . The low - level
* static factory function such as { @link QrSegment # makeNumeric ( CharSequence ) } . The low - level
* way to create a segment is to custom - make the bit buffer and call the { @link
* QrSegment # QrSegment ( Mode , int , BitBuffer ) constructor } with appropriate values . < / p >
* < p > This segment class imposes no length restrictions , but QR Codes have restrictions .
@ -72,7 +72,7 @@ public final class QrSegment {
* @throws NullPointerException if the string is { @code null }
* @throws IllegalArgumentException if the string contains non - digit characters
* /
public static QrSegment makeNumeric ( String digits ) {
public static QrSegment makeNumeric ( CharSequence digits ) {
Objects . requireNonNull ( digits ) ;
if ( ! isNumeric ( digits ) )
throw new IllegalArgumentException ( "String contains non-numeric characters" ) ;
@ -80,7 +80,7 @@ public final class QrSegment {
BitBuffer bb = new BitBuffer ( ) ;
for ( int i = 0 ; i < digits . length ( ) ; ) { // Consume up to 3 digits per iteration
int n = Math . min ( digits . length ( ) - i , 3 ) ;
bb . appendBits ( Integer . parseInt ( digits . sub string ( i , i + n ) ) , n * 3 + 1 ) ;
bb . appendBits ( Integer . parseInt ( digits . sub Sequence ( i , i + n ) . toString ( ) ) , n * 3 + 1 ) ;
i + = n ;
}
return new QrSegment ( Mode . NUMERIC , digits . length ( ) , bb ) ;
@ -96,7 +96,7 @@ public final class QrSegment {
* @throws NullPointerException if the string is { @code null }
* @throws IllegalArgumentException if the string contains non - encodable characters
* /
public static QrSegment makeAlphanumeric ( String text ) {
public static QrSegment makeAlphanumeric ( CharSequence text ) {
Objects . requireNonNull ( text ) ;
if ( ! isAlphanumeric ( text ) )
throw new IllegalArgumentException ( "String contains unencodable characters in alphanumeric mode" ) ;
@ -121,7 +121,7 @@ public final class QrSegment {
* @return a new mutable list ( not { @code null } ) of segments ( not { @code null } ) containing the text
* @throws NullPointerException if the text is { @code null }
* /
public static List < QrSegment > makeSegments ( String text ) {
public static List < QrSegment > makeSegments ( CharSequence text ) {
Objects . requireNonNull ( text ) ;
// Select the most efficient segment encoding automatically
@ -132,7 +132,7 @@ public final class QrSegment {
else if ( isAlphanumeric ( text ) )
result . add ( makeAlphanumeric ( text ) ) ;
else
result . add ( makeBytes ( text . getBytes( StandardCharsets . UTF_8 ) ) ) ;
result . add ( makeBytes ( text . toString( ) . getBytes( StandardCharsets . UTF_8 ) ) ) ;
return result ;
}
@ -168,9 +168,9 @@ public final class QrSegment {
* @param text the string to test for encodability ( not { @code null } )
* @return { @code true } iff each character is in the range 0 to 9.
* @throws NullPointerException if the string is { @code null }
* @see # makeNumeric ( String )
* @see # makeNumeric ( CharSequence )
* /
public static boolean isNumeric ( String text ) {
public static boolean isNumeric ( CharSequence text ) {
return NUMERIC_REGEX . matcher ( text ) . matches ( ) ;
}
@ -182,9 +182,9 @@ public final class QrSegment {
* @param text the string to test for encodability ( not { @code null } )
* @return { @code true } iff each character is in the alphanumeric mode character set
* @throws NullPointerException if the string is { @code null }
* @see # makeAlphanumeric ( String )
* @see # makeAlphanumeric ( CharSequence )
* /
public static boolean isAlphanumeric ( String text ) {
public static boolean isAlphanumeric ( CharSequence text ) {
return ALPHANUMERIC_REGEX . matcher ( text ) . matches ( ) ;
}