com.ejie.r01f.util
Class NumberUtils

java.lang.Object
  extended bycom.ejie.r01f.util.NumberUtils

public abstract class NumberUtils
extends java.lang.Object

Contiene utilidades matemáticas.

Author:
Alex (EJIE)

Field Summary
static int INTEGER_WIDTH
          El tamaño estandar para enteros de java
 
Constructor Summary
NumberUtils()
           
 
Method Summary
static int bytesToInt(byte[] byteArray)
          Convierte un array de bytes en un entero NOTA: Devuelve el LSB (LessSignificantByte) en [0]
static int clearBit(int originalInt, int bitIndex)
          Borra un bit de un entero y devuelve este nuevo entero
static boolean getBit(int integer, int bitIndex)
          Devuelve el valor de un bit de un entero
static byte[] intToBytes(int integer)
          Convierte un entero en un array de bytes NOTA: Devuelve el LSB (LessSignificantByte) en [0]
static boolean isByte(java.lang.String strByte)
          Comprueba si una cadena es un byte
static boolean isByte(java.lang.String strByte, int radix)
          Comprueba si una cadena es un byte
static boolean isDouble(java.lang.String strDouble)
          Comprueba si una cadena es un Double
static boolean isEven(int intNum)
          Comprueba si un entero es par.
static boolean isEven(long longNum)
          Comprueba si un long es par.
static boolean isFloat(java.lang.String strFloat)
          Comprueba si una cadena es un Float
static boolean isInteger(java.lang.String strInt)
          Comprueba si una cadena es un entero
static boolean isInteger(java.lang.String strInt, int radix)
          Comprueba si una cadena es un entero
static boolean isLong(java.lang.String strLong)
          Comprueba si una cadena es un Long
static boolean isLong(java.lang.String strLong, int radix)
          Comprueba si una cadena es un Long
static boolean isNumber(java.lang.String s)
          Valida si una cadena es un número
static boolean isOdd(int intNum)
          Comprueba si un entero es impar.
static boolean isOdd(long longNum)
          Comprueba si un long es impar.
static boolean isShort(java.lang.String strShort)
          Comprueba si una cadena es un Short
static void main(java.lang.String[] args)
          Main Method
static int setBit(int originalInt, int bitIndex)
          Establece un bit de un entero y devuelve este nuevo entero
static byte toByte(double d)
          double to byte
static byte toByte(float f)
          float to byte
static byte toByte(int i)
          int to byte
static byte toByte(long l)
          long to byte
static byte toByte(short sh)
          short to byte
static byte toByte(java.lang.String s)
          String to byte
static double toDouble(byte b)
          byte to double
static double toDouble(float f)
          float to double
static double toDouble(int i)
          int to double
static double toDouble(long l)
          long to double
static double toDouble(short s)
          short to double
static double toDouble(java.lang.String s)
          String to double
static float toFloat(byte b)
          byte to float
static float toFloat(double d)
          double to float
static float toFloat(int i)
          int to float
static float toFloat(long l)
          long to float
static float toFloat(short sh)
          short to float
static float toFloat(java.lang.String s)
          String to float
static int toInt(byte b)
          byte to int
static int toInt(double d)
          double to int
static int toInt(float f)
          float to int
static int toInt(long l)
          long to int
static int toInt(short sh)
          short to int
static int toInt(java.lang.String s)
          String to int
static long toLong(byte b)
          byte to Long
static long toLong(double d)
          double to Long
static long toLong(float f)
          float to Long
static long toLong(int i)
          int to Long
static long toLong(short sh)
          short to Long
static long toLong(java.lang.String s)
          String to Long
static short toShort(byte b)
          byte to Short
static short toShort(double d)
          double to Short
static short toShort(float f)
          float to Short
static short toShort(int i)
          int to Short
static short toShort(long l)
          long to Short
static short toShort(java.lang.String s)
          String to Short
static java.lang.String toString(byte d)
          byte to String
static java.lang.String toString(double d)
          double to String
static java.lang.String toString(float f)
          float to String
static java.lang.String toString(int i)
          int to String
static java.lang.String toString(long l)
          long to String
static java.lang.String toString(short sh)
          short to String
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTEGER_WIDTH

public static final int INTEGER_WIDTH
El tamaño estandar para enteros de java

See Also:
Constant Field Values
Constructor Detail

NumberUtils

public NumberUtils()
Method Detail

isEven

public static boolean isEven(int intNum)
Comprueba si un entero es par. Java Puzzle 1: Oddity

Returns:
true si es par

isOdd

public static boolean isOdd(int intNum)
Comprueba si un entero es impar. Java Puzzle 1: Oddity

Parameters:
intNum - el entero
Returns:
true si es impar

isEven

public static boolean isEven(long longNum)
Comprueba si un long es par. Java Puzzle 1: Oddity

Returns:
true si es par

isOdd

public static boolean isOdd(long longNum)
Comprueba si un long es impar. Java Puzzle 1: Oddity

Parameters:
longNum - el long
Returns:
true si es impar

setBit

public static int setBit(int originalInt,
                         int bitIndex)
Establece un bit de un entero y devuelve este nuevo entero

Parameters:
originalInt - El entero en el que hay que establecer el bit
bitIndex - El indice del bit a establecer
Returns:
el entero con el bit establecido

clearBit

public static int clearBit(int originalInt,
                           int bitIndex)
Borra un bit de un entero y devuelve este nuevo entero

Parameters:
originalInt - el entero en el que hay que establecer el bit
bitIndex - El indice del bit a establecer
Returns:
el entero con el bit establecido

getBit

public static boolean getBit(int integer,
                             int bitIndex)
Devuelve el valor de un bit de un entero

