Top Description Fields Constructors Methods
org.codehaus.stax2.ri.typed

public final Class NumberUtil

extends Object
Class Inheritance

Helper class that contains method for converting numeric values to and from String representations.

Field Summary

Modifier and TypeField and Description
private static final int
private static final byte
private static final byte
private static final byte
pack-priv static final char[]
pack-priv static final char[]
public static final int
MAX_DOUBLE_CLEN

Maximum 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.

public static final int
MAX_FLOAT_CLEN

JDK serializes floats same way as doubles, so let's reserve as much space

private static long
public static final int
MAX_INT_CLEN

Maximum number of characters in a serialized integer is 11; one for (minus) sign, and then up to 10 digits

public static final int
MAX_LONG_CLEN

Maximum number of characters in a serialized long is 21; one for (minus) sign, and then up to 20 digits

private static final int
private static long
MIN_INT_AS_LONG

Note

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 char
private static final long
private static final long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static int
calcLongStrLength(long posValue)

Pre-conditions: posValue is positive, and larger than Integer.MAX_VALUE (about 2 billions).

private static int
getAsciiBytes(String str, byte[] buffer, int ptr)

private static int
getChars(String str, char[] buffer, int ptr)

public static int
writeDouble(double value, char[] buffer, int offset)

public static int
writeDouble(double value, byte[] buffer, int offset)

public static int
writeFloat(float value, char[] buffer, int offset)

public static int
writeFloat(float value, byte[] buffer, int offset)

private static int
writeFullTriplet(int triplet, char[] buffer, int offset)

private static int
writeFullTriplet(int triplet, byte[] buffer, int offset)

public static int

Returns:

Offset within buffer after outputting 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.

public static int
writeInt(int value, byte[] buffer, int offset)

private static int
writeLeadingTriplet(int triplet, char[] buffer, int offset)

private static int
writeLeadingTriplet(int triplet, byte[] buffer, int offset)

public static int

Returns:

Offset within buffer after outputting 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.

public static int
writeLong(long value, byte[] buffer, int offset)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BILLIONback to summary
private static final int BILLION
BYTE_1back to summary
private static final byte BYTE_1
BYTE_2back to summary
private static final byte BYTE_2
BYTE_HYPHENback to summary
private static final byte BYTE_HYPHEN
FULL_TRIPLETSback to summary
pack-priv static final char[] FULL_TRIPLETS
LEADING_TRIPLETSback to summary
pack-priv static final char[] LEADING_TRIPLETS
MAX_DOUBLE_CLENback to summary
public static final int MAX_DOUBLE_CLEN

Maximum 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.

MAX_FLOAT_CLENback to summary
public static final int MAX_FLOAT_CLEN

JDK serializes floats same way as doubles, so let's reserve as much space

MAX_INT_AS_LONGback to summary
private static long MAX_INT_AS_LONG
MAX_INT_CLENback to summary
public static final int MAX_INT_CLEN

Maximum number of characters in a serialized integer is 11; one for (minus) sign, and then up to 10 digits

MAX_LONG_CLENback to summary
public static final int MAX_LONG_CLEN

Maximum number of characters in a serialized long is 21; one for (minus) sign, and then up to 20 digits

MILLIONback to summary
private static final int MILLION
MIN_INT_AS_LONGback to summary
private static long MIN_INT_AS_LONG

Note

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)

NULL_CHARback to summary
private static final char NULL_CHAR
TEN_BILLION_Lback to summary
private static final long TEN_BILLION_L
THOUSAND_Lback to summary
private static final long THOUSAND_L

Constructor Detail

NumberUtilback to summary
public NumberUtil()

Method Detail

calcLongStrLengthback to summary
private static int calcLongStrLength(long posValue)

Pre-conditions: posValue is positive, and larger than Integer.MAX_VALUE (about 2 billions).

getAsciiBytesback to summary
private static int getAsciiBytes(String str, byte[] buffer, int ptr)
getCharsback to summary
private static int getChars(String str, char[] buffer, int ptr)
writeDoubleback to summary
public static int writeDouble(double value, char[] buffer, int offset)
writeDoubleback to summary
public static int writeDouble(double value, byte[] buffer, int offset)
writeFloatback to summary
public static int writeFloat(float value, char[] buffer, int offset)
writeFloatback to summary
public static int writeFloat(float value, byte[] buffer, int offset)
writeFullTripletback to summary
private static int writeFullTriplet(int triplet, char[] buffer, int offset)
writeFullTripletback to summary
private static int writeFullTriplet(int triplet, byte[] buffer, int offset)
writeIntback to summary
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:int

Offset within buffer after outputting int

writeIntback to summary
public static int writeInt(int value, byte[] buffer, int offset)
writeLeadingTripletback to summary
private static int writeLeadingTriplet(int triplet, char[] buffer, int offset)
writeLeadingTripletback to summary
private static int writeLeadingTriplet(int triplet, byte[] buffer, int offset)
writeLongback to summary
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:int

Offset within buffer after outputting int

writeLongback to summary
public static int writeLong(long value, byte[] buffer, int offset)