java.lang.Object | |
↳ | org.rrd4j.core.Util |
Class defines various utility functions used in Rrd4j.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Util.Xml | Various DOM utility functions. |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
double | MAX_DOUBLE | ||||||||||
long | MAX_LONG | ||||||||||
double | MIN_DOUBLE | ||||||||||
long | MIN_LONG |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Compares two doubles but treats all NaNs as equal.
| |||||||||||
Checks if the file with the given file name exists
| |||||||||||
Formats double as a string using exponential notation (RRDTool like).
| |||||||||||
Returns
Calendar object for the given Date object | |||||||||||
Returns
Calendar object for the given timestamp
(in seconds, without milliseconds) | |||||||||||
Creates Calendar object from a string.
| |||||||||||
Returns canonical file path for the given file path
| |||||||||||
Returns
Date object for the given timestamp (in seconds, without
milliseconds) | |||||||||||
Returns file system separator string.
| |||||||||||
Function used for debugging purposes and performance bottlenecks detection.
| |||||||||||
Returns last modification time for the given file.
| |||||||||||
Returns path to directory used for placement of Rrd4j demo graphs and creates it
if necessary.
| |||||||||||
Returns full path to the file stored in the demo directory of Rrd4j
| |||||||||||
Returns the root directory of the Rrd4j distribution.
| |||||||||||
Returns current timestamp in seconds (without milliseconds).
| |||||||||||
Returns timestamp (unix epoch) for the given Date object
| |||||||||||
Returns timestamp (unix epoch) for the given Calendar object
| |||||||||||
Just an alias for
getTime() method. | |||||||||||
Parses at-style time specification and returns the corresponding timestamp.
| |||||||||||
Returns timestamp (unix epoch) for the given year, month, day, hour and minute.
| |||||||||||
Returns timestamp (unix epoch) for the given year, month and day.
| |||||||||||
Parses two related at-style time specifications and returns corresponding timestamps.
| |||||||||||
Returns path to user's home directory.
| |||||||||||
Checks if a string can be parsed as double.
| |||||||||||
Finds max value for an array of doubles (NaNs are ignored).
| |||||||||||
Returns the greater of two double values, but treats NaN as the smallest possible
value.
| |||||||||||
Finds min value for an array of doubles (NaNs are ignored).
| |||||||||||
Returns the smaller of two double values, but treats NaN as the greatest possible
value.
| |||||||||||
Rounds the given timestamp to the nearest whole "e;step"e;.
| |||||||||||
Parses input string as a boolean value.
| |||||||||||
Parses input string as color.
| |||||||||||
Parses input string as a double value.
| |||||||||||
Equivalent of the C-style sprintf function.
| |||||||||||
Calculates sum of two doubles, but treats NaNs as zeros.
| |||||||||||
Converts an array of long primitives to an array of doubles.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Compares two doubles but treats all NaNs as equal.
In Java (by default) Double.NaN == Double.NaN always returns false
x | the first value |
---|---|
y | the second value |
true
if x and y are both equal to Double.NaN, or if x == y. false
otherwise
Checks if the file with the given file name exists
filename | File name |
---|
true
if file exists, false
otherwise
Formats double as a string using exponential notation (RRDTool like). Used for debugging throught the project.
x | value to be formatted |
---|
Returns Calendar
object for the given Date object
date | Date object |
---|
Returns Calendar
object for the given timestamp
(in seconds, without milliseconds)
timestamp | Timestamp in seconds. |
---|
Creates Calendar 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").
timeStr | Input string |
---|
Returns canonical file path for the given file path
path | Absolute or relative file path |
---|
IOException | Thrown if canonical file path could not be resolved |
---|
Returns Date
object for the given timestamp (in seconds, without
milliseconds)
timestamp | Timestamp in seconds. |
---|
Returns file system separator string.
Function used for debugging purposes and performance bottlenecks detection. Probably of no use for end users of Rrd4j.
getLapTime()
method call.
Returns last modification time for the given file.
file | File object representing file on the disk |
---|
Returns path to directory used for placement of Rrd4j demo graphs and creates it if necessary.
Returns full path to the file stored in the demo directory of Rrd4j
filename | Partial path to the file stored in the demo directory of Rrd4j (just name and extension, without parent directories) |
---|
Returns the root directory of the Rrd4j distribution. Useful in some demo applications, probably of no use anywhere else.
The function assumes that all Rrd4j .class files are placed under the <root>/classes subdirectory and that all jars (libraries) are placed in the <root>/lib subdirectory (the original Rrd4j directory structure).
Returns current timestamp in seconds (without milliseconds). Returned timestamp is obtained with the following expression:
(System.currentTimeMillis() + 500L) / 1000L
Returns timestamp (unix epoch) for the given Date object
date | Date object |
---|
Returns timestamp (unix epoch) for the given Calendar object
gc | Calendar object |
---|
Just an alias for getTime()
method.
Parses at-style time specification and returns the corresponding timestamp. For example:
long t = Util.getTimestamp("now-1d");
atStyleTimeSpec | at-style time specification. For the complete explanation of the syntax
allowed see RRDTool's rrdfetch man page. |
---|
Returns timestamp (unix epoch) for the given year, month, day, hour and minute.
year | Year |
---|---|
month | Month (zero-based) |
day | Day in month |
hour | Hour |
min | Minute |
Returns timestamp (unix epoch) for the given year, month and day.
year | Year |
---|---|
month | Month (zero-based) |
day | Day in month |
Parses two related at-style time specifications and returns corresponding timestamps. For example:
long[] t = Util.getTimestamps("end-1d","now");
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 path to user's home directory.
Checks if a string can be parsed as double.
s | Input string |
---|
true
if the string can be parsed as double, false
otherwise
Finds max value for an array of doubles (NaNs are ignored). If all values in the array are NaNs, NaN is returned.
values | Array of double values |
---|
Returns the greater of two double values, but treats NaN as the smallest possible
value. Note that Math.max()
behaves differently for NaN arguments.
x | an argument |
---|---|
y | another argument |
Finds min value for an array of doubles (NaNs are ignored). If all values in the array are NaNs, NaN is returned.
values | Array of double values |
---|
Returns the smaller of two double values, but treats NaN as the greatest possible
value. Note that Math.min()
behaves differently for NaN arguments.
x | an argument |
---|---|
y | another argument |
Rounds the given timestamp to the nearest whole "e;step"e;. Rounded value is obtained from the following expression:
timestamp - timestamp % step;
timestamp | Timestamp in seconds |
---|---|
step | Step in seconds |
Parses input string as a boolean value. The parser is case insensitive.
valueStr | String representing boolean value |
---|
true
, if valueStr equals to 'true', 'on', 'yes', 'y' or '1';
false
in all other cases.
Parses input string as color. The color string should be of the form #RRGGBB (no alpha specified, opaque color) or #RRGGBBAA (alpa specified, transparent colors). Leading character '#' is optional.
valueStr | Input string, for example #FFAA24, #AABBCC33, 010203 or ABC13E4F |
---|
IllegalArgumentException | If the input string is not 6 or 8 characters long (without optional '#') |
---|
Parses input string as a double value. If the value cannot be parsed, Double.NaN is returned (NumberFormatException is never thrown).
valueStr | String representing double value |
---|
Equivalent of the C-style sprintf function.
format | Format string |
---|---|
args | Arbitrary list of arguments |
Calculates sum of two doubles, but treats NaNs as zeros.
x | First double |
---|---|
y | Second double |
Double.isNaN(x)? y: Double.isNaN(y)? x: x + y;
Converts an array of long primitives to an array of doubles.