p3j.misc
Class Misc

java.lang.Object
  extended by p3j.misc.Misc

public final class Misc
extends Object

Miscellaneous (auxiliary) functions and constants. For simulation-related constants, see Constants. Created on February 12, 2007

Author:
Christina Bohk, Roland Ewald

Field Summary
static int BASE_NUM
          Base of numerical system that is used.
static String CONFIG_FILE
          The name of the configuration file.
static james.core.data.DBConnectionData DEFAULT_DB_CONN
          Default setup for database connection.
static String DEFAULT_DB_PWD
          The default database password.
static String DEFAULT_DB_URL
          The default datbase URL.
static String DEFAULT_DB_USER
          The default database user name.
static ExecutionMode DEFAULT_EXEC_MODE
          The default execution mode.
static String DEFAULT_HIBERNATE_CONFIG_FILE
          The default location of the hibernate configuration file.
static int DEFAULT_NUM_PARALLEL_THREADS
          The default number of parallel threads.
static int DEFAULT_NUM_TRIALS
          The default number of trials.
static double EPSILON
          Minimal precision value (used to avoid rounding problems).
static String GUI_LABEL_DESCENDANT_GENERATIONS
          The number of descendant generations.
static String GUI_LABEL_DESCRIPTION
          The Constant GUI_LABEL_DESCRIPTION.
static String GUI_LABEL_DEVIATION
          The Constant GUI_LABEL_DEVIATION.
static String GUI_LABEL_JUMP_OFF_YEAR
          The label for the jump-off year in the GUI.
static String GUI_LABEL_NAME
          The Constant GUI_LABEL_NAME.
static String GUI_LABEL_NUM_AGE_CLASSES
          The number of age classes.
static String GUI_LABEL_PROBABILITY
          The Constant GUI_LABEL_PROBABILITY.
static String GUI_LABEL_PROJECTION_HORIZON
          The projection horizon.
static DecimalFormat NUMBER_FORMAT
          Number format to be used when editing matrices.
static String PREF_DB_PWD
          The key for the database password.
static String PREF_DB_URL
          The key for the database URL.
static String PREF_DB_USER
          The key for the database user name.
static String PREF_EXECUTION_MODE
          The key for the execution mode.
static String PREF_NUM_PARALLEL_THREADS
          The key for the number of parallel threads.
static String PREF_NUM_TRIALS
          The key for the number of trials.
static String TEST_HIBERNATE_CONFIG_FILE
          The default location of the hibernate configuration file for testing.
 
Method Summary
static
<X> X
autoCast(Object o)
          Auto-casts any kind of object to the desired case.
static boolean checkClassEquality(Class<?> class1, Class<?> class2)
          Checks whether two classes are the same.
static String getCleanedClassName(Class<?> theClass)
          Cleans up class name by removing everything after '_$$_', which is used by Hibernate to identify generated custom classes ('my.Class_$$_javassist...').
static String getFileEnding(File file)
          Retrieves file ending.
static
<X,Y> void
invertMap(Map<X,Y> src, Map<Y,X> dest)
          Inverts a map.
static
<D> List<D>
mergeList(List<D>... listsToMerge)
          Merges list of lists to a newly created ArrayList.
static boolean numEqual(double x, double y)
          Two values are recognised as equal as long as their absolute differece does not exceed EPSILON.
static double parseToDouble(Object value)
          Parses string to double.
static double parseToDoubleProb(String probString)
          Converts a string into a probability (a double that has to be in [0,1]).
static int parseToInt(String numString)
          Parses string to integer.
static double round(double value, int digits)
          Rounds a value to a certain number of digits after the comma.
static void writeDocumentToFile(String fileName, Document document)
          Deprecated. 
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BASE_NUM

public static final int BASE_NUM
Base of numerical system that is used.

See Also:
Constant Field Values

NUMBER_FORMAT

public static final DecimalFormat NUMBER_FORMAT
Number format to be used when editing matrices.


EPSILON

public static final double EPSILON
Minimal precision value (used to avoid rounding problems).

See Also:
Constant Field Values

CONFIG_FILE

public static final String CONFIG_FILE
The name of the configuration file.

See Also:
Constant Field Values

DEFAULT_DB_URL

public static final String DEFAULT_DB_URL
The default datbase URL.

See Also:
Constant Field Values

DEFAULT_DB_USER

public static final String DEFAULT_DB_USER
The default database user name.

See Also:
Constant Field Values

DEFAULT_DB_PWD

public static final String DEFAULT_DB_PWD
The default database password.

See Also:
Constant Field Values

DEFAULT_EXEC_MODE

public static final ExecutionMode DEFAULT_EXEC_MODE
The default execution mode.


DEFAULT_DB_CONN

public static final james.core.data.DBConnectionData DEFAULT_DB_CONN
Default setup for database connection.


DEFAULT_HIBERNATE_CONFIG_FILE

public static final String DEFAULT_HIBERNATE_CONFIG_FILE
The default location of the hibernate configuration file.

See Also:
Constant Field Values

TEST_HIBERNATE_CONFIG_FILE

public static final String TEST_HIBERNATE_CONFIG_FILE
The default location of the hibernate configuration file for testing.

See Also:
Constant Field Values

DEFAULT_NUM_TRIALS

public static final int DEFAULT_NUM_TRIALS
The default number of trials.

See Also:
Constant Field Values

DEFAULT_NUM_PARALLEL_THREADS

public static final int DEFAULT_NUM_PARALLEL_THREADS
The default number of parallel threads.

See Also:
Constant Field Values

PREF_DB_URL

public static final String PREF_DB_URL
The key for the database URL.

See Also:
Constant Field Values

PREF_DB_USER

public static final String PREF_DB_USER
The key for the database user name.

See Also:
Constant Field Values

PREF_DB_PWD

public static final String PREF_DB_PWD
The key for the database password.

See Also:
Constant Field Values

PREF_NUM_TRIALS

public static final String PREF_NUM_TRIALS
The key for the number of trials.

See Also:
Constant Field Values

PREF_NUM_PARALLEL_THREADS

public static final String PREF_NUM_PARALLEL_THREADS
The key for the number of parallel threads.

See Also:
Constant Field Values

PREF_EXECUTION_MODE

public static final String PREF_EXECUTION_MODE
The key for the execution mode.

See Also:
Constant Field Values

GUI_LABEL_PROBABILITY

public static final String GUI_LABEL_PROBABILITY
The Constant GUI_LABEL_PROBABILITY.

See Also:
Constant Field Values

GUI_LABEL_NAME

public static final String GUI_LABEL_NAME
The Constant GUI_LABEL_NAME.

See Also:
Constant Field Values

GUI_LABEL_DESCRIPTION

public static final String GUI_LABEL_DESCRIPTION
The Constant GUI_LABEL_DESCRIPTION.

See Also:
Constant Field Values

GUI_LABEL_DEVIATION

public static final String GUI_LABEL_DEVIATION
The Constant GUI_LABEL_DEVIATION.

See Also:
Constant Field Values

GUI_LABEL_JUMP_OFF_YEAR

public static final String GUI_LABEL_JUMP_OFF_YEAR
The label for the jump-off year in the GUI.

See Also:
Constant Field Values

GUI_LABEL_NUM_AGE_CLASSES

public static final String GUI_LABEL_NUM_AGE_CLASSES
The number of age classes.

See Also:
Constant Field Values

GUI_LABEL_DESCENDANT_GENERATIONS

public static final String GUI_LABEL_DESCENDANT_GENERATIONS
The number of descendant generations.

See Also:
Constant Field Values

GUI_LABEL_PROJECTION_HORIZON

public static final String GUI_LABEL_PROJECTION_HORIZON
The projection horizon.

See Also:
Constant Field Values
Method Detail

getFileEnding

public static String getFileEnding(File file)
Retrieves file ending.

Parameters:
file - the file name
Returns:
file ending

parseToDouble

public static double parseToDouble(Object value)
Parses string to double. Replaces ',' by '.'.

Parameters:
value - string to be parsed
Returns:
double value

parseToDoubleProb

public static double parseToDoubleProb(String probString)
Converts a string into a probability (a double that has to be in [0,1]).

Parameters:
probString - string containing a probability
Returns:
double value if valid, otherwise 0

numEqual

public static boolean numEqual(double x,
                               double y)
Two values are recognised as equal as long as their absolute differece does not exceed EPSILON.

Parameters:
x - the first value
y - the second value
Returns:
true if |x-y| < e

parseToInt

public static int parseToInt(String numString)
Parses string to integer.

Parameters:
numString - the string containing the number
Returns:
integer value of string

round

public static double round(double value,
                           int digits)
Rounds a value to a certain number of digits after the comma.

Parameters:
value - the value
digits - the desired maximum number of digits after the comma
Returns:
value value rounded to a given number of digits after the comma

writeDocumentToFile

@Deprecated
public static void writeDocumentToFile(String fileName,
                                                  Document document)
                                throws FileNotFoundException,
                                       TransformerException
Deprecated. 

Writes a document to a file.

Parameters:
fileName - the name of the file
document - the document to be written
Throws:
FileNotFoundException - if destination file could not be found/created
TransformerException - if transformation of document to XML failed

autoCast

public static <X> X autoCast(Object o)
Auto-casts any kind of object to the desired case. This is a work-around for Java's many insufficiencies regarding generics etc. Handle with care, only use this when you know what you are doing!

Type Parameters:
X - the desired type
Parameters:
o - the object
Returns:
the object, now casted to the desired type

checkClassEquality

public static boolean checkClassEquality(Class<?> class1,
                                         Class<?> class2)
Checks whether two classes are the same. This is tricky here: Hibernate enhances/replaces existing types, so classes from DB and from JVM are not the same! Classes for the DB have '_$$_...' etc. with them.

Parameters:
class1 - one class
class2 - the other class
Returns:
true if classes are the same, otherwise false

getCleanedClassName

public static String getCleanedClassName(Class<?> theClass)
Cleans up class name by removing everything after '_$$_', which is used by Hibernate to identify generated custom classes ('my.Class_$$_javassist...').

Parameters:
theClass - the class for which the name should be cleaned up
Returns:
the cleaned-up class name

mergeList

public static <D> List<D> mergeList(List<D>... listsToMerge)
Merges list of lists to a newly created ArrayList.

Type Parameters:
D - the type of the list elements
Parameters:
listsToMerge - the lists to merge
Returns:
the new list, containing all elements of the others

invertMap

public static <X,Y> void invertMap(Map<X,Y> src,
                                   Map<Y,X> dest)
Inverts a map.

Type Parameters:
X - the type of the original keys
Y - the type of the original values
Parameters:
src - the content
dest - the destination map to be filled (will be cleared at first)


Copyright © 2012. All Rights Reserved.