public class Util
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static long |
MILLIS_IN_DAY |
static long |
MILLIS_IN_HOUR |
static long |
MILLIS_IN_MINUTE |
static long |
MILLIS_IN_MONTH |
static long |
MILLIS_IN_WEEK |
static long |
MILLIS_IN_YEAR |
static int |
SECONDS_IN_DAY |
static int |
SECONDS_IN_HOUR |
static int |
SECONDS_IN_MINUTE |
static int |
SECONDS_IN_WEEK |
Constructor and Description |
---|
Util() |
Modifier and Type | Method and Description |
---|---|
static void |
calcLatestMA(DataContext ctx,
Enums.MAMethod method,
java.lang.Object input,
int period,
int shift,
java.lang.Object valKey,
boolean fillForward)
This convenience method updates the calculates a moving average of the current (latest) bar in the data series
and stores it in the internal data cache with key specified (@see valKey)
|
static void |
calcMAAt(int index,
DataContext ctx,
Enums.MAMethod method,
java.lang.Object input,
int period,
int shift,
java.lang.Object valKey)
This convenience method calculates the moving average at the given index in the data series
and stores it in the internal data cache with key specified (@see valKey)
|
static void |
calcSeriesMA(DataContext ctx,
Enums.MAMethod method,
java.lang.Object input,
int period,
int shift,
java.lang.Object valKey,
boolean fillForward)
This convenience method calculates a moving average for the visible bars in the data series
and stores it in the internal data cache with key specified (@see valKey)
|
static void |
calcSeriesMA(DataContext ctx,
Enums.MAMethod method,
java.lang.Object input,
int period,
int shift,
java.lang.Object valKey,
boolean fillForward,
boolean includeUnfinishedBars)
This convenience method calculates a moving average for the visible bars in the data series
and stores it in the internal data cache with key specified (@see valKey)
|
static double |
calculateAngle(double x1,
double y1,
double x2,
double y2)
Calculates the angle (in radians) between the two given points.
|
static double |
calculateAngle(java.awt.geom.Point2D start,
java.awt.geom.Point2D end)
Calculates the angle (in radians) between the two given points.
|
static double |
calculateAngle(java.awt.geom.Point2D origin,
java.awt.geom.Point2D end1,
java.awt.geom.Point2D end2)
Calculates the angle (in radians) between the two given points.
|
static java.awt.geom.Line2D |
clipLine(double x1,
double y1,
double x2,
double y2,
java.awt.geom.Rectangle2D bounds) |
static java.awt.geom.Line2D |
clipLine(java.awt.geom.Line2D line,
java.awt.geom.Rectangle2D bounds) |
static java.awt.geom.Line2D |
clipLine(java.awt.geom.Point2D p1,
java.awt.geom.Point2D p2,
java.awt.geom.Rectangle2D bounds)
Clips the line defined by the two given points to the bounds.
|
static boolean |
compare(java.lang.Object x,
java.lang.Object y)
Compares the two objects.
|
static java.awt.geom.Path2D |
createDownTriangle(int x,
int y,
int d)
Creates a triangle path pointing down.
|
static java.awt.geom.Path2D |
createUpTriangle(int x,
int y,
int d)
Creates a triangle path pointing up.
|
static double |
distance(double ux,
double uy,
double vx,
double vy) |
static double |
distance(java.awt.geom.Point2D p1,
int x,
int y) |
static double |
distance(java.awt.geom.Point2D p1,
java.awt.geom.Point2D p2)
Calculates and returns the distance between the two points.
|
static double |
distanceFromLine(double x,
double y,
double lx1,
double ly1,
double lx2,
double ly2)
Calculates distance from the given line.
|
static double |
distanceFromLine(double x,
double y,
java.awt.geom.Line2D line)
Calculates distance from the given line.
|
static double |
dot(double ux,
double uy,
double vx,
double vy) |
static java.lang.String |
formatMMDDYYYY(long date)
Formats the given date (in milliseconds since 1970) in MM/dd/yyyy format.
|
static java.lang.String |
formatMMDDYYYYHHMM(long date)
Formats the given date (in milliseconds since 1970) in MM/dd/yyyy h:mm a format.
|
static java.awt.Color |
getAlphaFill(java.awt.Color c) |
static java.awt.Color |
getAlphaFill(java.awt.Color c,
int alpha) |
static java.io.File |
getExtensionsDirectory()
Gets the extensions directory.
|
static long |
getMidnight(java.util.Calendar cal,
long time)
Gets the time in millis as of midnight on the morning of the specified date
|
static long |
getMidnight(long time)
Gets the time in millis as of midnight on the morning of the specified date
|
static long |
getMidnight(long time,
java.util.TimeZone tz)
Gets the time in millis as of midnight on the morning of the specified date
|
static long |
getMidnightEST(long time)
Gets the time in millis as of midnight on the morning of the specified date
|
static long |
getMidnightGMT(long time)
Gets the time in millis as of midnight on the morning of the specified date
|
static java.awt.Stroke |
getStroke(PathInfo path,
boolean selected) |
static boolean |
in(double i,
double[] list)
Determines if the given double value i is in the list of double values.
|
static boolean |
in(int i,
int[] list)
Returns true if the number i is in the search list
|
static boolean |
in(java.lang.Object o,
java.lang.Object... list)
Returns true if the Object o is in the search list
|
static boolean |
in(java.lang.String s,
java.lang.String... list)
Returns true if the String s is present in the list
|
static java.awt.geom.Point2D |
intersection(double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
double y4)
Computes the intersection between two segments.
|
static java.awt.geom.Point2D |
intersection(java.awt.geom.Line2D line1,
java.awt.geom.Line2D line2)
computes the intersection point between the two given lines.
|
static java.awt.geom.Point2D |
intersection(java.awt.geom.Point2D start1,
java.awt.geom.Point2D end1,
java.awt.geom.Point2D start2,
java.awt.geom.Point2D end2)
Computes the intersection point between the two lines defined by the pairs of start and end points.
|
static boolean |
isEmpty(java.lang.Object o)
Tests if an object is empty or null.
|
static double |
max(double... args) |
static double |
max(double someNumber,
double someOtherNumber)
Returns the greater number between someNumber and someOtherNumber.
|
static int |
max(int someNumber,
int someOtherNumber)
Returns the greater number between someNumber and someOtherNumber.
|
static java.lang.Double |
maxDouble(java.lang.Double... args) |
static int |
maxInt(int... args) |
static long |
maxLong(long... args) |
static java.awt.geom.Point2D |
midpoint(java.awt.geom.Line2D line)
Calculates and returns the midpoint of the given line.
|
static java.awt.geom.Point2D |
midpoint(java.awt.geom.Point2D start,
java.awt.geom.Point2D end)
Calculates and returns the midpoint of the line defined by the given points.
|
static double |
min(double... args) |
static java.lang.Double |
minDouble(java.lang.Double... args) |
static int |
minInt(int... args) |
static long |
minLong(long... args) |
static double |
norm(double vx,
double vy) |
static double |
radiansToDegrees(double rad)
Converts the given value in radians to degrees.
|
static java.lang.String |
replace(java.lang.String source,
java.lang.String[] patterns,
java.lang.String[] replacements)
Replaces occurences of the given pattern in the source string with the replacement value.
|
static java.lang.String |
replaceAll(java.lang.String source,
java.lang.String[] patterns,
java.lang.Object[] replacements)
Takes a collection of patterns (no support for regex), replacements and a target string.
|
static java.lang.String |
replaceAll(java.lang.String source,
java.lang.String[] patterns,
java.lang.String[] replacements)
Takes a collection of patterns (no support for regex), replacements and a target string.
|
static void |
replaceAll(java.io.Writer out,
java.lang.String source,
java.lang.String[] patterns,
java.lang.Object[] replacements)
Takes a collection of patterns (no support for regex), replacements and a target string.
|
static double[] |
rotate(double[] points,
double radians)
Rotates the given array of points and returns the result in a new array.
|
static java.awt.geom.Point2D |
rotate(java.awt.geom.Point2D p,
java.awt.geom.Point2D origin,
double radians)
Rotates the given point p about the given origin.
|
static double |
round(double val,
double step)
Rounds a double value using the given step (minimum value).
|
static double |
round(double val,
int places)
Round a double value to a specified number of decimal places.
|
static float |
round(float val,
float step)
Rounds a double value using the given step (minimum value).
|
static float |
round(float val,
int places)
Round a double value to a specified number of decimal places.
|
static double |
slope(double xl,
double yl,
double xr,
double yr)
Calculates the slope for the line defined by the given points.
|
static double |
slope(java.awt.geom.Line2D line)
Calculates the slope for the given line.
|
static double |
slope(java.awt.geom.Point2D start,
java.awt.geom.Point2D end)
Calculates the slope for the line defined by the given points.
|
static double |
toDouble(java.lang.Object value)
Converts the given object to an double.
|
static double |
toDouble(java.lang.Object value,
double def) |
static double |
toDouble(java.lang.String value) |
static int |
toInt(java.lang.Object value)
Converts the given object to an int.
|
public static final int SECONDS_IN_MINUTE
public static final int SECONDS_IN_HOUR
public static final int SECONDS_IN_DAY
public static final int SECONDS_IN_WEEK
public static final long MILLIS_IN_MINUTE
public static final long MILLIS_IN_HOUR
public static final long MILLIS_IN_DAY
public static final long MILLIS_IN_MONTH
public static final long MILLIS_IN_WEEK
public static final long MILLIS_IN_YEAR
public static java.io.File getExtensionsDirectory()
public static double round(double val, int places)
val
- the value to be rounded.places
- the number of decimal places to round to.public static double round(double val, double step)
val
- value to roundstep
- minimum value to roundpublic static float round(float val, int places)
val
- the value to be rounded.places
- the number of decimal places to round to.public static float round(float val, float step)
val
- value to roundstep
- minimum value to roundpublic static java.awt.geom.Path2D createDownTriangle(int x, int y, int d)
x
- x coordinatey
- y coordinated
- size of the trianglepublic static java.awt.geom.Path2D createUpTriangle(int x, int y, int d)
x
- x coordinatey
- y coordinated
- size of the trianglepublic static java.awt.geom.Point2D intersection(java.awt.geom.Point2D start1, java.awt.geom.Point2D end1, java.awt.geom.Point2D start2, java.awt.geom.Point2D end2)
start1
- start point of the first line.end1
- end point of the first line.start2
- start point of the second lineend2
- end point of the second linepublic static java.awt.geom.Point2D intersection(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
x1
- Starting point of Segment 1y1
- Starting point of Segment 1x2
- Ending point of Segment 1y2
- Ending point of Segment 1x3
- Starting point of Segment 2y3
- Starting point of Segment 2x4
- Ending point of Segment 2y4
- Ending point of Segment 2public static java.awt.geom.Point2D intersection(java.awt.geom.Line2D line1, java.awt.geom.Line2D line2)
public static java.awt.geom.Line2D clipLine(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, java.awt.geom.Rectangle2D bounds)
public static java.awt.geom.Line2D clipLine(double x1, double y1, double x2, double y2, java.awt.geom.Rectangle2D bounds)
public static java.awt.geom.Line2D clipLine(java.awt.geom.Line2D line, java.awt.geom.Rectangle2D bounds)
public static double[] rotate(double[] points, double radians)
public static java.awt.geom.Point2D midpoint(java.awt.geom.Line2D line)
public static java.awt.geom.Point2D midpoint(java.awt.geom.Point2D start, java.awt.geom.Point2D end)
public static java.awt.geom.Point2D rotate(java.awt.geom.Point2D p, java.awt.geom.Point2D origin, double radians)
public static double slope(java.awt.geom.Line2D line)
public static double slope(java.awt.geom.Point2D start, java.awt.geom.Point2D end)
public static double slope(double xl, double yl, double xr, double yr)
public static double radiansToDegrees(double rad)
public static double calculateAngle(double x1, double y1, double x2, double y2)
public static double calculateAngle(java.awt.geom.Point2D start, java.awt.geom.Point2D end)
public static double calculateAngle(java.awt.geom.Point2D origin, java.awt.geom.Point2D end1, java.awt.geom.Point2D end2)
public static double distanceFromLine(double x, double y, double lx1, double ly1, double lx2, double ly2)
public static double distanceFromLine(double x, double y, java.awt.geom.Line2D line)
public static double distance(double ux, double uy, double vx, double vy)
public static double distance(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
public static double distance(java.awt.geom.Point2D p1, int x, int y)
public static double norm(double vx, double vy)
public static double dot(double ux, double uy, double vx, double vy)
public static final boolean compare(java.lang.Object x, java.lang.Object y)
x
- The first objecty
- The second objectpublic static final boolean in(java.lang.String s, java.lang.String... list)
s
- The string to search forlist
- The list of parameters to searchpublic static final boolean in(java.lang.Object o, java.lang.Object... list)
o
- The object to search forlist
- The list of parameters to searchpublic static final boolean in(int i, int[] list)
i
- the number to search forlist
- The list of parameters to searchpublic static final boolean in(double i, double[] list)
public static final boolean isEmpty(java.lang.Object o)
o
- The object to testpublic static final java.awt.Color getAlphaFill(java.awt.Color c)
public static final java.awt.Color getAlphaFill(java.awt.Color c, int alpha)
public static final java.awt.Stroke getStroke(PathInfo path, boolean selected)
public static double min(double... args)
public static int minInt(int... args)
public static long minLong(long... args)
public static double max(double... args)
public static int maxInt(int... args)
public static java.lang.Double maxDouble(java.lang.Double... args)
public static java.lang.Double minDouble(java.lang.Double... args)
public static long maxLong(long... args)
public static int max(int someNumber, int someOtherNumber)
someNumber
- Some number.someOtherNumber
- Some other number (or the same number if you want).public static double max(double someNumber, double someOtherNumber)
someNumber
- Some number.someOtherNumber
- Some other number (or the same number if you want).public static final int toInt(java.lang.Object value)
value
- The value to convertpublic static final double toDouble(java.lang.Object value)
value
- The value to convertpublic static final double toDouble(java.lang.Object value, double def)
public static final double toDouble(java.lang.String value)
public static long getMidnight(long time)
time
- the day in millisecondspublic static long getMidnight(long time, java.util.TimeZone tz)
time
- the day in millisecondspublic static long getMidnightEST(long time)
time
- the day in millisecondspublic static long getMidnightGMT(long time)
time
- the day in millisecondspublic static long getMidnight(java.util.Calendar cal, long time)
time
- the day in millisecondspublic static java.lang.String formatMMDDYYYY(long date)
date
- milliseconds since 1970public static java.lang.String formatMMDDYYYYHHMM(long date)
date
- milliseconds since 1970public static void calcLatestMA(DataContext ctx, Enums.MAMethod method, java.lang.Object input, int period, int shift, java.lang.Object valKey, boolean fillForward)
ctx
- - Study contextmethod
- - Moving Average Methodinput
- - input type (high, low close etc)period
- - Period of the moving averageshift
- - number of bars to shift (left or right, negative value for left)valKey
- - id of the series of cached datafillForward
- - if true and shift is negative, add forward valuespublic static void calcSeriesMA(DataContext ctx, Enums.MAMethod method, java.lang.Object input, int period, int shift, java.lang.Object valKey, boolean fillForward, boolean includeUnfinishedBars)
ctx
- - Study contextmethod
- - Moving Average Methodinput
- - input type (high, low close etc)period
- - Period of the moving averageshift
- - number of bars to shift (left or right, negative value for left)valKey
- - id of the series of cached datafillForward
- - if true and shift is negative, add forward valuesincludeUnfinishedBars
- - if true, the latest incomplete bar is includedpublic static void calcSeriesMA(DataContext ctx, Enums.MAMethod method, java.lang.Object input, int period, int shift, java.lang.Object valKey, boolean fillForward)
ctx
- - Study contextmethod
- - Moving Average Methodinput
- - input type (high, low close etc)period
- - Period of the moving averageshift
- - number of bars to shift (left or right, negative value for left)valKey
- - id of the series of cached datafillForward
- - if true and shift is negative, add forward valuespublic static void calcMAAt(int index, DataContext ctx, Enums.MAMethod method, java.lang.Object input, int period, int shift, java.lang.Object valKey)
index
- index in the data seriesctx
- - Study contextmethod
- - Moving Average Methodinput
- - input type (high, low close etc)period
- - Period of the moving averageshift
- - number of bars to shift (left or right, negative value for left)valKey
- - id of the series of cached datapublic static final java.lang.String replaceAll(java.lang.String source, java.lang.String[] patterns, java.lang.String[] replacements)
source
- A string that may contain patterns that need to be replaced.patterns
- A collection of strings that need to be replaced (regex will not be parsed)replacements
- A collection of replacements. NOTE: The order of the replacements must corrispond
to the patterns they replace in the pattern collection.
EXAMPLE:public static final java.lang.String replaceAll(java.lang.String source, java.lang.String[] patterns, java.lang.Object[] replacements)
source
- A string that may contain patterns that need to be replaced.patterns
- A collection of strings that need to be replaced (regex will not be parsed)replacements
- A collection of replacements. NOTE: The order of the replacements must corrispond
to the patterns they replace in the pattern collection.
EXAMPLE:public static final void replaceAll(java.io.Writer out, java.lang.String source, java.lang.String[] patterns, java.lang.Object[] replacements) throws java.io.IOException
out
- output streamsource
- A string that may contain patterns that need to be replaced.patterns
- A collection of strings that need to be replaced (regex will not be parsed)replacements
- A collection of replacements. NOTE: The order of the replacements must corrispond
to the patterns they replace in the pattern collection.
EXAMPLE:java.io.IOException
public static final java.lang.String replace(java.lang.String source, java.lang.String[] patterns, java.lang.String[] replacements)
source
- source stringpatterns
- patterns to search forreplacements
- replacement strings