Package org.codehaus.stax2.ri.typed
Class NumberUtil
java.lang.Object
org.codehaus.stax2.ri.typed.NumberUtil
Helper class that contains method for converting numeric
values to and from String representations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final byteprivate static final byteprivate static final byte(package private) static final char[](package private) static final char[]static final intMaximum number of characters in a serialized double is 26 (at least for Sun JDK; 19 digits for mantissa, 3 for exponent, signs for mantissa and exponent, decimal point, 'E'): but let's pad it up a little bit just to play it safe.static final intJDK serializes floats same way as doubles, so let's reserve as much spaceprivate static longstatic final intMaximum number of characters in a serialized integer is 11; one for (minus) sign, and then up to 10 digitsstatic final intMaximum number of characters in a serialized long is 21; one for (minus) sign, and then up to 20 digitsprivate static final intprivate static longNote: we'll increase value since Integer.MIN_VALUE can not actually be output using simple int-serialization mechanism (since its negation does not fit in 32-bit signed int range)private static final charprivate static final longprivate static final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static intcalcLongStrLength(long posValue) Pre-conditions: posValue is positive, and larger than Integer.MAX_VALUE (about 2 billions).private static intgetAsciiBytes(String str, byte[] buffer, int ptr) private static intstatic intwriteDouble(double value, byte[] buffer, int offset) static intwriteDouble(double value, char[] buffer, int offset) static intwriteFloat(float value, byte[] buffer, int offset) static intwriteFloat(float value, char[] buffer, int offset) private static intwriteFullTriplet(int triplet, byte[] buffer, int offset) private static intwriteFullTriplet(int triplet, char[] buffer, int offset) static intwriteInt(int value, byte[] buffer, int offset) static intwriteInt(int value, char[] buffer, int offset) Note: caller must ensure that there is room for least 11 characters (leading sign, and up to 10 digits) in buffer passed.private static intwriteLeadingTriplet(int triplet, byte[] buffer, int offset) private static intwriteLeadingTriplet(int triplet, char[] buffer, int offset) static intwriteLong(long value, byte[] buffer, int offset) static intwriteLong(long value, char[] buffer, int offset) Note: caller must ensure that there is room for least 21 characters (leading sign, and up to 20 digits ) in buffer passed.
-
Field Details
-
MAX_INT_CLEN
public static final int MAX_INT_CLENMaximum number of characters in a serialized integer is 11; one for (minus) sign, and then up to 10 digits- See Also:
-
MAX_LONG_CLEN
public static final int MAX_LONG_CLENMaximum number of characters in a serialized long is 21; one for (minus) sign, and then up to 20 digits- See Also:
-
MAX_DOUBLE_CLEN
public static final int MAX_DOUBLE_CLENMaximum number of characters in a serialized double is 26 (at least for Sun JDK; 19 digits for mantissa, 3 for exponent, signs for mantissa and exponent, decimal point, 'E'): but let's pad it up a little bit just to play it safe.- See Also:
-
MAX_FLOAT_CLEN
public static final int MAX_FLOAT_CLENJDK serializes floats same way as doubles, so let's reserve as much space- See Also:
-
NULL_CHAR
private static final char NULL_CHAR- See Also:
-
MILLION
private static final int MILLION- See Also:
-
BILLION
private static final int BILLION- See Also:
-
TEN_BILLION_L
private static final long TEN_BILLION_L- See Also:
-
THOUSAND_L
private static final long THOUSAND_L- See Also:
-
BYTE_HYPHEN
private static final byte BYTE_HYPHEN- See Also:
-
BYTE_1
private static final byte BYTE_1- See Also:
-
BYTE_2
private static final byte BYTE_2- See Also:
-
MIN_INT_AS_LONG
private static long MIN_INT_AS_LONGNote: we'll increase value since Integer.MIN_VALUE can not actually be output using simple int-serialization mechanism (since its negation does not fit in 32-bit signed int range)
-
MAX_INT_AS_LONG
private static long MAX_INT_AS_LONG -
LEADING_TRIPLETS
static final char[] LEADING_TRIPLETS -
FULL_TRIPLETS
static final char[] FULL_TRIPLETS
-
-
Constructor Details
-
NumberUtil
public NumberUtil()
-
-
Method Details
-
writeInt
public static int writeInt(int value, char[] buffer, int offset) Note: caller must ensure that there is room for least 11 characters (leading sign, and up to 10 digits) in buffer passed.
- Returns:
- Offset within buffer after outputting int
-
writeInt
public static int writeInt(int value, byte[] buffer, int offset) -
writeLong
public static int writeLong(long value, char[] buffer, int offset) Note: caller must ensure that there is room for least 21 characters (leading sign, and up to 20 digits ) in buffer passed.
- Returns:
- Offset within buffer after outputting int
-
writeLong
public static int writeLong(long value, byte[] buffer, int offset) -
writeFloat
public static int writeFloat(float value, char[] buffer, int offset) -
writeFloat
public static int writeFloat(float value, byte[] buffer, int offset) -
writeDouble
public static int writeDouble(double value, char[] buffer, int offset) -
writeDouble
public static int writeDouble(double value, byte[] buffer, int offset) -
writeLeadingTriplet
private static int writeLeadingTriplet(int triplet, char[] buffer, int offset) -
writeLeadingTriplet
private static int writeLeadingTriplet(int triplet, byte[] buffer, int offset) -
writeFullTriplet
private static int writeFullTriplet(int triplet, char[] buffer, int offset) -
writeFullTriplet
private static int writeFullTriplet(int triplet, byte[] buffer, int offset) -
calcLongStrLength
private static int calcLongStrLength(long posValue) Pre-conditions: posValue is positive, and larger than Integer.MAX_VALUE (about 2 billions).
-
getChars
-
getAsciiBytes
-