org.kalmeo.util
Class NumberUtil

java.lang.Object
  extended by org.kalmeo.util.NumberUtil

public class NumberUtil
extends java.lang.Object

Author:
omarino

Field Summary
static int ALL_FORMAT
           
static int KILO_BYTE
           
static int KILO_FORMAT
           
static int MEGA_BYTE
           
static int MEGA_FORMAT
           
 
Constructor Summary
NumberUtil()
           
 
Method Summary
static java.lang.String formatByte(int bytes, int formsAllowed)
          Format a bytes's count in string
static java.lang.String formatFP(int fpValue, int integerDigit, int decimalDigit)
          Format a fpValue with specified integer and decimal digits number
static java.lang.String formatInt(int value, int numDigit)
          Format an integer value with specifie integer digits number
static byte[] toBytes(int value)
          Convert an int to a byte array
static void toBytes(int value, byte[] buffer, int offset)
          Convert an int to a byte array and set it into buffer at specified offset
static byte[] toBytes(long value)
          Convert a long to a byte array
static void toBytes(long value, byte[] buffer, int offset)
          Convert a long to a byte array and set it into buffer at specified offset
static byte[] toBytes(short value)
          Convert a short to a byte array
static void toBytes(short value, byte[] buffer, int offset)
          Convert a short to a byte array and set it into buffer at specified offset
static int toInt(byte[] bytes, int offset)
          Convert a byte array to an int value
static long toLong(byte[] bytes, int offset)
          Convert a byte array to a long value
static short toShort(byte[] bytes, int offset)
          Convert a byte array to a short value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MEGA_BYTE

public static final int MEGA_BYTE
See Also:
Constant Field Values

KILO_BYTE

public static final int KILO_BYTE
See Also:
Constant Field Values

MEGA_FORMAT

public static final int MEGA_FORMAT
See Also:
Constant Field Values

KILO_FORMAT

public static final int KILO_FORMAT
See Also:
Constant Field Values

ALL_FORMAT

public static final int ALL_FORMAT
See Also:
Constant Field Values
Constructor Detail

NumberUtil

public NumberUtil()
Method Detail

formatByte

public static java.lang.String formatByte(int bytes,
                                          int formsAllowed)
Format a bytes's count in string

Parameters:
bytes - the bytes's count
formsAllowed - specifie wich form are autorized by the formater. MEGA_FORMAT return bytes under MegaByte form, Byte else KILO_FORMAT return bytes under KiloByte form, Byte else ALL_FORMAT return bytes under MegaByte, KiloByte ot Byte form.
Returns:
formated string containing bytes's count

formatInt

public static java.lang.String formatInt(int value,
                                         int numDigit)
Format an integer value with specifie integer digits number

Parameters:
value - the value wich be formated
numDigit - specifie the integer part size
Returns:
formated integer

formatFP

public static java.lang.String formatFP(int fpValue,
                                        int integerDigit,
                                        int decimalDigit)
Format a fpValue with specified integer and decimal digits number

Parameters:
fpValue - is the fixed point integer wich be formated
integerDigit - specifie the integer part size
decimalDigit - specifie the decimal part size
Returns:
formated fixed point

toBytes

public static byte[] toBytes(short value)
Convert a short to a byte array

Parameters:
value -
Returns:
the byte array corresponding to the short value

toBytes

public static byte[] toBytes(int value)
Convert an int to a byte array

Parameters:
value -
Returns:
the byte array corresponding to the int value

toBytes

public static byte[] toBytes(long value)
Convert a long to a byte array

Parameters:
value -
Returns:
the byte array corresponding to the int value

toBytes

public static void toBytes(short value,
                           byte[] buffer,
                           int offset)
Convert a short to a byte array and set it into buffer at specified offset

Parameters:
value -
buffer -
offset -

toBytes

public static void toBytes(int value,
                           byte[] buffer,
                           int offset)
Convert an int to a byte array and set it into buffer at specified offset

Parameters:
value -
buffer -
offset -

toBytes

public static void toBytes(long value,
                           byte[] buffer,
                           int offset)
Convert a long to a byte array and set it into buffer at specified offset

Parameters:
value -
buffer -
offset -

toShort

public static short toShort(byte[] bytes,
                            int offset)
Convert a byte array to a short value

Parameters:
bytes -
offset -
Returns:
the short value corresponding to the 2 first bytes of the byte array

toInt

public static int toInt(byte[] bytes,
                        int offset)
Convert a byte array to an int value

Parameters:
bytes -
offset -
Returns:
the int value corresponding to the 4 first bytes of the byte array

toLong

public static long toLong(byte[] bytes,
                          int offset)
Convert a byte array to a long value

Parameters:
bytes -
offset -
Returns:
the long value corresponding to the 8 first bytes of the byte array


Copyright © 2007-2008 Kalmeo. All Rights Reserved.