cosmic.util
Class Misc

java.lang.Object
  |
  +--cosmic.util.Misc

public class Misc
extends java.lang.Object

General utility class with various value conversion and input methods. Author: James.A.Marshall@imperial.ac.uk


Field Summary
private static org.w3c.dom.Node msNodeReading
          The node currently being read in a DOM document (for error reporting)
 
Constructor Summary
private Misc()
          Private constructor for Misc class to prevent instantiation of Misc objects
 
Method Summary
static double getDoubleFromString(java.lang.String string)
          Gets a double from the specified string
static double getDoubleFromStringInInterval(java.lang.String string, double lowerBound, double upperBound, boolean closedLowerBound, boolean closedUpperBound)
          Gets a double from the specified string in the specified interval
static double getDoubleFromStringWithLowerBound(java.lang.String string, double lowerBound, boolean closedLowerBound)
          Gets a double from the specified string with the specified lower bound
static double getDoubleFromStringWithUpperBound(java.lang.String string, double upperBound, boolean closedUpperBound)
          Gets a double from the specified string with the specified upper bound
static org.w3c.dom.Node getFirstChildElementNode(org.w3c.dom.Node node)
          Gets the first child element node of the given input node in a DOM document
static int getIntegerFromString(java.lang.String string)
          Gets an integer from the specified string
static int getIntegerFromStringInInterval(java.lang.String string, int lowerBound, int upperBound, boolean closedLowerBound, boolean closedUpperBound)
          Gets an integer from the specified string in the specified interval
static int getIntegerFromStringWithLowerBound(java.lang.String string, int lowerBound, boolean closedLowerBound)
          Gets an integer from the specified string with the specified lower bound
static int getIntegerFromStringWithUpperBound(java.lang.String string, int upperBound, boolean closedUpperBound)
          Gets an integer from the specified string with the specified upper bound
static int getIntFromTwosComplementString(java.lang.String string)
          Converts a binary string in two's complement into an integer
static org.w3c.dom.Node getNextElementNode(org.w3c.dom.Node node)
          Gets the next element node after the given input node in a DOM document
static java.lang.String getNodeReadingName()
          Gets the name of the node currently being read in a DOM document
static java.lang.String getTwosComplementString(int sourceInt, int numBits)
          Converts a source integer to a binary string in two's complement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

msNodeReading

private static org.w3c.dom.Node msNodeReading
The node currently being read in a DOM document (for error reporting)

Constructor Detail

Misc

private Misc()
Private constructor for Misc class to prevent instantiation of Misc objects

Method Detail

getTwosComplementString

public static java.lang.String getTwosComplementString(int sourceInt,
                                                       int numBits)
Converts a source integer to a binary string in two's complement

Returns:
Binary string in two's complement
Throws:
java.lang.IllegalArgumentException - if source integer cannot be encoded in the specified number of bits

getIntFromTwosComplementString

public static int getIntFromTwosComplementString(java.lang.String string)
                                          throws java.lang.NumberFormatException
Converts a binary string in two's complement into an integer

Returns:
Integer value of two's complement binary string
Throws:
java.lang.NumberFormatException - if string is not a binary string

getIntegerFromString

public static int getIntegerFromString(java.lang.String string)
                                throws java.lang.NumberFormatException
Gets an integer from the specified string

Parameters:
string - (!= null)
Returns:
integer value of string
Throws:
java.lang.NumberFormatException - if string does not represent a valid integer

getIntegerFromStringInInterval

public static int getIntegerFromStringInInterval(java.lang.String string,
                                                 int lowerBound,
                                                 int upperBound,
                                                 boolean closedLowerBound,
                                                 boolean closedUpperBound)
                                          throws java.lang.NumberFormatException
Gets an integer from the specified string in the specified interval

Parameters:
string - (!= null)
Returns:
integer value of string
Throws:
java.lang.NumberFormatException - if string does not represent a valid integer
java.lang.IllegalArgumentException - if integer is not within interval

getIntegerFromStringWithLowerBound

public static int getIntegerFromStringWithLowerBound(java.lang.String string,
                                                     int lowerBound,
                                                     boolean closedLowerBound)
Gets an integer from the specified string with the specified lower bound

Parameters:
string - (!= null)
Returns:
integer value of string
Throws:
java.lang.NumberFormatException - if string does not represent a valid integer
java.lang.IllegalArgumentException - if integer violates lower bound

getIntegerFromStringWithUpperBound

public static int getIntegerFromStringWithUpperBound(java.lang.String string,
                                                     int upperBound,
                                                     boolean closedUpperBound)
Gets an integer from the specified string with the specified upper bound

Parameters:
string - (!= null)
Returns:
integer value of string
Throws:
java.lang.NumberFormatException - if string does not represent a valid integer
java.lang.IllegalArgumentException - if integer violates upper bound

getDoubleFromString

public static double getDoubleFromString(java.lang.String string)
                                  throws java.lang.NumberFormatException
Gets a double from the specified string

Parameters:
string - (!= null)
Returns:
double value of string
Throws:
java.lang.NumberFormatException - if string does not represent a valid double

getDoubleFromStringInInterval

public static double getDoubleFromStringInInterval(java.lang.String string,
                                                   double lowerBound,
                                                   double upperBound,
                                                   boolean closedLowerBound,
                                                   boolean closedUpperBound)
                                            throws java.lang.NumberFormatException
Gets a double from the specified string in the specified interval

Parameters:
string - (!= null)
Returns:
double value of string
Throws:
java.lang.NumberFormatException - if string does not represent a valid double
java.lang.IllegalArgumentException - if double is not within interval

getDoubleFromStringWithLowerBound

public static double getDoubleFromStringWithLowerBound(java.lang.String string,
                                                       double lowerBound,
                                                       boolean closedLowerBound)
Gets a double from the specified string with the specified lower bound

Parameters:
string - (!= null)
Returns:
double value of string
Throws:
java.lang.NumberFormatException - if string does not represent a valid double
java.lang.IllegalArgumentException - if double violates lower bound

getDoubleFromStringWithUpperBound

public static double getDoubleFromStringWithUpperBound(java.lang.String string,
                                                       double upperBound,
                                                       boolean closedUpperBound)
Gets a double from the specified string with the specified upper bound

Parameters:
string - (!= null)
Returns:
double value of string
Throws:
java.lang.NumberFormatException - if string does not represent a valid double
java.lang.IllegalArgumentException - if double violates upper bound

getFirstChildElementNode

public static org.w3c.dom.Node getFirstChildElementNode(org.w3c.dom.Node node)
Gets the first child element node of the given input node in a DOM document

Returns:
first child element node of input node (null indicates no child element node)

getNextElementNode

public static org.w3c.dom.Node getNextElementNode(org.w3c.dom.Node node)
Gets the next element node after the given input node in a DOM document

Returns:
next element node after input node (null indicates no next element node)

getNodeReadingName

public static java.lang.String getNodeReadingName()
Gets the name of the node currently being read in a DOM document

Returns:
name of the node currently being read (null indicates no node currently being read)