|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jrobin.core.Util
public class Util
Class defines various utility functions used in JRobin.
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
|
Constructor Summary | |
---|---|
Util()
|
Method Summary | |
---|---|
static boolean |
equal(double x,
double y)
Compares two doubles but treats all NaNs as equal. |
static boolean |
fileExists(java.lang.String filename)
Checks if the file with the given file name exists |
static java.lang.String |
formatDouble(double x)
Formats double as a string using exponential notation (RRDTool like). |
static java.util.Calendar |
getCalendar(java.util.Date date)
Returns Calendar object for the given Date object |
static java.util.Calendar |
getCalendar(long timestamp)
Returns Calendar object for the given timestamp
(in seconds, without milliseconds) |
static java.util.Calendar |
getCalendar(java.lang.String timeStr)
Creates Calendar object from a string. |
static java.lang.String |
getCanonicalPath(java.lang.String path)
Returns canonical file path for the given file path |
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.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 |
getLastModified(java.lang.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(java.util.Calendar gc)
Returns timestamp (unix epoch) for the given Calendar object |
static long |
getTimestamp(java.util.Date date)
Returns timestamp (unix epoch) for the given Date 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 long |
getTimestamp(java.lang.String atStyleTimeSpec)
Parses at-style time specification and returns the corresponding timestamp. |
static long[] |
getTimestamps(java.lang.String atStyleTimeSpec1,
java.lang.String atStyleTimeSpec2)
Parses two related at-style time specifications and returns corresponding timestamps. |
static java.lang.String |
getUserHomeDirectory()
Returns path to user's home directory. |
static boolean |
isDouble(java.lang.String s)
Checks if a string can be parsed as double. |
static double |
max(double[] values)
Finds max value for an array of doubles (NaNs are ignored). |
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[] values)
Finds min 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 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 java.awt.Paint |
parseColor(java.lang.String valueStr)
Parses input string as color. |
static double |
parseDouble(java.lang.String valueStr)
Parses input string as a double value. |
static java.lang.String |
sprintf(java.lang.String format,
java.lang.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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final long MAX_LONG
public static final long MIN_LONG
public static final double MAX_DOUBLE
public static final double MIN_DOUBLE
Constructor Detail |
---|
public Util()
Method Detail |
---|
public static double[] toDoubleArray(long[] array)
public static long getTime()
(System.currentTimeMillis() + 500L) / 1000L
public static long getTimestamp()
getTime()
method.
public static long normalize(long timestamp, long step)
timestamp - timestamp % step;
timestamp
- Timestamp in secondsstep
- Step in seconds
public static double max(double x, double y)
Math.max()
behaves differently for NaN arguments.
x
- an argumenty
- another argument
public static double min(double x, double y)
Math.min()
behaves differently for NaN arguments.
x
- an argumenty
- another argument
public static double sum(double x, double y)
x
- First doubley
- Second double
Double.isNaN(x)? y: Double.isNaN(y)? x: x + y;
public static java.lang.String formatDouble(double x)
x
- value to be formatted
public static java.util.Date getDate(long timestamp)
Date
object for the given timestamp (in seconds, without
milliseconds)
timestamp
- Timestamp in seconds.
public static java.util.Calendar getCalendar(long timestamp)
Calendar
object for the given timestamp
(in seconds, without milliseconds)
timestamp
- Timestamp in seconds.
public static java.util.Calendar getCalendar(java.util.Date date)
Calendar
object for the given Date object
date
- Date object
public static long getTimestamp(java.util.Date date)
date
- Date object
public static long getTimestamp(java.util.Calendar gc)
gc
- Calendar object
public static long getTimestamp(int year, int month, int day, int hour, int min)
year
- Yearmonth
- Month (zero-based)day
- Day in monthhour
- Hourmin
- Minute
public static long getTimestamp(int year, int month, int day)
year
- Yearmonth
- Month (zero-based)day
- Day in month
public static long getTimestamp(java.lang.String atStyleTimeSpec) throws RrdException
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.
RrdException
- Thrown if invalid time specification is supplied.public static long[] getTimestamps(java.lang.String atStyleTimeSpec1, java.lang.String atStyleTimeSpec2) throws RrdException
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.
RrdException
- Thrown if any input time specification is invalid.public static double parseDouble(java.lang.String valueStr)
valueStr
- String representing double value
public static boolean isDouble(java.lang.String s)
s
- Input string
true
if the string can be parsed as double, false
otherwisepublic static boolean parseBoolean(java.lang.String valueStr)
valueStr
- String representing boolean value
true
, if valueStr equals to 'true', 'on', 'yes', 'y' or '1';
false
in all other cases.public static java.awt.Paint parseColor(java.lang.String valueStr) throws RrdException
valueStr
- Input string, for example #FFAA24, #AABBCC33, 010203 or ABC13E4F
RrdException
- If the input string is not 6 or 8 characters long (without optional '#')public static java.lang.String getFileSeparator()
public static java.lang.String getUserHomeDirectory()
public static java.lang.String getJRobinDemoDirectory()
public static java.lang.String getJRobinDemoPath(java.lang.String filename)
filename
- Partial path to the file stored in the demo directory of JRobin
(just name and extension, without parent directories)
public static java.util.Calendar getCalendar(java.lang.String timeStr)
timeStr
- Input string
public static java.lang.String getLapTime()
getLapTime()
method call.public static java.lang.String getJRobinHomeDirectory()
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).
public static boolean equal(double x, double y)
false
x
- the first valuey
- the second value
true
if x and y are both equal to Double.NaN, or if x == y. false
otherwisepublic static java.lang.String getCanonicalPath(java.lang.String path) throws java.io.IOException
path
- Absolute or relative file path
java.io.IOException
- Thrown if canonical file path could not be resolvedpublic static long getLastModified(java.lang.String file)
file
- File object representing file on the disk
public static boolean fileExists(java.lang.String filename)
filename
- File name
true
if file exists, false
otherwisepublic static double max(double[] values)
values
- Array of double values
public static double min(double[] values)
values
- Array of double values
public static java.lang.String sprintf(java.lang.String format, java.lang.Object... args)
format
- Format stringargs
- Arbitrary list of arguments
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |