org.jrobin.core
Class Util

java.lang.Object
  extended by org.jrobin.core.Util

public class Util
extends java.lang.Object

Class defines various utility functions used in JRobin.


Nested Class Summary
static class Util.Xml
          Various DOM utility functions
 
Constructor Summary
Util()
           
 
Method Summary
static boolean equal(double x, double y)
          Compares two doubles, but returns true if x = y = Double.NaN
static java.util.Date getDate(long timestamp)
          Returns Date object for the given timestamp (in seconds, without milliseconds)
static java.lang.String getFileSeparator()
          Returns file system separator string.
static java.util.GregorianCalendar getGregorianCalendar(java.util.Date date)
          Returns GregorianCalendar object for the given Date object
static java.util.GregorianCalendar getGregorianCalendar(long timestamp)
          Returns GregorianCalendar object for the given timestamp (in seconds, without milliseconds)
static java.util.GregorianCalendar getGregorianCalendar(java.lang.String timeStr)
          Creates GregorianCalendar object from a string.
static java.lang.String getJRobinDemoDirectory()
          Returns path to directory used for placement of JRobin demo graphs and creates it if necessary.
static java.lang.String getJRobinDemoPath(java.lang.String filename)
          Returns full path to the file stored in the demo directory of JRobin
static java.lang.String getJRobinHomeDirectory()
          Returns the root directory of the JRobin distribution.
static java.lang.String getLapTime()
          Function used for debugging purposes and performance bottlenecks detection.
static long getTime()
          Returns current timestamp in seconds (without milliseconds).
static long getTimestamp()
          Just an alias for getTime() method.
static long getTimestamp(java.util.Date date)
          Returns timestamp (unix epoch) for the given Date object
static long getTimestamp(java.util.GregorianCalendar gc)
          Returns timestamp (unix epoch) for the given GregorianCalendar object
static long getTimestamp(int year, int month, int day)
          Returns timestamp (unix epoch) for the given year, month and day.
static long getTimestamp(int year, int month, int day, int hour, int min)
          Returns timestamp (unix epoch) for the given year, month, day, hour and minute.
static java.lang.String getUserHomeDirectory()
          Returns path to user's home directory.
static double max(double x, double y)
          Returns the greater of two double values, but treats NaN as the smallest possible value.
static double min(double x, double y)
          Returns the smaller of two double values, but treats NaN as the greatest possible value.
static long normalize(long timestamp, long step)
          Rounds the given timestamp to the nearest whole "e;step"e;.
static boolean parseBoolean(java.lang.String valueStr)
          Parses input string as a boolean value.
static double parseDouble(java.lang.String valueStr)
          Parses input string as a double value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

getTime

public static long getTime()
Returns current timestamp in seconds (without milliseconds). Returned timestamp is obtained with the following expression:

(System.currentTimeMillis() + 500L) / 1000L

Returns:
Current timestamp

getTimestamp

public static long getTimestamp()
Just an alias for getTime() method.

Returns:
Current timestamp (without milliseconds)

normalize

public static long normalize(long timestamp,
                             long step)
Rounds the given timestamp to the nearest whole "e;step"e;. Rounded value is obtained from the following expression:

timestamp - timestamp % step;

Parameters:
timestamp - Timestamp in seconds
step - Step in seconds
Returns:
"Rounded" timestamp

max

public static double max(double x,
                         double y)
Returns the greater of two double values, but treats NaN as the smallest possible value. Note that Math.max() behaves differently for NaN arguments.

Parameters:
x - an argument
y - another argument
Returns:
the lager of arguments

min

public static double min(double x,
                         double y)
Returns the smaller of two double values, but treats NaN as the greatest possible value. Note that Math.min() behaves differently for NaN arguments.

Parameters:
x - an argument
y - another argument
Returns:
the smaller of arguments

getDate

public static java.util.Date getDate(long timestamp)
Returns Date object for the given timestamp (in seconds, without milliseconds)

Parameters:
timestamp - Timestamp in seconds.
Returns:
Corresponding Date object.

getGregorianCalendar

public static java.util.GregorianCalendar getGregorianCalendar(long timestamp)
Returns GregorianCalendar object for the given timestamp (in seconds, without milliseconds)

