org.jgap.util
Class NumberKit
- java.lang.Object
-
- org.jgap.util.NumberKit
-
public class NumberKit extends java.lang.ObjectUtility routines related to numbers.- Since:
- 3.2
-
-
Constructor Summary
Constructors Constructor and Description NumberKit()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description 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 inthexValue(char a_c)Returns the hex value of "c" or -1 if there is no corresponding hex value.static java.lang.StringniceDecimalNumber(double a_number, int a_decimals)Removes decimal places if there are more than a_decimals.static java.lang.StringniceNumber(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 shortparseShort(java.lang.String s)Parses a short from a hex encoded number.
-
-
-
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 bytea_length- the number of octets to produce- Returns:
- the hex byte array
-
parseShort
public static short parseShort(java.lang.String s) throws java.lang.NullPointerExceptionParses 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 formata_places- total length of output stringa_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 stringa_decimals- maximum number of decimal places allowed- Returns:
- nicified string
- Since:
- 3.3.3
-
-
DMelt 3.0 © DataMelt by jWork.ORG