Parameters:
integer - el entero del cual hay que extraer un bit
bitIndex - el indice del bit a extraer
Returns:
el valor del bit

intToBytes

public static byte[] intToBytes(int integer)
Convierte un entero en un array de bytes NOTA: Devuelve el LSB (LessSignificantByte) en [0]

Parameters:
integer - El entero a convertir
Returns:
un array de 4 bytes con el LSB(LessSignificantByte) en [0]

bytesToInt

public static int bytesToInt(byte[] byteArray)
Convierte un array de bytes en un entero NOTA: Devuelve el LSB (LessSignificantByte) en [0]

Parameters:
byteArray - El array de bytes que componen el entero con el LSB (LessSignificantByte) en [0]
Returns:
un entero

toByte

public static byte toByte(double d)
double to byte


toByte

public static byte toByte(float f)
float to byte


toByte

public static byte toByte(int i)
int to byte


toByte

public static byte toByte(long l)
long to byte


toByte

public static byte toByte(short sh)
short to byte


toByte

public static byte toByte(java.lang.String s)
String to byte


toDouble

public static double toDouble(byte b)
byte to double


toDouble

public static double toDouble(float f)
float to double


toDouble

public static double toDouble(int i)
int to double


toDouble

public static double toDouble(long l)
long to double


toDouble

public static double toDouble(short s)
short to double


toDouble

public static double toDouble(java.lang.String s)
String to double


toFloat

public static float toFloat(byte b)
byte to float


toFloat

public static float toFloat(double d)
double to float


toFloat

public static float toFloat(int i)
int to float


toFloat

public static float toFloat(long l)
long to float


toFloat

public static float toFloat(short sh)
short to float


toFloat

public static float toFloat(java.lang.String s)
String to float


toInt

public static int toInt(byte b)
byte to int


toInt

public static int toInt(double d)
double to int


toInt

public static int toInt(float f)
float to int


toInt

public static int toInt(long l)
long to int


toInt

public static int toInt(short sh)
short to int


toInt

public static int toInt(java.lang.String s)
String to int


toLong

public static long toLong(byte b)
byte to Long


toLong

public static long toLong(double d)
double to Long


toLong

public static long toLong(float f)
float to Long


toLong

public static long toLong(int i)
int to Long


toLong

public static long toLong(short sh)
short to Long


toLong

public static long toLong(java.lang.String s)
String to Long


toShort

public static short toShort(byte b)
byte to Short


toShort

public static short toShort(double d)
double to Short


toShort

public static short toShort(float f)
float to Short


toShort

public static short toShort(int i)
int to Short


toShort

public static short toShort(long l)
long to Short


toShort

public static short toShort(java.lang.String s)
String to Short


toString

public static java.lang.String toString(byte d)
byte to String


toString

public static java.lang.String toString(double d)
double to String


toString

public static java.lang.String toString(float f)
float to String


toString

public static java.lang.String toString(int i)
int to String


toString

public static java.lang.String toString(long l)
long to String


toString

public static java.lang.String toString(short sh)
short to String


isNumber

public static boolean isNumber(java.lang.String s)
Valida si una cadena es un número

Parameters:
s - cadena a validar
Returns:
true si es un número, false para el resto de casos (valor nulo; cadena vacia; cadena no numérica)

isInteger

public static boolean isInteger(java.lang.String strInt,
                                int radix)
Comprueba si una cadena es un entero

Parameters:
strInt - La representacion del entero en forma de cadena
radix - El formato de de la cadena de entrada: 2 binario, 8 octal, 10 decimal, 16 hex
Returns:
true si el la cadena es un entero o false si no lo es.

isInteger

public static boolean isInteger(java.lang.String strInt)
Comprueba si una cadena es un entero

Parameters:
strInt - La representacion DECIMAL del entero en forma de cadena
Returns:
true si el la cadena es un entero o false si no lo es.

isByte

public static boolean isByte(java.lang.String strByte,
                             int radix)
Comprueba si una cadena es un byte

Parameters:
strByte - La representacion del byte en forma de cadena
radix - El formato de de la cadena de entrada: 2 binario, 8 octal, 10 decimal, 16 hex
Returns:
true si el la cadena es un byte o false si no lo es.

isByte

public static boolean isByte(java.lang.String strByte)
Comprueba si una cadena es un byte

Parameters:
strByte - La representacion DECIMAL del byte en forma de cadena
Returns:
true si el la cadena es un byte o false si no lo es.

isLong

public static boolean isLong(java.lang.String strLong,
                             int radix)
Comprueba si una cadena es un Long

Parameters:
strLong - La representacion del long en forma de cadena
radix - El formato de de la cadena de entrada: 2 binario, 8 octal, 10 decimal, 16 hex
Returns:
true si el la cadena es un long o false si no lo es.

isLong

public static boolean isLong(java.lang.String strLong)
Comprueba si una cadena es un Long

Parameters:
strLong - La representacion DECIMAL del long en forma de cadena
Returns:
true si el la cadena es un long o false si no lo es.

isFloat

public static boolean isFloat(java.lang.String strFloat)
Comprueba si una cadena es un Float

Parameters:
strFloat - La representacion decimal del float en forma de cadena
Returns:
true si el la cadena es un float o false si no lo es.

isShort

public static boolean isShort(java.lang.String strShort)
Comprueba si una cadena es un Short

Parameters:
strShort - La representacion decimal del short en forma de cadena
Returns:
true si la cadena es un short o false si no lo es.

isDouble

public static boolean isDouble(java.lang.String strDouble)
Comprueba si una cadena es un Double

Parameters:
strDouble - La representacion del double en forma de cadena
Returns:
true si la cadena es un double o false si no lo es.

main

public static void main(java.lang.String[] args)
Main Method

Parameters:
args -