net.sf.qualitycheck
Class NumberInRange

java.lang.Object
  extended by net.sf.qualitycheck.NumberInRange

public final class NumberInRange
extends Object

Check if a number is in a given range of a particular datatype.

Author:
Dominik Seichter Based on code from, Cedric Chabanois (cchabanois at gmail.com)

Field Summary
static BigInteger BYTE_MAX
           
static BigInteger BYTE_MIN
           
static BigDecimal DOUBLE_MAX
           
static BigDecimal DOUBLE_MIN
           
static BigDecimal FLOAT_MAX
           
static BigDecimal FLOAT_MIN
           
static BigInteger INTEGER_MAX
           
static BigInteger INTEGER_MIN
           
static BigInteger LONG_MAX
           
static BigInteger LONG_MIN
           
static BigInteger SHORT_MAX
           
static BigInteger SHORT_MIN
           
 
Method Summary
static byte checkByte(Number number)
          Checks if a given number is in the range of a byte.
static double checkDouble(Number number)
          Checks if a given number is in the range of a double.
static float checkFloat(Number number)
          Checks if a given number is in the range of a float.
static int checkInteger(Number number)
          Checks if a given number is in the range of an integer.
static int checkLong(Number number)
          Checks if a given number is in the range of a long.
static short checkShort(Number number)
          Checks if a given number is in the range of a short.
static boolean isInByteRange(Number number)
          Test if a number is in the range of the datatype byte
static boolean isInDoubleRange(Number number)
          Test if a number is in the range of the datatype double
static boolean isInFloatRange(Number number)
          Test if a number is in the range of the datatype float
static boolean isInIntegerRange(Number number)
          Test if a number is in the range of the datatype int
static boolean isInLongRange(Number number)
          Test if a number is in the range of the datatype long
static boolean isInRange(Number number, BigDecimal min, BigDecimal max)
          Test if a number is in an arbitrary range.
static boolean isInRange(Number number, BigInteger min, BigInteger max)
          Test if a number is in an arbitrary range.
static boolean isInShortRange(Number number)
          Test if a number is in the range of the datatype short
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BYTE_MIN

public static final BigInteger BYTE_MIN

BYTE_MAX

public static final BigInteger BYTE_MAX

SHORT_MIN

public static final BigInteger SHORT_MIN

SHORT_MAX

public static final BigInteger SHORT_MAX

INTEGER_MIN

public static final BigInteger INTEGER_MIN

INTEGER_MAX

public static final BigInteger INTEGER_MAX

LONG_MIN

public static final BigInteger LONG_MIN

LONG_MAX

public static final BigInteger LONG_MAX

FLOAT_MAX

public static final BigDecimal FLOAT_MAX

FLOAT_MIN

public static final BigDecimal FLOAT_MIN

DOUBLE_MAX

public static final BigDecimal DOUBLE_MAX

DOUBLE_MIN

public static final BigDecimal DOUBLE_MIN
Method Detail

checkByte

public static byte checkByte(@Nonnull
                             Number number)
Checks if a given number is in the range of a byte.

Parameters:
number - a number which should be in the range of a byte (positive or negative)
Returns:
number as a byte (rounding might occur)
See Also:
Byte.MIN_VALUE, Byte.MAX_VALUE

checkShort

public static short checkShort(@Nonnull
                               Number number)
Checks if a given number is in the range of a short.

Parameters:
number - a number which should be in the range of a short (positive or negative)
Returns:
number as a short (rounding might occur)
See Also:
Short.MIN_VALUE, Short.MAX_VALUE

checkInteger

public static int checkInteger(@Nonnull
                               Number number)
Checks if a given number is in the range of an integer.

Parameters:
number - a number which should be in the range of an integer (positive or negative)
Returns:
number as an integer (rounding might occur)
See Also:
Integer.MIN_VALUE, Integer.MAX_VALUE

checkLong

public static int checkLong(@Nonnull
                            Number number)
Checks if a given number is in the range of a long.

Parameters:
number - a number which should be in the range of a long (positive or negative)
Returns:
number as a long (rounding might occur)
See Also:
Long.MIN_VALUE, Long.MAX_VALUE

checkFloat

public static float checkFloat(@Nonnull
                               Number number)
Checks if a given number is in the range of a float.

Parameters:
number - a number which should be in the range of a float (positive or negative)
Returns:
number as a float
See Also:
Float.MIN_VALUE, Float.MAX_VALUE

checkDouble

public static double checkDouble(@Nonnull
                                 Number number)
Checks if a given number is in the range of a double.

Parameters:
number - a number which should be in the range of a double (positive or negative)
Returns:
number as a double
See Also:
Double.MIN_VALUE, Double.MAX_VALUE

isInByteRange

public static boolean isInByteRange(@Nonnull
                                    Number number)
Test if a number is in the range of the datatype byte

Parameters:
number - a number
Returns:
true if the given number can be stored in a byte

isInShortRange

public static boolean isInShortRange(@Nonnull
                                     Number number)
Test if a number is in the range of the datatype short

Parameters:
number - a number
Returns:
true if the given number can be stored in a short

isInIntegerRange

public static boolean isInIntegerRange(@Nonnull
                                       Number number)
Test if a number is in the range of the datatype int

Parameters:
number - a number
Returns:
true if the given number can be stored in a int

isInLongRange

public static boolean isInLongRange(@Nonnull
                                    Number number)
Test if a number is in the range of the datatype long

Parameters:
number - a number
Returns:
true if the given number can be stored in a long

isInRange

public static boolean isInRange(@Nonnull
                                Number number,
                                @Nonnull
                                BigInteger min,
                                @Nonnull
                                BigInteger max)
Test if a number is in an arbitrary range.

Parameters:
number - a number
min - lower boundary of the range
max - upper boundary of the range
Returns:
true if the given number is within the range

isInRange

public static boolean isInRange(@Nonnull
                                Number number,
                                @Nonnull
                                BigDecimal min,
                                @Nonnull
                                BigDecimal max)
Test if a number is in an arbitrary range.

Parameters:
number - a number
min - lower boundary of the range
max - upper boundary of the range
Returns:
true if the given number is within the range

isInFloatRange

public static boolean isInFloatRange(@Nonnull
                                     Number number)
Test if a number is in the range of the datatype float

Parameters:
number - a number
Returns:
true if the given number can be stored in a float

isInDoubleRange

public static boolean isInDoubleRange(@Nonnull
                                      Number number)
Test if a number is in the range of the datatype double

Parameters:
number - a number
Returns:
true if the given number can be stored in a double


Copyright © 2012-2013. All Rights Reserved.