public class Util extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Util.Xml
Various DOM utility functions.
|
| Modifier and Type | Field and Description |
|---|---|
(package private) static ThreadLocal<NumberFormat> |
df |
(package private) static String |
ISO_DATE_FORMAT |
static double |
MAX_DOUBLE
Constant
MAX_DOUBLE=Double.MAX_VALUE |
static long |
MAX_LONG
Constant
MAX_LONG=Long.MAX_VALUE |
static double |
MIN_DOUBLE
Constant
MIN_DOUBLE=-Double.MAX_VALUE |
static long |
MIN_LONG
Constant
MIN_LONG=-Long.MAX_VALUE |
(package private) static String |
PATTERN |
(package private) static String |
RRD4J_DIR |
| Modifier and Type | Method and Description |
|---|---|
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).
|
(package private) static String |
formatDouble(double x,
boolean forceExponents)
Formats a double value as a string with default NaN string.
|
(package private) static String |
formatDouble(double x,
String nanString,
boolean forceExponents)
Formats a double value as a string.
|
static Calendar |
getCalendar(Date date)
Returns
Calendar object for the given Date object |
static Calendar |
getCalendar(long timestamp)
Returns
Calendar object for the given timestamp (in seconds, without
milliseconds) |
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 |
getLapTime()
Function used for debugging purposes and performance bottlenecks detection.
|
static long |
getLastModifiedTime(String file)
Returns last modification time for the given file.
|
(package private) static int |
getMatchingArchiveIndex(RrdDb rrd1,
int arcIndex,
RrdDb rrd2) |
(package private) static int |
getMatchingDatasourceIndex(RrdDb rrd1,
int dsIndex,
RrdDb rrd2) |
static String |
getRrd4jDemoDirectory()
Returns path to directory used for placement of Rrd4j demo graphs and creates it if
necessary.
|
static String |
getRrd4jDemoPath(String filename)
Returns full path to the file stored in the demo directory of Rrd4j
|
static String |
getRrd4jHomeDirectory()
Returns the root directory of the Rrd4j distribution.
|
static long |
getTime()
Returns current timestamp in seconds (without milliseconds).
|
static long |
getTimestamp()
Just an alias for
getTime() method. |
static long |
getTimestamp(Calendar gc)
Returns timestamp (unix epoch) for the given Calendar object
|
static long |
getTimestamp(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(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.
|
(package private) static String |
getTmpFilename() |
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[] 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 "step".
|
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.
|
(package private) static boolean |
sameFilePath(String pathname1,
String pathname2) |
static String |
sprintf(Locale l,
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.
|
static final ThreadLocal<NumberFormat> df
static final String ISO_DATE_FORMAT
public static final double MAX_DOUBLE
MAX_DOUBLE=Double.MAX_VALUEpublic static final long MAX_LONG
MAX_LONG=Long.MAX_VALUEpublic static final double MIN_DOUBLE
MIN_DOUBLE=-Double.MAX_VALUEpublic static final long MIN_LONG
MIN_LONG=-Long.MAX_VALUEstatic final String PATTERN
static final String RRD4J_DIR
public static boolean equal(double x,
double y)
falsex - the first valuey - the second valuetrue if x and y are both equal to Double.NaN, or if x == y. false
otherwisepublic static boolean fileExists(String filename)
filename - File nametrue if file exists, false otherwisepublic static String formatDouble(double x)
x - value to be formattedstatic String formatDouble(double x, boolean forceExponents)
x - value to formatforceExponents - whether to force exponential notationstatic String formatDouble(double x, String nanString, boolean forceExponents)
x - value to formatnanString - string to use for NaN valuesforceExponents - whether to force exponential notationpublic static Calendar getCalendar(Date date)
Calendar object for the given Date objectdate - Date objectpublic static Calendar getCalendar(long timestamp)
Calendar object for the given timestamp (in seconds, without
milliseconds)timestamp - Timestamp in seconds.public static Calendar getCalendar(String timeStr)
timeStr - Input stringpublic static String getCanonicalPath(String path) throws IOException
path - Absolute or relative file pathIOException - Thrown if canonical file path could not be resolvedpublic static Date getDate(long timestamp)
Date object for the given timestamp (in seconds, without milliseconds)timestamp - Timestamp in seconds.public static String getFileSeparator()
public static String getLapTime()
getLapTime() method call.public static long getLastModifiedTime(String file) throws IOException
file - File object representing file on the diskIOExceptionstatic int getMatchingArchiveIndex(RrdDb rrd1, int arcIndex, RrdDb rrd2) throws IOException
IOExceptionstatic int getMatchingDatasourceIndex(RrdDb rrd1, int dsIndex, RrdDb rrd2) throws IOException
IOExceptionpublic static String getRrd4jDemoDirectory()
public static String getRrd4jDemoPath(String filename)
filename - Partial path to the file stored in the demo directory of Rrd4j (just name and
extension, without parent directories)public static String getRrd4jHomeDirectory()
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).
public static long getTime()
(System.currentTimeMillis() + 500L) / 1000L
public static long getTimestamp()
getTime() method.public static long getTimestamp(Calendar gc)
gc - Calendar objectpublic static long getTimestamp(Date date)
date - Date objectpublic static long getTimestamp(int year,
int month,
int day)
The date is resolved in the current time zone
year - Yearmonth - Month (zero-based)day - Day in monthpublic static long getTimestamp(int year,
int month,
int day,
int hour,
int min)
The date is resolved in the current time zone
year - Yearmonth - Month (zero-based)day - Day in monthhour - Hourmin - Minutepublic static long getTimestamp(String atStyleTimeSpec)
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.
public static long[] getTimestamps(String atStyleTimeSpec1, String atStyleTimeSpec2)
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.
static String getTmpFilename() throws IOException
IOExceptionpublic static String getUserHomeDirectory()
public static boolean isDouble(String s)
s - Input stringtrue if the string can be parsed as double, false otherwisepublic static double max(double[] values)
values - Array of double valuespublic static double max(double x,
double y)
Math.max() behaves differently for NaN arguments.x - an argumenty - another argumentpublic static double min(double[] values)
values - Array of double valuespublic static double min(double x,
double y)
Math.min() behaves differently for NaN arguments.x - an argumenty - another argumentpublic static long normalize(long timestamp,
long step)
timestamp - timestamp % step;
timestamp - Timestamp in secondsstep - Step in secondspublic static boolean parseBoolean(String valueStr)
valueStr - String representing boolean valuetrue, if valueStr equals to 'true', 'on', 'yes', 'y' or '1'; false
in all other cases.public static Paint parseColor(String valueStr)
valueStr - Input string, for example #FFAA24, #AABBCC33, 010203 or ABC13E4FIllegalArgumentException - If the input string is not 6 or 8 characters long
(without optional '#')public static double parseDouble(String valueStr)
valueStr - String representing double valuestatic boolean sameFilePath(String pathname1, String pathname2) throws IOException
IOExceptionpublic static String sprintf(Locale l, String format, Object... args)
format - Format stringargs - Arbitrary list of argumentsl - a Locale object.public static double sum(double x,
double y)
x - First doubley - Second doubleDouble.isNaN(x)? y: Double.isNaN(y)? x: x + y;public static double[] toDoubleArray(long[] array)
array - input array of long values.