Class JavaBigIntegerParser
- java.lang.Object
-
- ch.randelshofer.fastdoubleparser.JavaBigIntegerParser
-
public final class JavaBigIntegerParser extends java.lang.ObjectParses aBigIntegervalue; the supported syntax is compatible withBigInteger(String, int).Syntax
Formal specification of the grammar:
- BigIntegerString:
- [Sign] Digits
- Sign:
- (one of)
+ -
- Digits:
- Digit {Digit}
- Digit:
- (one of)
0 1 2 3 4 5 6 7 8 9a b c d e f g h i j k l m n o p q r s t u v w x y zA B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Character lengths accepted by
BigInteger(String):BigIntegerString:Integer.MAX_VALUE- 4.If the significand consists only of zero digits, the length is only limited by the maximal supported length of a Java array.
radix=10If the significand contains at least one non-zero digit, the length is limited to
index of first non-zero digit + 646_456_993. This is because the resulting value must fit into2^31 - 1bits. The decimal representation of the value2^31 - 1needs 646,456,993 digits. Therefore an input String can only contain up to that many significant digits - the remaining digits must be leading zeroes.radix=16If the significand contains at least one non-zero digit, the length is limited to
index of first non-zero digit + 536_870_912. This is because the resulting value must fit into2^31 - 1bits. The hexa-decimal representation of the value2^31 - 1needs 536,870,912 digits. Therefore an input String can only contain up to that many significant digits - the remaining digits must be leading zeroes.
References:
- Java SE 17 & JDK 17, JavaDoc, Class BigInteger
- docs.oracle.com
-
-
Field Summary
Fields Modifier and Type Field Description private static JavaBigIntegerFromByteArrayBYTE_ARRAY_PARSERprivate static JavaBigIntegerFromCharArrayCHAR_ARRAY_PARSERprivate static JavaBigIntegerFromCharSequenceCHAR_SEQUENCE_PARSER
-
Constructor Summary
Constructors Modifier Constructor Description privateJavaBigIntegerParser()Don't let anyone instantiate this class.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.math.BigIntegerparseBigInteger(byte[] str)Convenience method for callingparseBigInteger(byte[], int, int).static java.math.BigIntegerparseBigInteger(byte[] str, int radix)Convenience method for callingparseBigInteger(byte[], int, int, int).static java.math.BigIntegerparseBigInteger(byte[] str, int offset, int length)Parses aBigIntegerStringfrom abyte-Array and converts it into aBigIntegervalue.static java.math.BigIntegerparseBigInteger(byte[] str, int offset, int length, int radix)Parses aBigIntegerStringfrom abyte-Array and converts it into aBigIntegervalue.static java.math.BigIntegerparseBigInteger(char[] str)Convenience method for callingparseBigInteger(char[], int, int).static java.math.BigIntegerparseBigInteger(char[] str, int radix)Convenience method for callingparseBigInteger(char[], int, int, int).static java.math.BigIntegerparseBigInteger(char[] str, int offset, int length)Parses aBigIntegerStringfrom achar-Array and converts it into aBigIntegervalue.static java.math.BigIntegerparseBigInteger(char[] str, int offset, int length, int radix)Parses aBigIntegerStringfrom achar-Array and converts it into aBigIntegervalue.static java.math.BigIntegerparseBigInteger(java.lang.CharSequence str)Convenience method for callingparseBigInteger(CharSequence, int, int).static java.math.BigIntegerparseBigInteger(java.lang.CharSequence str, int radix)Convenience method for callingparseBigInteger(CharSequence, int, int, int).static java.math.BigIntegerparseBigInteger(java.lang.CharSequence str, int offset, int length)Convenience method for callingparseBigInteger(CharSequence, int, int, int).static java.math.BigIntegerparseBigInteger(java.lang.CharSequence str, int offset, int length, int radix)Parses aBigIntegerStringfrom aCharSequenceand converts it into aBigIntegervalue.
-
-
-
Field Detail
-
BYTE_ARRAY_PARSER
private static final JavaBigIntegerFromByteArray BYTE_ARRAY_PARSER
-
CHAR_ARRAY_PARSER
private static final JavaBigIntegerFromCharArray CHAR_ARRAY_PARSER
-
CHAR_SEQUENCE_PARSER
private static final JavaBigIntegerFromCharSequence CHAR_SEQUENCE_PARSER
-
-
Method Detail
-
parseBigInteger
public static java.math.BigInteger parseBigInteger(java.lang.CharSequence str)
Convenience method for callingparseBigInteger(CharSequence, int, int).- Parameters:
str- the string to be parsed- Returns:
- the parsed value
- Throws:
java.lang.NullPointerException- if the string is nulljava.lang.NumberFormatException- if the string can not be parsed successfully
-
parseBigInteger
public static java.math.BigInteger parseBigInteger(java.lang.CharSequence str, int radix)Convenience method for callingparseBigInteger(CharSequence, int, int, int).- Parameters:
str- the string to be parsedradix- the radix to be used in interpreting thestr- Returns:
- the parsed value
- Throws:
java.lang.NullPointerException- if the string is nulljava.lang.NumberFormatException- if the string can not be parsed successfully
-
parseBigInteger
public static java.math.BigInteger parseBigInteger(java.lang.CharSequence str, int offset, int length)Convenience method for callingparseBigInteger(CharSequence, int, int, int).- Parameters:
str- the string to be parsedoffset- The index of the first character to parselength- The number of characters to parse- Returns:
- the parsed value
- Throws:
java.lang.NullPointerException- if the string is nulljava.lang.IllegalArgumentException- if offset or length are illegaljava.lang.NumberFormatException- if the string can not be parsed successfully
-
parseBigInteger
public static java.math.BigInteger parseBigInteger(java.lang.CharSequence str, int offset, int length, int radix)Parses aBigIntegerStringfrom aCharSequenceand converts it into aBigIntegervalue.- Parameters:
str- the string to be parsedoffset- The index of the first character to parselength- The number of characters to parseradix- the radix to be used in interpreting thestr- Returns:
- the parsed value
- Throws:
java.lang.NullPointerException- if the string is nulljava.lang.IllegalArgumentException- if offset or length are illegaljava.lang.NumberFormatException- if the string can not be parsed successfully
-
parseBigInteger
public static java.math.BigInteger parseBigInteger(byte[] str)
Convenience method for callingparseBigInteger(byte[], int, int).- Parameters:
str- the string to be parsed- Returns:
- the parsed value
- Throws:
java.lang.NullPointerException- if the string is nulljava.lang.NumberFormatException- if the string can not be parsed successfully
-
parseBigInteger
public static java.math.BigInteger parseBigInteger(byte[] str, int radix)Convenience method for callingparseBigInteger(byte[], int, int, int).- Parameters:
str- the string to be parsedradix- the radix to be used in interpreting thestr- Returns:
- the parsed value
- Throws:
java.lang.NullPointerException- if the string is nulljava.lang.NumberFormatException- if the string can not be parsed successfully
-
parseBigInteger
public static java.math.BigInteger parseBigInteger(byte[] str, int offset, int length)Parses aBigIntegerStringfrom abyte-Array and converts it into aBigIntegervalue.See
JsonDoubleParserfor the syntax ofFloatingPointLiteral.- Parameters:
str- the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encodingoffset- The index of the first character to parselength- The number of characters to parse- Returns:
- the parsed value
- Throws:
java.lang.NullPointerException- if the string is nulljava.lang.IllegalArgumentException- if offset or length are illegaljava.lang.NumberFormatException- if the string can not be parsed successfully
-
parseBigInteger
public static java.math.BigInteger parseBigInteger(byte[] str, int offset, int length, int radix)Parses aBigIntegerStringfrom abyte-Array and converts it into aBigIntegervalue.See
JsonDoubleParserfor the syntax ofFloatingPointLiteral.- Parameters:
str- the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encodingoffset- The index of the first character to parselength- The number of characters to parseradix- the radix to be used in interpreting thestr- Returns:
- the parsed value
- Throws:
java.lang.NullPointerException- if the string is nulljava.lang.IllegalArgumentException- if offset or length are illegaljava.lang.NumberFormatException- if the string can not be parsed successfully
-
parseBigInteger
public static java.math.BigInteger parseBigInteger(char[] str)
Convenience method for callingparseBigInteger(char[], int, int).- Parameters:
str- the string to be parsed- Returns:
- the parsed value
- Throws:
java.lang.NullPointerException- if the string is nulljava.lang.NumberFormatException- if the string can not be parsed successfully
-
parseBigInteger
public static java.math.BigInteger parseBigInteger(char[] str, int radix)Convenience method for callingparseBigInteger(char[], int, int, int).- Parameters:
str- the string to be parsedradix- the radix to be used in interpreting thestr- Returns:
- the parsed value
- Throws:
java.lang.NullPointerException- if the string is nulljava.lang.NumberFormatException- if the string can not be parsed successfully
-
parseBigInteger
public static java.math.BigInteger parseBigInteger(char[] str, int offset, int length)Parses aBigIntegerStringfrom achar-Array and converts it into aBigIntegervalue.See
JsonDoubleParserfor the syntax ofFloatingPointLiteral.- Parameters:
str- the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encodingoffset- The index of the first character to parselength- The number of characters to parse- Returns:
- the parsed value
- Throws:
java.lang.NullPointerException- if the string is nulljava.lang.IllegalArgumentException- if offset or length are illegaljava.lang.NumberFormatException- if the string can not be parsed successfully
-
parseBigInteger
public static java.math.BigInteger parseBigInteger(char[] str, int offset, int length, int radix)Parses aBigIntegerStringfrom achar-Array and converts it into aBigIntegervalue.See
JsonDoubleParserfor the syntax ofFloatingPointLiteral.- Parameters:
str- the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encodingoffset- The index of the first character to parselength- The number of characters to parseradix- the radix to be used in interpreting thestr- Returns:
- the parsed value
- Throws:
java.lang.NullPointerException- if the string is nulljava.lang.IllegalArgumentException- if offset or length are illegaljava.lang.NumberFormatException- if the string can not be parsed successfully
-
-