org.jrobin.core
public class Util extends Object
Nested Class Summary | |
---|---|
static class | Util.Xml
Various DOM utility functions |
Field Summary | |
---|---|
static double | MAX_DOUBLE |
static long | MAX_LONG |
static double | MIN_DOUBLE |
static long | MIN_LONG |
Method Summary | |
---|---|
static boolean | equal(double x, double y)
Compares two doubles but treats all NaNs as equal.
|
static boolean | fileExists(String filename)
Checks if the file with the given file name exists
|
static String | formatDouble(double x)
Formats double as a string using exponential notation (RRDTool like). |
static Calendar | getCalendar(long timestamp)
Returns Calendar object for the given timestamp
(in seconds, without milliseconds)
|
static Calendar | getCalendar(Date date)
Returns Calendar object for the given Date object
|
static Calendar | getCalendar(String timeStr)
Creates Calendar object from a string. |
static String | getCanonicalPath(String path)
Returns canonical file path for the given file path
|
static Date | getDate(long timestamp)
Returns Date object for the given timestamp (in seconds, without
milliseconds)
|
static String | getFileSeparator()
Returns file system separator string.
|
static String | getJRobinDemoDirectory()
Returns path to directory used for placement of JRobin demo graphs and creates it
if necessary.
|
static String | getJRobinDemoPath(String filename)
Returns full path to the file stored in the demo directory of JRobin
|
static String | getJRobinHomeDirectory()
Returns the root directory of the JRobin distribution. |
static String | getLapTime()
Function used for debugging purposes and performance bottlenecks detection.
|
static long | getLastModified(String file)
Returns last modification time for the given file.
|
static long | getTime()
Returns current timestamp in seconds (without milliseconds). |
static long | getTimestamp()
Just an alias for getTime method.
|
static long | getTimestamp(Date date)
Returns timestamp (unix epoch) for the given Date object
|
static long | getTimestamp(Calendar gc)
Returns timestamp (unix epoch) for the given Calendar object
|
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 long | getTimestamp(int year, int month, int day)
Returns timestamp (unix epoch) for the given year, month and day.
|
static long | getTimestamp(String atStyleTimeSpec)
Parses at-style time specification and returns the corresponding timestamp. |
static long[] | getTimestamps(String atStyleTimeSpec1, String atStyleTimeSpec2)
Parses two related at-style time specifications and returns corresponding timestamps. |
static String | getUserHomeDirectory()
Returns path to user's home directory.
|
static boolean | isDouble(String s)
Checks if a string can be parsed as double.
|
static double | max(double x, double y)
Returns the greater of two double values, but treats NaN as the smallest possible
value. |
static double | max(double[] values)
Finds max value for an array of doubles (NaNs are ignored). |
static double | min(double x, double y)
Returns the smaller of two double values, but treats NaN as the greatest possible
value. |
static double | min(double[] values)
Finds min value for an array of doubles (NaNs are ignored). |
static long | normalize(long timestamp, long step)
Rounds the given timestamp to the nearest whole "e;step"e;. |
static boolean | parseBoolean(String valueStr)
Parses input string as a boolean value. |
static Paint | parseColor(String valueStr)
Parses input string as color. |
static double | parseDouble(String valueStr)
Parses input string as a double value. |
static String | sprintf(String format, Object... args)
Equivalent of the C-style sprintf function. |
static double | sum(double x, double y)
Calculates sum of two doubles, but treats NaNs as zeros.
|
static double[] | toDoubleArray(long[] array)
Converts an array of long primitives to an array of doubles.
|
false
Parameters: x the first value y the second value
Returns: true
if x and y are both equal to Double.NaN, or if x == y. false
otherwise
Parameters: filename File name
Returns: true
if file exists, false
otherwise
Parameters: x value to be formatted
Returns: string like "+1.234567E+02"
Calendar
object for the given timestamp
(in seconds, without milliseconds)
Parameters: timestamp Timestamp in seconds.
Returns: Corresponding Calendar object.
Calendar
object for the given Date object
Parameters: date Date object
Returns: Corresponding Calendar object.
Parameters: timeStr Input string
Returns: Calendar object
Parameters: path Absolute or relative file path
Returns: Canonical file path
Throws: IOException Thrown if canonical file path could not be resolved
Date
object for the given timestamp (in seconds, without
milliseconds)
Parameters: timestamp Timestamp in seconds.
Returns: Corresponding Date object.
Returns: File system separator ("/" on Unix, "\" on Windows)
Returns: Path to demo directory (defaults to $HOME/jrobin/) if directory exists or was successfully created. Null if such directory could not be created.
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
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
Returns: String representing time in seconds since last
getLapTime()
method call.
Parameters: file File object representing file on the disk
Returns: Last modification time in seconds (without milliseconds)
(System.currentTimeMillis() + 500L) / 1000L
Returns: Current timestamp
Returns: Current timestamp (without milliseconds)
Parameters: date Date object
Returns: Corresponding timestamp (without milliseconds)
Parameters: gc Calendar object
Returns: Corresponding timestamp (without milliseconds)
Parameters: year Year month Month (zero-based) day Day in month hour Hour min Minute
Returns: Corresponding timestamp
Parameters: year Year month Month (zero-based) day Day in month
Returns: Corresponding timestamp
long t = Util.getTimestamp("now-1d");
Parameters: atStyleTimeSpec at-style time specification. For the complete explanation of the syntax
allowed see RRDTool's rrdfetch
man page.
Returns: timestamp in seconds since epoch.
Throws: RrdException Thrown if invalid time specification is supplied.
long[] t = Util.getTimestamps("end-1d","now");
Parameters: atStyleTimeSpec1 Starting at-style time specification. For the complete explanation of the syntax
allowed see RRDTool's rrdfetch
man page. atStyleTimeSpec2 Ending at-style time specification. For the complete explanation of the syntax
allowed see RRDTool's rrdfetch
man page.
Returns: An array of two longs representing starting and ending timestamp in seconds since epoch.
Throws: RrdException Thrown if any input time specification is invalid.
Returns: Path to users home directory, with file separator appended.
Parameters: s Input string
Returns: true
if the string can be parsed as double, false
otherwise
Math.max()
behaves differently for NaN arguments.
Parameters: x an argument y another argument
Returns: the lager of arguments
Parameters: values Array of double values
Returns: max value in the array (NaNs are ignored)
Math.min()
behaves differently for NaN arguments.
Parameters: x an argument y another argument
Returns: the smaller of arguments
Parameters: values Array of double values
Returns: min value in the array (NaNs are ignored)
timestamp - timestamp % step;
Parameters: timestamp Timestamp in seconds step Step in seconds
Returns: "Rounded" timestamp
Parameters: valueStr String representing boolean value
Returns: true
, if valueStr equals to 'true', 'on', 'yes', 'y' or '1';
false
in all other cases.
Parameters: valueStr Input string, for example #FFAA24, #AABBCC33, 010203 or ABC13E4F
Returns: Paint object
Throws: RrdException If the input string is not 6 or 8 characters long (without optional '#')
Parameters: valueStr String representing double value
Returns: a double corresponding to the input string
Parameters: format Format string args Arbitrary list of arguments
Returns: Formatted string
Parameters: x First double y Second double
Returns: Sum(x,y) calculated as Double.isNaN(x)? y: Double.isNaN(y)? x: x + y;
Returns: Same array but with all values as double.