uk.ac.starlink.ttools.func
Class Conversions

java.lang.Object
  extended by uk.ac.starlink.ttools.func.Conversions

public class Conversions
extends Object

Functions for converting between strings and numeric values.

Since:
2 Sep 2004
Author:
Mark Taylor (Starlink)

Method Summary
static int fromHex(String hexVal)
          Converts a string representing a hexadecimal number to its integer value.
static byte parseByte(String str)
          Attempts to interpret a string as a byte (8-bit signed integer) value.
static double parseDouble(String str)
          Attempts to interpret a string as a double (64-bit signed integer) value.
static float parseFloat(String str)
          Attempts to interpret a string as a float (32-bit floating point) value.
static int parseInt(String str)
          Attempts to interpret a string as an int (32-bit signed integer) value.
static long parseLong(String str)
          Attempts to interpret a string as a long (64-bit signed integer) value.
static short parseShort(String str)
          Attempts to interpret a string as a short (16-bit signed integer) value.
static byte toByte(double value)
          Attempts to convert the numeric argument to a byte (8-bit signed integer) result.
static double toDouble(double value)
          Converts the numeric argument to a double (64-bit signed integer) result.
static float toFloat(double value)
          Attempts to convert the numeric argument to a float (32-bit floating point) result.
static String toHex(long value)
          Converts the integer argument to hexadecimal form.
static int toInteger(double value)
          Attempts to convert the numeric argument to an int (32-bit signed integer) result.
static long toLong(double value)
          Attempts to convert the numeric argument to a long (64-bit signed integer) result.
static short toShort(double value)
          Attempts to convert the numeric argument to a short (16-bit signed integer) result.
static String toString(boolean booleanVal)
          Turns a boolean value into a string.
static String toString(byte byteVal)
          Turns a byte value into a string.
static String toString(char charVal)
          Turns a single character value into a string.
static String toString(double fpVal)
          Turns a numeric value into a string.
static String toString(long intVal)
          Turns an integer numeric value into a string.
static String toString(Object objVal)
          Turns any object value into a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toString

public static String toString(double fpVal)
Turns a numeric value into a string.

Parameters:
fpVal - floating point numeric value
Returns:
a string representation of fpVal

toString

public static String toString(long intVal)
Turns an integer numeric value into a string.

Parameters:
intVal - integer numeric value
Returns:
a string representation of intVal

toString

public static String toString(char charVal)
Turns a single character value into a string.

Parameters:
charVal - character numeric value
Returns:
a string representation of charVal

toString

public static String toString(byte byteVal)
Turns a byte value into a string.

Parameters:
byteVal - byte numeric value
Returns:
a string representation of byteVal

toString

public static String toString(boolean booleanVal)
Turns a boolean value into a string.

Parameters:
booleanVal - boolean value (true or false)
Returns:
a string representation of booleanVal ("true" or "false")

toString

public static String toString(Object objVal)
Turns any object value into a string. As applied to existing string values this isn't really useful, but it means that you can apply toString to any object value without knowing its type and get a useful return from it.

Parameters:
objVal - non-primitive value
Returns:
a string representation of objVal

parseByte

public static byte parseByte(String str)
Attempts to interpret a string as a byte (8-bit signed integer) value. If the input string can't be interpreted in this way, a blank value will result.

Parameters:
str - string containing numeric representation
Returns:
byte value of str

parseShort

public static short parseShort(String str)
Attempts to interpret a string as a short (16-bit signed integer) value. If the input string can't be interpreted in this way, a blank value will result.

Parameters:
str - string containing numeric representation
Returns:
byte value of str

parseInt

public static int parseInt(String str)
Attempts to interpret a string as an int (32-bit signed integer) value. If the input string can't be interpreted in this way, a blank value will result.

Parameters:
str - string containing numeric representation
Returns:
byte value of str

parseLong

public static long parseLong(String str)
Attempts to interpret a string as a long (64-bit signed integer) value. If the input string can't be interpreted in this way, a blank value will result.

Parameters:
str - string containing numeric representation
Returns:
byte value of str

parseFloat

public static float parseFloat(String str)
Attempts to interpret a string as a float (32-bit floating point) value. If the input string can't be interpreted in this way, a blank value will result.

Parameters:
str - string containing numeric representation
Returns:
byte value of str

parseDouble

public static double parseDouble(String str)
Attempts to interpret a string as a double (64-bit signed integer) value. If the input string can't be interpreted in this way, a blank value will result.

Parameters:
str - string containing numeric representation
Returns:
byte value of str

toByte

public static byte toByte(double value)
Attempts to convert the numeric argument to a byte (8-bit signed integer) result. If it is out of range, a blank value will result.

Parameters:
value - numeric value for conversion
Returns:
value converted to type byte

toShort

public static short toShort(double value)
Attempts to convert the numeric argument to a short (16-bit signed integer) result. If it is out of range, a blank value will result.

Parameters:
value - numeric value for conversion
Returns:
value converted to type short

toInteger

public static int toInteger(double value)
Attempts to convert the numeric argument to an int (32-bit signed integer) result. If it is out of range, a blank value will result.

Parameters:
value - numeric value for conversion
Returns:
value converted to type int

toLong

public static long toLong(double value)
Attempts to convert the numeric argument to a long (64-bit signed integer) result. If it is out of range, a blank value will result.

Parameters:
value - numeric value for conversion
Returns:
value converted to type long

toFloat

public static float toFloat(double value)
Attempts to convert the numeric argument to a float (32-bit floating point) result. If it is out of range, a blank value will result.

Parameters:
value - numeric value for conversion
Returns:
value converted to type float

toDouble

public static double toDouble(double value)
Converts the numeric argument to a double (64-bit signed integer) result.

Parameters:
value - numeric value for conversion
Returns:
value converted to type double

toHex

public static String toHex(long value)
Converts the integer argument to hexadecimal form.

Parameters:
value - integer value
Returns:
hexadecimal representation of value

fromHex

public static int fromHex(String hexVal)
Converts a string representing a hexadecimal number to its integer value.

Parameters:
hexVal - hexadecimal representation of value
Returns:
integer value represented by hexVal


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.