JGAP

org.jgap.util
Class NumberKit

java.lang.Object
  extended by org.jgap.util.NumberKit

public class NumberKit
extends java.lang.Object

Utility routines related to numbers.

Since:
3.2

Constructor Summary
NumberKit()
           
 
Method Summary
static char[] asChars(byte a_in)
          Transforms a byte to a character array of hex octets.
static char[] asChars(byte a_in, int a_length)
          Transforms a byte to a character array of hex octets.
static int hexValue(char a_c)
          Returns the hex value of "c" or -1 if there is no corresponding hex value.
static java.lang.String niceDecimalNumber(double a_number, int a_decimals)
          Removes decimal places if there are more than a_decimals.
static java.lang.String niceNumber(int a_number, int a_places, char a_filler)
          Formats a number as a string having the total length of a_places, filling up needed characters with a_filler.
static short parseShort(java.lang.String s)
          Parses a short from a hex encoded number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumberKit

public NumberKit()
Method Detail

hexValue

public static int hexValue(char a_c)
Returns the hex value of "c" or -1 if there is no corresponding hex value.

Parameters:
a_c - hex character to convert
Returns:
integer value of the character
Since:
3.2

asChars

public static char[] asChars(byte a_in)
Transforms a byte to a character array of hex octets. Taken from UUID.

Parameters:
a_in - the byte
Returns:
the hex byte array

asChars

public static char[] asChars(byte a_in,
                             int a_length)
Transforms a byte to a character array of hex octets. Taken from UUID.

Parameters:
a_in - the byte
a_length - the number of octets to produce
Returns:
the hex byte array

parseShort

public static short parseShort(java.lang.String s)
                        throws java.lang.NullPointerException
Parses a short from a hex encoded number. This method will skip all characters that are not 0-9 and a-f (the String is lower cased first).

Parameters:
s - the String to extract a short from, may not be null
Returns:
0 if the String does not contain any interesting characters
Throws:
java.lang.NullPointerException - if the String is null
Since:
3.3.3

niceNumber

public static java.lang.String niceNumber(int a_number,
                                          int a_places,
                                          char a_filler)
Formats a number as a string having the total length of a_places, filling up needed characters with a_filler.

Parameters:
a_number - the number to format
a_places - total length of output string
a_filler - fill character
Returns:
formatted number
Since:
3.3.3

niceDecimalNumber

public static java.lang.String niceDecimalNumber(double a_number,
                                                 int a_decimals)
Removes decimal places if there are more than a_decimals.

Parameters:
a_number - the number to convert to a string
a_decimals - maximum number of decimal places allowed
Returns:
nicified string
Since:
3.3.3

JGAP