Parameters:
timestamp - Timestamp in seconds.
Returns:
Corresponding GregorianCalendar object.

getGregorianCalendar

public static java.util.GregorianCalendar getGregorianCalendar(java.util.Date date)
Returns GregorianCalendar object for the given Date object

Parameters:
date - Date object
Returns:
Corresponding GregorianCalendar object.

getTimestamp

public static long getTimestamp(java.util.Date date)
Returns timestamp (unix epoch) for the given Date object

Parameters:
date - Date object
Returns:
Corresponding timestamp (without milliseconds)

getTimestamp

public static long getTimestamp(java.util.GregorianCalendar gc)
Returns timestamp (unix epoch) for the given GregorianCalendar object

Parameters:
gc - GregorianCalendar object
Returns:
Corresponding timestamp (without milliseconds)

getTimestamp

public static long getTimestamp(int year,
                                int month,
                                int day,
                                int hour,
                                int min)
Returns timestamp (unix epoch) for the given year, month, day, hour and minute.

Parameters:
year - Year
month - Month (zero-based)
day - Day in month
hour - Hour
min - Minute
Returns:
Corresponding timestamp

getTimestamp

public static long getTimestamp(int year,
                                int month,
                                int day)
Returns timestamp (unix epoch) for the given year, month and day.

Parameters:
year - Year
month - Month (zero-based)
day - Day in month
Returns:
Corresponding timestamp

parseDouble

public static double parseDouble(java.lang.String valueStr)
Parses input string as a double value. If the value cannot be parsed, Double.NaN is returned (NumberFormatException is never thrown).

Parameters:
valueStr - String representing double value
Returns:
a double corresponding to the input string

parseBoolean

public static boolean parseBoolean(java.lang.String valueStr)
Parses input string as a boolean value. The parser is case insensitive.

Parameters:
valueStr - String representing boolean value
Returns:
true, if valueStr equals to 'true', 'on', 'yes', 'y' or '1'; false in all other cases.

getFileSeparator

public static java.lang.String getFileSeparator()
Returns file system separator string.

Returns:
File system separator ("/" on Unix, "\" on Windows)

getUserHomeDirectory

public static java.lang.String getUserHomeDirectory()
Returns path to user's home directory.

Returns:
Path to users home directory, with file separator appended.

getJRobinDemoDirectory

public static java.lang.String getJRobinDemoDirectory()
Returns path to directory used for placement of JRobin demo graphs and creates it if necessary.

Returns:
Path to demo directory (defaults to $HOME/jrobin/) if directory exists or was successfully created. Null if such directory could not be created.

getJRobinDemoPath

public static java.lang.String getJRobinDemoPath(java.lang.String filename)
Returns full path to the file stored in the demo directory of JRobin

Parameters:
filename - Partial path to the file stored in the demo directory of JRobin (just name and extension, without parent directories)
Returns:
Full path to the file

getGregorianCalendar

public static java.util.GregorianCalendar getGregorianCalendar(java.lang.String timeStr)
Creates GregorianCalendar object from a string. The string should represent either a long integer (UNIX timestamp in seconds without milliseconds, like "1002354657") or a human readable date string in the format "yyyy-MM-dd HH:mm:ss" (like "2004-02-25 12:23:45").

Parameters:
timeStr - Input string
Returns:
GregorianCalendar object

getLapTime

public static java.lang.String getLapTime()
Function used for debugging purposes and performance bottlenecks detection. Probably of no use for end users of JRobin.

Returns:
String representing time in seconds since last getLapTime() method call.

getJRobinHomeDirectory

public static java.lang.String getJRobinHomeDirectory()
Returns the root directory of the JRobin distribution. Useful in some demo applications, probably of no use anywhere else.

The function assumes that all JRobin .class files are placed under the <root>/classes subdirectory and that all jars (libraries) are placed in the <root>/lib subdirectory (the original JRobin directory structure).

Returns:
absolute path to JRobin's home directory

equal

public static boolean equal(double x,
                            double y)
Compares two doubles, but returns true if x = y = Double.NaN

Parameters:
x - First double
y - Second double
Returns:
true, if doubles are equal, false otherwise.