Class JxnUtilities
- java.lang.Object
-
- JxnUtilities
-
public class JxnUtilities extends Object
Collection of methods in the following sections:
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
__1_fileDialog()
protected void
__2_plot_and_curve()
protected void
__3_formatting_to_String()
protected void
__4_hex_formatting()
Adds to hex formatting and parsing methods.protected void
__5_ClassExplorer()
protected void
__6_extensions_to_Math()
Collection of methods adding tojava.lang.Math
.protected void
__7_setField()
Set public fields of an object or a class.protected void
__8_array_operations()
protected void
__9_boolean_operators()
protected void
_10_bitwise_operators()
protected void
_11_relational_operators()
protected void
_12_formula_switching()
static double
abs(double x, double y)
Returnssqrt( x * x + y * y )
.static double
abs(double x, double y, double z)
Returnssqrt( x * x + y * y + z * z )
.static double
acosD(double a)
CallsMath.acos(double)
and converts the result from radians to degrees.static double
acosh(double x)
Returns the inverse ofMath.cosh(double)
.static Object
add(byte[] array, int i, byte value)
Addsvalue
toarray[i]
with overflow, if the result does not fit into byte.static Object
add(double[] array, int i, double value)
Addsvalue
toarray[i]
.static Object
add(int[] array, int i, int value)
Addsvalue
toarray[i]
.static Object
add(long[] array, int i, long value)
Addsvalue
toarray[i]
.static String
addLeadingBlanks(String text, int n)
Prefixestext
with blanks so that the result contains at leastn
characters.static String
addLeadingChars(String text, int n, char ch)
Prefixestext
withch
so that the result contains at leastn
characters.static String
addLeadingZeros(String text, int n)
Prefixestext
with'0'
so that the result contains at leastn
characters.static String
addTrailingChars(String text, int n, char ch)
Appendstext
withch
so that the result contains at leastn
characters.static boolean
all(boolean[] array)
Returns true, if all values inarray
are true.static boolean
and(boolean x, boolean y)
Represents the Java boolean operator.static int
and(int x, int y)
Represents the Java bitwise operator (for int).static long
and(long x, long y)
Represents the Java bitwise operator (for long).static boolean
any(boolean[] array)
Returns true, if at least one value inarray
is true.static double
asinD(double a)
CallsMath.asin(double)
and converts the result from radians to degrees.static double
asinh(double x)
Returns the inverse ofMath.sinh(double)
.static double
atan2D(double y, double x)
CallsMath.atan2(double, double)
and converts the result from radians to degrees.static double
atanD(double a)
CallsMath.atan(double)
and converts the result from radians to degrees.static double
atanh(double x)
Returns the inverse ofMath.tanh(double)
.static Object
booleanArray(int length, boolean initial)
Creates a new boolean array with the specified length, initialized withinitial
.static Object
byteArray(int length)
Creates a new byte array with the specified length.static Object
byteArray(int length, byte initial)
Creates a new byte array with the specified length, initialized withinitial
.static double
clip(double x, double lower, double upper)
Returnsx
limitted bylower
andupper
.static Object
concat(Object... arrays)
Returns a new array containing the elements of all arrays passed as arguments.static Object
concat(Object arr1, Object arr2)
Returns a new array containing the elements of arrayarr1
followed by the elements of arrayarr2
.static boolean
contains(String chars, char ch)
Returns true ifchars
containsch
.static double
cosD(double a)
CallsMath.cos(double)
after converting argumenta
from degrees to radians.static double[]
cumulated(double[] array)
Returns a new array containing the partial (cumulated) sums of the values ofarray
.static int[]
cumulated(int[] array)
Returns a new array containing the partial (cumulated) sums of the values ofarray
.static long[]
cumulated(long[] array)
Returns a new array containing the partial (cumulated) sums of the values ofarray
.static JxnRealArrayCurve
curve(double[] x, double[] y, double[] z, IKmg3DProjection p3d)
Deprecated.Useplot(p3d)
.add( x, y, z )
.static JxnRealArrayCurve
curve(double[] x, double[] y, double[] z, IKmg3DProjection p3d, Color color)
Deprecated.static JxnRealArrayCurve
curve(double[] x, double[] y, double[] z, IKmg3DProjection p3d, Color color, int lineType)
Deprecated.static JxnRealArrayCurve
curve(double[] x, double[] y, Color color)
Returns a curve representation ofx
andy
( xi = x[i], yi = y[i] ).static JxnRealArrayCurve
curve(double[] x, double[] y, Color color, int lineType)
Seecurve
.static JxnRealArrayCurve
curve(double[] y, Color color)
Returns a curve representation ofy
( xi = i, yi = y[i] ).static JxnRealArrayCurve
curve(double[] y, Color color, int lineType)
Seecurve
.static double[]
differences(double[] array)
Returns a new array containing the differences of subsequent values ofarray
.static int[]
differences(int[] array)
Returns a new array containing the differences of subsequent values ofarray
.static long[]
differences(long[] array)
Returns a new array containing the differences of subsequent values ofarray
.static Object
doubleArray(int length)
Creates a new double array with the specified length.static Object
doubleArray(int length, double initial)
Creates a new double array with the specified length, initialized withinitial
.static double[]
doubleArray(String csvList)
Deprecated.In JXN prefer{ 2., 3., 5., 7. }
.static boolean
eq(boolean x, boolean y)
Represents the Java relational operator.static boolean
eq(double x, double y)
Represents the Java relational operator.static boolean
eq(long x, long y)
Represents the Java relational operator.static boolean
equals(Object o1, Object o2)
Deprecated.No more needed: Simply callo1.equals(o2)
.static boolean
exor(boolean x, boolean y)
Represents the Java boolean operator.static int
exor(int x, int y)
Represents the Java bitwise operator (for int).static long
exor(long x, long y)
Represents the Java bitwise operator (for long).static String
fileDialog()
CallsfileDialog( String defaultFilename, int mode )
withdefaultFilename = "*"
andmode =
FileDialog.LOAD
.static String
fileDialog(String defaultFilename)
static String
fileDialog(String defaultFilename, int mode)
Displaysjava.awt.
FileDialog
and returns the filename selected by the user.static int
find(boolean[] array, boolean value)
Searcharray
forvalue
.static int
find(boolean[] array, int fromIndex, boolean value)
Searcharray
forvalue
starting fromfromIndex
.static int
find(byte[] array, byte value)
Searcharray
forvalue
.static int
find(byte[] array, int fromIndex, byte value)
Searcharray
forvalue
starting fromfromIndex
.static int
find(char[] array, char value)
Searcharray
forvalue
.static int
find(char[] array, int fromIndex, char value)
Searcharray
forvalue
starting fromfromIndex
.static int
find(int[] array, int value)
Searcharray
forvalue
.static int
find(int[] array, int fromIndex, int value)
Searcharray
forvalue
starting fromfromIndex
.static int
find(long[] array, int fromIndex, long value)
Searcharray
forvalue
starting fromfromIndex
.static int
find(long[] array, long value)
Searcharray
forvalue
.static int
find(Object[] array, int fromIndex, Object o)
Searcharray
foro
starting fromfromIndex
.static int
find(Object[] array, Object o)
Searcharray
foro
.static Object
flip(boolean[] array, int i)
Togglesarray[i]
.static String
format(double value, int nDec)
Formatsvalue
as String with a fixed number ofnDec
decimals.static String
format(double value, int nDec, int minLength)
Formatsvalue
as String with a fixed number ofnDec
decimals and minimum lengthminLength
.static String
format(Object o)
Formatso
for JXN-output.static String
format(Object o, boolean recursive)
Formatso
for JXN-output.static String
format(String text)
Formats special characters intext
.static String[]
formatClass(Object o)
Formats information of the class of o (like menu: View > Class… in JxnSession window).static String[]
formatMethods(Object o)
Formats information of the methods of o (like menu: View > Methods… in JxnSession window).static String[]
formatMethods(Object o, String name)
Formats information of the methods of o.static boolean
ge(double x, double y)
Represents the Java relational operator.static boolean
ge(long x, long y)
Represents the Java relational operator.static Object
get(Object ao, double x)
Returnsao[round(x)]
with array index limitted to0 <= index < ao.length
.static Object
get(Object ao, int i)
In JXN preferao[i]
.static Class
getClass(Object ao)
Deprecated.No more needed: Simply callao.getClass()
.static String
getClassName(Object o)
Formats the class name of o as String.static String
getHeadTrail(String delimString, int nHead, String separator, int nTrail, String text)
Extracts the firstnHead
and the lastnTrail
tokens delimited bydelimString
fromtext
.static JxnRealArrayAlgebra
getZ(KmgParallelProjection p3d, JxnRealArrayAlgebra[] rxyz)
Returns the z-component of the projection (direction out of the projection plane towards the viewer).static String
group(String text, int m)
Groupstext
into sections ofm
characters by inserting blanks.static String
group(String text, int m, String separator)
Groupstext
into sections ofm
characters by inserting the Stringseparator
.static boolean
gt(double x, double y)
Represents the Java relational operator.static boolean
gt(long x, long y)
Represents the Java relational operator.static int
hashCode(Object ao)
Deprecated.No more needed: Simply callao.hashCode()
.static String
hexString(byte by)
Formats a byte as hexString.static String
hexString(byte[] by)
Formats a byte array as hexString.static String
hexString(char ch)
Formats a char as hexString.static String
hexString(char[] ch)
Formats a char array as hexString.static String
hexString(double d)
Formats a double as hexString.static String
hexString(float f)
Formats a float as hexString.static String
hexString(int i)
Formats an int as hexString.static String
hexString(long l)
Formats a long as hexString.static String
hexString(short sh)
Formats a short as hexString.static String
hexString(String text)
Formatstext
as hexString.static String
hexString(BigInteger bi)
Formats a BigInteger as hexString.static double
hexStringToDouble(String hexString)
Parses hexString to double usingparseHex(String hexString)
andDouble.longBitsToDouble(long)
.static float
hexStringToFloat(String hexString)
Parses hexString to float usingparseHex(String hexString)
andFloat.intBitsToFloat(int)
.static Object
intArray(int length)
Creates a new int array with the specified length.static Object
intArray(int length, int initial)
Creates a new int array with the specified length, initialized withinitial
.static int[]
intArray(String csvList)
Deprecated.In JXN prefer{ 123, 456, 789 }
.static boolean
isArray(Object o)
Returns true if o is an array (null returns false).static boolean
isNull(double x)
Allows the generic check of arbitrary variables (e.g.arguments passed to jxn files).static boolean
isNull(Object o)
Returns true if o == null.static boolean
isPrimitiveOrJavaWrapper(double x)
Used in jxn files to check the type ofx
.static boolean
isPrimitiveOrJavaWrapper(Object x)
Used in jxn files to check the type ofx
.static boolean
isSame(Object x, Object y)
Returns true if x == y (references to the same (identical) instance).static String
join(Object array)
Formatsarray
as string.static String
join(String separator, Object array)
Formatsarray
as string.static boolean
le(double x, double y)
Represents the Java relational operator.static boolean
le(long x, long y)
Represents the Java relational operator.static int
left(int x, int i)
Represents the Java bit shift operator (for int).static long
left(long x, int i)
Represents the Java bit shift operator (for long).static int
length(Object ao)
Returns the length of the specified array object.static double
limit(double x, double xmin, double xmax)
Keepsx
withinxmin
andxmax
.static int
limit(int x, int xmin, int xmax)
Keepsx
withinxmin
andxmax
.static long
limit(long x, long xmin, long xmax)
Keepsx
withinxmin
andxmax
.static double
log(double b, double x)
Returns the baseb
logarithm ofx
.static double
log2(double x)
Returns the base 2 logarithm ofx
.static Object
longArray(int length, long initial)
Creates a new long array with the specified length, initialized withinitial
.static boolean
lt(double x, double y)
Represents the Java relational operator.static boolean
lt(long x, long y)
Represents the Java relational operator.static int
modPow(int base, int exp, int m)
Returnsbaseexp mod m
.static double
modulo(double x, double y)
Preferx % y
ifx > 0
andy > 0
.
Example:static int
modulo(int x, int y)
Preferx % y
ifx > 0
andy > 0
.static long
modulo(long x, long y)
Preferx % y
ifx > 0
andy > 0
.static boolean
ne(boolean x, boolean y)
Represents the Java relational operator.static boolean
ne(double x, double y)
Represents the Java relational operator.static boolean
ne(long x, long y)
Represents the Java relational operator.static Object
newArray(int length, Object initial)
Creates a new array with the specified length, initialized withinitial
.static Object
newArray(Class<?> componentType, int length)
Creates a new array with the specified component type and length.static Object
newArray(Class<?> componentType, int... dimensions)
Creates a new array with the specified component type and dimensions.static Object
newArray(Class<?> componentType, int length, Object initial)
Creates a new array with the specified component type and length, initialized withinitial
.static byte
nop(double sliderDependentVariable)
Forces the repetition of a statement by inserting an artificial dependency onsliderDependentVariable
.static byte
nop(Object sliderDependentObject)
Deprecated.Not needed.static Object
nop(Object obj, double sliderDependentVariable)
Forces the repetition of a statement by inserting an artificial dependency onsliderDependentVariable
.static Object
nop(Object obj, Object sliderDependentObject)
Deprecated.Not needed.static boolean
not(boolean x)
Represents the Java boolean operator.static int
not(int x)
Represents the Java bitwise operator (for int).static long
not(long x)
Represents the Java bitwise operator (for long).static boolean
or(boolean x, boolean y)
Represents the Java boolean operator.static int
or(int x, int y)
Represents the Java bitwise operator (for int).static long
or(long x, long y)
Represents the Java bitwise operator (for long).static Number
parseHex(String hexString)
ParseshexString
to appropriateNumber
.static JxnRealArrayPlotFrame
plot(double[] y)
Creates a newJxnRealArrayPlotFrame
and visualizes the values ofy
as a curve:
xi = i, yi = y[i], i = 0 ... y.length - 1.static JxnRealArrayPlotFrame
plot(double[] x, double[] y)
Creates a newJxnRealArrayPlotFrame
and visualizes the values ofx
andy
as a curve:
xi = x[i], yi = y[i], i = 0 ... min( x.length, y.length ) - 1.static JxnRealArrayPlotFrame
plot(double[] x, double[] y, double vyx)
Seeplot
.static JxnRealArrayPlotFrame
plot(double[] x, double[] y1, double[] y2)
static JxnRealArrayPlotFrame
plot(double[] x, double[] y1, double[] y2, double[] y3)
static JxnRealArrayPlotFrame
plot(double[] x, double[] y, int logScales)
Seeplot
.static JxnRealArrayPlotFrame
plot(double[] x, double[] y, Color color)
Seeplot
.static JxnRealArrayPlotFrame
plot(double[] x, double[] y, Color color, float lineWidth)
Seeplot
.static JxnRealArrayPlotFrame
plot(double[] x, double[] y, Color color, int lineType)
Seeplot
.static JxnRealArrayPlotFrame
plot(double[] x, double[] y, Color color, int lineType, double vyx)
Seeplot
.static JxnRealArrayPlotFrame
plot(double[] x, double[] y, Color color, int lineType, float lineWidth, double vyx)
Seeplot
.static JxnRealArrayPlotFrame
plot(double[] x, double[] y, Color color, int lineType, float lineWidth, int logScales)
Seeplot
.static JxnRealArrayPlotFrame
plot(double[] x, double[] y, Color color, int lineType, int logScales)
Seeplot
.static JxnRealArrayPlotFrame
plot(double[] x, double[] y, Color color, Stroke stroke, double vyx)
Seeplot
.static JxnRealArrayPlotFrame
plot(double[] x, double[] y, Color color, Stroke stroke, int logScales)
Seeplot
.static JxnRealArrayPlotFrame
plot(double[] y, Color color, int lineType)
Seeplot
.static JxnPerspectivePlotFrame
plot(IKmg3DProjection p3d)
Creates aJxnPerspectivePlotFrame
for the three-dimensional display of vectors and curves.static JxnPerspectivePlotFrame
plot(IKmg3DProjection p3d, double size)
Creates aJxnPerspectivePlotFrame
for the three-dimensional display of vectors and curves.static Frame
plot(KmgXYPainter painter)
Deprecated....static double
pqRoot(double p, double q)
Returns solution ofx^2 + p x + q = 0
.static String[]
print(PrintStream ps, String[] lines)
Writeslines
line by line tops
.static String
repeat(String text, int n)
Returns a String which containstext
repeatedn
times.static int
right(int x, int i)
Represents the Java bit shift operator (for int).static long
right(long x, int i)
Represents the Java bit shift operator (for long).static int
right0(int x, int i)
Represents the Java bit shift operator (for int).static long
right0(long x, int i)
Represents the Java bit shift operator (for long).static long
round_half_away_from_zero(double x)
Returns result of commercial rounding ofx
.static Object
set(boolean[] array, int i, boolean value)
Shortcut forjava.lang.reflect.
Array.setBoolean( Object array, int i, boolean value )
.static Object
set(byte[] array, int i, byte value)
Shortcut forjava.lang.reflect.
Array.setByte( Object array, int i, byte value )
.static Object
set(char[] array, int i, char value)
Shortcut forjava.lang.reflect.
Array.setChar( Object array, int i, char value )
.static Object
set(double[] array, int i, double value)
Shortcut forjava.lang.reflect.
Array.setDouble( Object array, int i, double value )
.static Object
set(float[] array, int i, float value)
Shortcut forjava.lang.reflect.
Array.setFloat( Object array, int i, float value )
.static Object
set(int[] array, int i, int value)
Shortcut forjava.lang.reflect.
Array.setInt( Object array, int i, int value )
.static Object
set(long[] array, int i, long value)
Shortcut forjava.lang.reflect.
Array.setLong( Object array, int i, long value )
.static Object
set(short[] array, int i, short value)
Shortcut forjava.lang.reflect.
Array.setShort( Object array, int i, short value )
.static Object
set(Object[] array, int i, Object value)
Sets the value of thei
-th component ofarray
to the specified newvalue
.static Object
set(Object o, String fieldName, boolean value)
Sets a boolean field of an object or a class.static Object
set(Object o, String fieldName, byte value)
Sets a byte field of an object or a class.static Object
set(Object o, String fieldName, char value)
Sets a char field of an object or a class.static Object
set(Object o, String fieldName, double value)
Sets a double field of an object or a class.static Object
set(Object o, String fieldName, float value)
Sets a float field of an object or a class.static Object
set(Object o, String fieldName, int value)
Sets a int field of an object or a class.static Object
set(Object o, String fieldName, long value)
Sets a long field of an object or a class.static Object
set(Object o, String fieldName, short value)
Sets a short field of an object or a class.static Object
set(Object o, String fieldName, Object value)
Sets a public field specified byfieldName
of an object or a class to the givenvalue
.static boolean
setArrayReturnOldValue(boolean returnOldValue)
Controls if the set array methods return the old (overwriten) array value.static String
setHexStringSeparator(String separator)
Sets the group separator for hexString.static String
showClass(Object o)
Deprecated.Use#edit
formatClass(o)
or Menu: View > Class...static String
showMethods(Object o)
Deprecated.Use#edit
formatMethods(o)
or Menu: View > Methods...static String
showMethods(Object o, String name)
Deprecated.Use#edit
formatMethods( o, name )
or Menu: View > Methods...static double
sinD(double a)
CallsMath.sin(double)
after converting argumenta
from degrees to radians.static String[]
split(String delimString, String text)
Splitstext
into parts delimited by the delimiter stringdelimString
.static String
squeeze(String text)
Removes blanks fromtext
.static String
squeeze(String text, char chRemove)
Removes all occurrences ofchRemove
fromtext
.static String
squeeze(String text, String removeChars)
Removes all occurrences of the characters contained inremoveChars
fromtext
.static String[]
stringArray(String csvList)
Deprecated.In JXN prefer{ "abc", "xyz" }
.static String[]
stringArray(String csvList, String delimChars)
Returns array of tokens fromStringTokenizer.nextToken()
.static double
sw(boolean b, double yTrue, double yFalse)
ReturnsyTrue
, ifb
is true elseyFalse
.static int
sw(boolean b, int yTrue, int yFalse)
ReturnsyTrue
, ifb
is true elseyFalse
.static long
sw(boolean b, long yTrue, long yFalse)
ReturnsyTrue
, ifb
is true elseyFalse
.static Object
sw(boolean b, Object oTrue, Object oFalse)
ReturnsoTrue
, ifb
is true elseoFalse
.static double
sw(double x, double yLT, double yGE)
ReturnsyLT
, ifx < 0.
elseyGE
.static double
sw(double x, double yLT, double yEQ, double yGT)
ReturnsyLT
, ifx < 0.
elseyGT
, ifx > 0.
elseyEQ
.static double
sw(double x, double eps, double yLower, double yInner, double yUpper)
ReturnsyLower
, ifx < -eps
elseyUpper
, ifx > eps
elseyInner
.static double
sw(double x, double xLower, double xUpper, double yLower, double yInner, double yUpper)
ReturnsyLower
, ifx < xLower
elseyUpper
, ifx > xUpper
elseyInner
.static Object
sw(double x, double xLower, double xUpper, Object oLower, Object oInner, Object oUpper)
ReturnsoLower
, ifx < xLower
elseoUpper
, ifx > xUpper
elseoInner
.static Object
sw(double x, double eps, Object oLower, Object oInner, Object oUpper)
ReturnsoLower
, ifx < -eps
elseoUpper
, ifx > eps
elseoInner
.static int
sw(double x, int yLT, int yGE)
ReturnsyLT
, ifx < 0.
elseyGE
.static int
sw(double x, int yLT, int yEQ, int yGT)
ReturnsyLT
, ifx < 0.
elseyGT
, ifx > 0.
elseyEQ
.static long
sw(double x, long yLT, long yGE)
ReturnsyLT
, ifx < 0.
elseyGE
.static long
sw(double x, long yLT, long yEQ, long yGT)
ReturnsyLT
, ifx < 0.
elseyGT
, ifx > 0.
elseyEQ
.static Object
sw(double x, Object[] oa)
static Object
sw(double x, Object oLT, Object oGE)
ReturnsoLT
, ifx < 0
elseoGE
.static Object
sw(double x, Object oLT, Object oEQ, Object oGT)
ReturnsoLT
, ifx < 0
elseoGT
, ifx > 0
elseoEQ
.static int
sw(int ivar, double slider_switch)
Returns1
ifivar-0.5 <= slider_switch < ivar+0.5
else0
.static double
tanD(double a)
CallsMath.tan(double)
after converting argumenta
from degrees to radians.static Object
toArray(Object ao)
CallstoArray( ao, 0 )
.static Object
toArray(Object ao, int mode)
Check, ifao
is an array or try to callao.toArray()
.static String
toRawString(Object o)
Formatso
to the string which would be returned by thetoString()
method, if the same had not been overwriten for the class ofo
.static String
toString(Object o)
Formats o as String.static String
toString(Object o, boolean showHashCode)
Formats o as String.static String
toString(Object o, int verboseLevel)
Formats o as String.static String[]
toStringArray(Object o)
Formatso
as aString
array.static String[]
toTableRows(double[][] colArrays)
Formats a set of column arrays as a String array of the rows using'\t'
to separate the array elements of a row.static String[]
toTableRows(Object[] colArrays)
Formats a set of column arrays as a String array of the rows using'\t'
to separate the array elements of a row.static String[]
toTableRows(String separator, double[][] colArrays)
Formats a set of column arrays as a String array of the rows usingseparator
to separate the array elements of a row.static String[]
toTableRows(String separator, Object[] colArrays)
Formats a set of column arrays as a String array of the rows usingseparator
to separate the array elements of a row.static int
total(boolean[] array)
Returns the number oftrue
values inarray
.static int
total(byte[] array)
Returns theint
sum of the values ofarray
.static double
total(double[] array)
Returns the sum of the values ofarray
.static int
total(int[] array)
Returns the sum of the values ofarray
.static long
total(long[] array)
Returns the sum of the values ofarray
.static String
whatIs(Object o)
Deprecated.replaced byJxnParameterCheck.whatIs(Object)
.
-
-
-
Method Detail
-
__1_fileDialog
protected void __1_fileDialog()
-
fileDialog
public static String fileDialog(String defaultFilename, int mode)
Displaysjava.awt.
FileDialog
and returns the filename selected by the user.- Parameters:
defaultFilename
- narrows down the files displayed in the FileDialogmode
- eitherjava.awt.
FileDialog.LOAD
orjava.awt.
FileDialog.SAVE
- Returns:
- name of the file selected by the user
-
fileDialog
public static String fileDialog(String defaultFilename)
- Returns:
- name of the file selected by the user
-
fileDialog
public static String fileDialog()
CallsfileDialog( String defaultFilename, int mode )
withdefaultFilename = "*"
andmode =
FileDialog.LOAD
.- Returns:
- name of the file selected by the user
-
__2_plot_and_curve
protected void __2_plot_and_curve()
-
plot
public static Frame plot(KmgXYPainter painter)
Deprecated....
-
plot
public static JxnPerspectivePlotFrame plot(IKmg3DProjection p3d)
Creates aJxnPerspectivePlotFrame
for the three-dimensional display of vectors and curves. Callsplot
( p3d, 1. )
.
-
plot
public static JxnPerspectivePlotFrame plot(IKmg3DProjection p3d, double size)
Creates aJxnPerspectivePlotFrame
for the three-dimensional display of vectors and curves.
-
getZ
public static JxnRealArrayAlgebra getZ(KmgParallelProjection p3d, JxnRealArrayAlgebra[] rxyz)
Returns the z-component of the projection (direction out of the projection plane towards the viewer).
Can be used to hide invisible lines.
Example: JxnPortable/docs/plot_examples/PlotFrameDemo.html plot 2c: u, v -> x, y, z
-
plot
public static JxnRealArrayPlotFrame plot(double[] y)
Creates a newJxnRealArrayPlotFrame
and visualizes the values ofy
as a curve:
xi = i, yi = y[i], i = 0 ... y.length - 1.- Returns:
PlotFrame
instance can be used to add furthercurves
andphasors
.- See Also:
JxnRealArrayAlgebra.plot(JxnRealArrayAlgebra ry)
-
plot
public static JxnRealArrayPlotFrame plot(double[] y, Color color, int lineType)
Seeplot
.- Parameters:
lineType
- seeJxnRealArrayCurve
- See Also:
JxnRealArrayAlgebra.plot(JxnRealArrayAlgebra ry, Color color, int lineType)
-
plot
public static JxnRealArrayPlotFrame plot(double[] x, double[] y)
Creates a newJxnRealArrayPlotFrame
and visualizes the values ofx
andy
as a curve:
xi = x[i], yi = y[i], i = 0 ... min( x.length, y.length ) - 1.- Returns:
PlotFrame
instance can be used to add furthercurves
andphasors
.- See Also:
JxnRealArrayAlgebra.plot(JxnRealArrayAlgebra rx, JxnRealArrayAlgebra ry)
-
plot
public static JxnRealArrayPlotFrame plot(double[] x, double[] y1, double[] y2)
-
plot
public static JxnRealArrayPlotFrame plot(double[] x, double[] y1, double[] y2, double[] y3)
-
plot
public static JxnRealArrayPlotFrame plot(double[] x, double[] y, double vyx)
Seeplot
.- Parameters:
vyx
- fixed ratio of the scaling: 1.0 for equally scaled x- and y-axis.- See Also:
JxnRealArrayAlgebra.plot(JxnRealArrayAlgebra rx, JxnRealArrayAlgebra ry, double vyx)
-
plot
public static JxnRealArrayPlotFrame plot(double[] x, double[] y, int logScales)
Seeplot
.
Note: logarithmic scaling requires that all values are positive. The scale switches to linear if rx or ry include any value(s) <= 0.- Parameters:
logScales
- determines which axis should be scaled logarithmiclogScales x-axis y-axis 0 lin lin 1 lin log 2 log lin 3 log log 4 time lin 5 time log - See Also:
JxnRealArrayAlgebra.plot(JxnRealArrayAlgebra rx, JxnRealArrayAlgebra ry, int logScales)
-
plot
public static JxnRealArrayPlotFrame plot(double[] x, double[] y, Color color)
Seeplot
.
-
plot
public static JxnRealArrayPlotFrame plot(double[] x, double[] y, Color color, int lineType)
Seeplot
.- Parameters:
lineType
- seeJxnRealArrayCurve
- See Also:
JxnRealArrayAlgebra.plot(JxnRealArrayAlgebra rx, JxnRealArrayAlgebra ry, Color color, int lineType)
-
plot
public static JxnRealArrayPlotFrame plot(double[] x, double[] y, Color color, float lineWidth)
Seeplot
.
-
plot
public static JxnRealArrayPlotFrame plot(double[] x, double[] y, Color color, int lineType, double vyx)
Seeplot
.- Parameters:
vyx
- fixed ratio of the scaling: 1.0 for equally scaled x- and y-axis.- See Also:
JxnRealArrayAlgebra.plot(JxnRealArrayAlgebra rx, JxnRealArrayAlgebra ry, Color color, int lineType, double vyx)
-
plot
public static JxnRealArrayPlotFrame plot(double[] x, double[] y, Color color, int lineType, int logScales)
Seeplot
.
-
plot
public static JxnRealArrayPlotFrame plot(double[] x, double[] y, Color color, int lineType, float lineWidth, double vyx)
Seeplot
.- Parameters:
lineWidth
- seejava.awt.BasicStroke
vyx
- fixed ratio of the scaling: 1.0 for equally scaled x- and y-axis.- See Also:
JxnRealArrayAlgebra.plot(JxnRealArrayAlgebra rx, JxnRealArrayAlgebra ry, Color color, int lineType, float lineWidth, double vyx)
-
plot
public static JxnRealArrayPlotFrame plot(double[] x, double[] y, Color color, int lineType, float lineWidth, int logScales)
Seeplot
.- Parameters:
lineWidth
- seejava.awt.BasicStroke
- See Also:
JxnRealArrayAlgebra.plot(JxnRealArrayAlgebra rx, JxnRealArrayAlgebra ry, Color color, int lineType, float lineWidth, int logScales)
-
plot
public static JxnRealArrayPlotFrame plot(double[] x, double[] y, Color color, Stroke stroke, double vyx)
Seeplot
.- Parameters:
stroke
- seejava.awt.BasicStroke
vyx
- fixed ratio of the scaling: 1.0 for equally scaled x- and y-axis.- See Also:
JxnRealArrayAlgebra.plot(JxnRealArrayAlgebra rx, JxnRealArrayAlgebra ry, Color color, Stroke stroke, double vyx)
-
plot
public static JxnRealArrayPlotFrame plot(double[] x, double[] y, Color color, Stroke stroke, int logScales)
Seeplot
.- Parameters:
stroke
- seejava.awt.BasicStroke
- See Also:
JxnRealArrayAlgebra.plot(JxnRealArrayAlgebra rx, JxnRealArrayAlgebra ry, Color color, Stroke stroke, int logScales)
-
curve
public static JxnRealArrayCurve curve(double[] x, double[] y, Color color)
Returns a curve representation ofx
andy
( xi = x[i], yi = y[i] ). Call theadd
method on aPlotFrame
instance to display the curve in the PlotFrame. Allows e.g. to show a curve in aJxnComplexPlotFrame
.
Example for given arraysx
andy
:pf = plot( 3 + j 4 ).add( curve( x, y, Color.BLUE ) )
-
curve
public static JxnRealArrayCurve curve(double[] x, double[] y, Color color, int lineType)
Seecurve
.- Parameters:
lineType
- seeJxnRealArrayCurve
- See Also:
JxnRealArrayAlgebra.curve(JxnRealArrayAlgebra rx, JxnRealArrayAlgebra ry, Color color, int lineType)
-
curve
public static JxnRealArrayCurve curve(double[] y, Color color)
-
curve
public static JxnRealArrayCurve curve(double[] y, Color color, int lineType)
Seecurve
.- Parameters:
lineType
- seeJxnRealArrayCurve
- See Also:
JxnRealArrayAlgebra.curve(JxnRealArrayAlgebra ry, Color color, int lineType)
-
curve
public static JxnRealArrayCurve curve(double[] x, double[] y, double[] z, IKmg3DProjection p3d)
Deprecated.Useplot(p3d)
.add( x, y, z )
.
-
curve
public static JxnRealArrayCurve curve(double[] x, double[] y, double[] z, IKmg3DProjection p3d, Color color)
Deprecated.
-
curve
public static JxnRealArrayCurve curve(double[] x, double[] y, double[] z, IKmg3DProjection p3d, Color color, int lineType)
Deprecated.
-
nop
public static byte nop(double sliderDependentVariable)
Forces the repetition of a statement by inserting an artificial dependency onsliderDependentVariable
.
A slider animatedPlotFrame
requires the repetition of all statements which depend on the slider variables. All statements which contain a slider variable or a variable which is dependent on a slider variable are repeated automatically on the change of any of the slider dependent variables. Therefore in most cases it is not necessary to explicitly control the repetition. Only if a statement does not contain any slider dependent variable but must be repeated, thenop
methods can be used to artificially create a dependency and thus force the repetition.
Usage: Addnop(sliderVar)
to an arbitrary Java primitive of the statement. Asnop(double)
returns0
the result is not changed. If the statement does not contain any Java primitive usenop(java.lang.Object, double)
.
Example:slider = @JxnSliderPanel(this) sliderVar = slider.add( "var", 0., -5., 5. ) countRepaint = 0 ! statement is not slider dependent => not repeated countRepaint = countRepaint + 1 + nop(sliderVar) ! nop forces repetition on change of sliderVar plot( @JxnComplexAlgebra( 1., sliderVar, false ) ).add( @JxnTextPainter( countRepaint, 0., 0. ) )
- Parameters:
sliderDependentVariable
- any of the slider variablessliderVar
from:sliderVar
=
slider
.
add
(...)
- Returns:
0
(byte) does not change the result if added to a primitive expression- See Also:
- SliderRepeatNopDemo.html
-
nop
public static byte nop(Object sliderDependentObject)
Deprecated.Not needed.
-
nop
public static Object nop(Object obj, double sliderDependentVariable)
Forces the repetition of a statement by inserting an artificial dependency onsliderDependentVariable
.
Usage:nop( obj, sliderVar ).fn() ! instead of obj.fn() obj = nop( fn(), sliderVar ) ! instead of obj = fn() fn( nop( obj, sliderVar ) ) ! instead of fn( obj )
- Parameters:
sliderDependentVariable
- any of the slider variablessliderVar
from:sliderVar
=
slider
.
add
(...)
- Returns:
obj
without change- See Also:
nop(double)
-
__3_formatting_to_String
protected void __3_formatting_to_String()
-
join
public static String join(Object array)
Formatsarray
as string. Array elements are formatted using thetoString()
method of the elements and separated by ", ".- Parameters:
array
- array or object of a class which implements atoArray()
method.
-
join
public static String join(String separator, Object array)
Formatsarray
as string. Array elements are formatted using thetoString()
method of the elements and separated byseparator
.- Parameters:
separator
- zero or more characters separating the array elements.array
- array or object of a class which implements atoArray()
method.
-
split
public static String[] split(String delimString, String text)
Splitstext
into parts delimited by the delimiter stringdelimString
. The parts are returned as array elements. The delimiter string is not included in the result. A pair of consecutive occurrences ofdelimString
results in an array element containing an empty string "".- Parameters:
delimString
- sequence of one or more chars- See Also:
KmgStringTokenizer
,String.split(java.lang.String, int)
-
toTableRows
public static String[] toTableRows(Object[] colArrays)
Formats a set of column arrays as a String array of the rows using'\t'
to separate the array elements of a row.- Parameters:
colArrays
- seetoTableRows(String, Object[])
-
toTableRows
public static String[] toTableRows(String separator, Object[] colArrays)
Formats a set of column arrays as a String array of the rows usingseparator
to separate the array elements of a row.- Parameters:
separator
- zero or more characters separating the array elements of a rowcolArrays
- array containing an arbitrary nummer of columns. The columns may be given as arrays of primitive, arrays of objects or single objects of a class which implements atoArray()
method.
-
toTableRows
public static String[] toTableRows(double[][] colArrays)
Formats a set of column arrays as a String array of the rows using'\t'
to separate the array elements of a row.- Parameters:
colArrays
- array of column arrays of double
-
toTableRows
public static String[] toTableRows(String separator, double[][] colArrays)
Formats a set of column arrays as a String array of the rows usingseparator
to separate the array elements of a row.- Parameters:
separator
- zero or more characters separating the array elements of a rowcolArrays
- array of column arrays of double
-
print
public static String[] print(PrintStream ps, String[] lines)
Writeslines
line by line tops
.
Example:ps = @
PrintStream
fileDialog()
print( ps,toTableRows
{ t, sin 2 PI t, cos 2 PI t } )ps.close()
- Returns:
lines
(the argument passed to the method)
-
format
public static String format(Object o)
Formatso
for JXN-output. Ifo
is an array it is unrolled recursively.- Returns:
format( o, true )
- See Also:
Arrays.toString(Object[])
,Arrays.deepToString(java.lang.Object[])
-
format
public static String format(Object o, boolean recursive)
Formatso
for JXN-output.- Parameters:
recursive
- iftrue
ando
is an array it is unrolled recursively.
-
format
public static String format(String text)
Formats special characters intext
.- Returns:
KmgStaticUtilities.format(String)
-
format
public static String format(double value, int nDec)
Formatsvalue
as String with a fixed number ofnDec
decimals.- Parameters:
nDec
- IfnDec <= 0
the sign ofvalue
is formatted as "+ value
" or "- value
".- See Also:
java.text.DecimalFormat
-
format
public static String format(double value, int nDec, int minLength)
Formatsvalue
as String with a fixed number ofnDec
decimals and minimum lengthminLength
.
Callsformat(double, int)
- Parameters:
minLength
- minimum length of the result
if > 0 right justified: callsaddLeadingBlanks( ..., minLength )
if < 0 left justified: callsaddTrailingChars( ..., -minLength, ' ' )
-
whatIs
public static String whatIs(Object o)
Deprecated.replaced byJxnParameterCheck.whatIs(Object)
. Returns description of o as String.
-
toRawString
public static String toRawString(Object o)
Formatso
to the string which would be returned by thetoString()
method, if the same had not been overwriten for the class ofo
.- Returns:
KmgStaticUtilities.toRawString(java.lang.Object)
- See Also:
Object.toString()
-
toStringArray
public static String[] toStringArray(Object o)
Formatso
as aString
array.- Parameters:
o
- may be an array, aCollection
or an instance of a class with atoString
method- Returns:
KmgStaticUtilities.toStringArray(java.lang.Object)
-
repeat
public static String repeat(String text, int n)
Returns a String which containstext
repeatedn
times.
-
squeeze
public static String squeeze(String text, char chRemove)
Removes all occurrences ofchRemove
fromtext
.
-
squeeze
public static String squeeze(String text, String removeChars)
Removes all occurrences of the characters contained inremoveChars
fromtext
.
-
group
public static String group(String text, int m)
Groupstext
into sections ofm
characters by inserting blanks.- Parameters:
m
- seegroup(java.lang.String, int, java.lang.String)
-
group
public static String group(String text, int m, String separator)
Groupstext
into sections ofm
characters by inserting the Stringseparator
.- Parameters:
m
- determines the number of characters of a section.
if m > 0, grouping start at the left end of text:group( "1234567890", 4, "~~" ) => 1234~~5678~~90
if m < 0, grouping start at the right end of text:group( "1234567890", -3, "_" ) => 1_234_567_890
-
addLeadingZeros
public static String addLeadingZeros(String text, int n)
Prefixestext
with'0'
so that the result contains at leastn
characters.
-
addLeadingBlanks
public static String addLeadingBlanks(String text, int n)
Prefixestext
with blanks so that the result contains at leastn
characters.
-
addLeadingChars
public static String addLeadingChars(String text, int n, char ch)
Prefixestext
withch
so that the result contains at leastn
characters.
-
addTrailingChars
public static String addTrailingChars(String text, int n, char ch)
Appendstext
withch
so that the result contains at leastn
characters.
-
getHeadTrail
public static String getHeadTrail(String delimString, int nHead, String separator, int nTrail, String text)
Extracts the firstnHead
and the lastnTrail
tokens delimited bydelimString
fromtext
. The removed tokens are replaced byseparator
. The delimiters are included in the result.
Example:getHeadTrail( "/", 3, "...", 2, "C:/Users/Default/AppData/Roaming/Microsoft/Windows/SendTo" )
returns:C:/Users/Default/.../Windows/SendTo
-
__4_hex_formatting
protected void __4_hex_formatting()
Adds to hex formatting and parsing methods.- See Also:
Double.longBitsToDouble(long)
,Double.doubleToRawLongBits(double)
,Double.toHexString(double)
,Double.parseDouble(java.lang.String)
,Float.intBitsToFloat(int)
,Float.floatToRawIntBits(float)
,Float.toHexString(float)
,Float.parseFloat(java.lang.String)
,Long.parseUnsignedLong( String s, int radix )
,Long.toUnsignedString( long value, int radix )
,Long.toHexString(long)
,Integer.parseUnsignedInt( String s, int radix )
,Integer.toUnsignedString( int value, int radix )
,Integer.toHexString(int)
,java.math.BigInteger( String s, int radix )
,java.math.BigInteger.toString( int radix )
-
hexStringToDouble
public static double hexStringToDouble(String hexString)
Parses hexString to double usingparseHex(String hexString)
andDouble.longBitsToDouble(long)
.- See Also:
Double.valueOf(java.lang.String)
-
hexStringToFloat
public static float hexStringToFloat(String hexString)
Parses hexString to float usingparseHex(String hexString)
andFloat.intBitsToFloat(int)
.- See Also:
Float.valueOf(java.lang.String)
-
setHexStringSeparator
public static String setHexStringSeparator(String separator)
Sets the group separator for hexString.- Returns:
- the old separator
-
hexString
public static String hexString(double d)
Formats a double as hexString.
-
hexString
public static String hexString(float f)
Formats a float as hexString.
-
hexString
public static String hexString(BigInteger bi)
Formats a BigInteger as hexString.
-
hexString
public static String hexString(long l)
Formats a long as hexString.
-
hexString
public static String hexString(int i)
Formats an int as hexString.
-
hexString
public static String hexString(short sh)
Formats a short as hexString.
-
hexString
public static String hexString(byte by)
Formats a byte as hexString.
-
hexString
public static String hexString(byte[] by)
Formats a byte array as hexString.
-
hexString
public static String hexString(char ch)
Formats a char as hexString.
-
hexString
public static String hexString(char[] ch)
Formats a char array as hexString.
-
__5_ClassExplorer
protected void __5_ClassExplorer()
-
formatClass
public static String[] formatClass(Object o)
Formats information of the class of o (like menu: View > Class… in JxnSession window).
Example:#edit formatClass j
! shows info of class JxnComplexAlgebra
- Parameters:
o
- object, class or "class name as String"
-
formatMethods
public static String[] formatMethods(Object o)
Formats information of the methods of o (like menu: View > Methods… in JxnSession window).- Parameters:
o
- object, class or "class name as String"
-
formatMethods
public static String[] formatMethods(Object o, String name)
Formats information of the methods of o.- Parameters:
o
- object, class or "class name as String"name
- selects only methods starting withname
-
showClass
public static String showClass(Object o)
Deprecated.Use#edit
formatClass(o)
or Menu: View > Class...
-
showMethods
public static String showMethods(Object o)
Deprecated.Use#edit
formatMethods(o)
or Menu: View > Methods...
-
showMethods
public static String showMethods(Object o, String name)
Deprecated.Use#edit
formatMethods( o, name )
or Menu: View > Methods...
-
__6_extensions_to_Math
protected void __6_extensions_to_Math()
Collection of methods adding tojava.lang.Math
.
-
sinD
public static double sinD(double a)
CallsMath.sin(double)
after converting argumenta
from degrees to radians.
-
cosD
public static double cosD(double a)
CallsMath.cos(double)
after converting argumenta
from degrees to radians.
-
tanD
public static double tanD(double a)
CallsMath.tan(double)
after converting argumenta
from degrees to radians.
-
asinD
public static double asinD(double a)
CallsMath.asin(double)
and converts the result from radians to degrees.
-
acosD
public static double acosD(double a)
CallsMath.acos(double)
and converts the result from radians to degrees.
-
atanD
public static double atanD(double a)
CallsMath.atan(double)
and converts the result from radians to degrees.
-
atan2D
public static double atan2D(double y, double x)
CallsMath.atan2(double, double)
and converts the result from radians to degrees.
-
log2
public static double log2(double x)
Returns the base 2 logarithm ofx
.
-
log
public static double log(double b, double x)
Returns the baseb
logarithm ofx
.
-
asinh
public static double asinh(double x)
-
acosh
public static double acosh(double x)
-
atanh
public static double atanh(double x)
-
abs
public static double abs(double x, double y)
-
abs
public static double abs(double x, double y, double z)
Returnssqrt( x * x + y * y + z * z )
.
-
pqRoot
public static double pqRoot(double p, double q)
Returns solution ofx^2 + p x + q = 0
.- Returns:
- the bigger magnitude solution
x1
. Get the 2nd solution asx2 = q / x1
.
ReturnsDouble.NaN
, if there are no real roots.
-
round_half_away_from_zero
public static long round_half_away_from_zero(double x)
Returns result of commercial rounding ofx
.
See → Wikipedia for a discussion of different rounding methods.- See Also:
Math.round(double)
,Math.rint(double)
-
modPow
public static int modPow(int base, int exp, int m)
Returnsbaseexp mod m
.
-
modulo
public static double modulo(double x, double y)
Preferx % y
ifx > 0
andy > 0
.
Example:eps = 0.1 ! move curves by eps to make superimposed curves visible x = { -200 : 200 } / 20 plot( x, x % 3 - eps, modulo( x, 3 ) + eps, IEEEremainder( x, 3 ) ).setXYLabels( "x", "y" ) $.setHeadline( "red: y = x % 3 | blue: y = modulo( x, 3 ) | green: y = IEEEremainder( x, 3 )" ) plot( x, x % -3 + eps, modulo( x, -3 ) - eps, IEEEremainder( x, -3 ) ).setXYLabels( "x", "y" ) $.setHeadline( "red: y = x % -3 | blue: y = modulo( x, -3 ) | green: y = IEEEremainder( x, -3 )" )
- Returns:
x % y + y
ifx < 0 exor y < 0
elsex % y
- See Also:
Math.IEEEremainder(double, double)
-
modulo
public static long modulo(long x, long y)
Preferx % y
ifx > 0
andy > 0
.- Returns:
x % y + y
ifx < 0 exor y < 0
elsex % y
-
modulo
public static int modulo(int x, int y)
Preferx % y
ifx > 0
andy > 0
.
Example:modulo( 7, 3 ) ! Note: 7 % 3 == 1 = 1 (int) modulo( -7, 3 ) ! Note: -7 % 3 == -1 = 2 (int) modulo( 7, -3 ) ! Note: 7 % -3 == 1 = -2 (int) modulo( -7, -3 ) ! Note: -7 % -3 == -1 = -1 (int)
- Returns:
x % y + y
ifx < 0 exor y < 0
elsex % y
-
__7_setField
protected void __7_setField()
Set public fields of an object or a class. (To be used, if the class does not provide setter methods for the fields).
-
set
public static Object set(Object o, String fieldName, Object value) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException
Sets a public field specified byfieldName
of an object or a class to the givenvalue
.
set( o, "fieldName", value )
is used in JXN instead ofo.fieldName = value.
set( "ClassName", "fieldName", value )
is used instead ofClassName.fieldName = value
(static field).- Parameters:
o
- object for which the field is to be changed or in case of a static field the class object or the classname as StringfieldName
- name of the field to be changedvalue
- new value of the field- Returns:
- old value of the field
- Throws:
ClassNotFoundException
NoSuchFieldException
IllegalAccessException
-
set
public static Object set(Object o, String fieldName, double value) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException
Sets a double field of an object or a class.
-
set
public static Object set(Object o, String fieldName, float value) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException
Sets a float field of an object or a class.
-
set
public static Object set(Object o, String fieldName, long value) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException
Sets a long field of an object or a class.
-
set
public static Object set(Object o, String fieldName, int value) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException
Sets a int field of an object or a class.
-
set
public static Object set(Object o, String fieldName, short value) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException
Sets a short field of an object or a class.
-
set
public static Object set(Object o, String fieldName, byte value) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException
Sets a byte field of an object or a class.
-
set
public static Object set(Object o, String fieldName, boolean value) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException
Sets a boolean field of an object or a class.
-
set
public static Object set(Object o, String fieldName, char value) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException
Sets a char field of an object or a class.
-
__8_array_operations
protected void __8_array_operations()
-
length
public static int length(Object ao)
Returns the length of the specified array object.
Shortcut forjava.lang.reflect.
Array.getLength(java.lang.Object)
-
get
public static Object get(Object ao, double x)
Returnsao[round(x)]
with array index limitted to0 <= index < ao.length
.
-
setArrayReturnOldValue
public static boolean setArrayReturnOldValue(boolean returnOldValue)
Controls if the set array methods return the old (overwriten) array value. By default the set methods return the array argument.
-
newArray
public static Object newArray(Class<?> componentType, int length)
Creates a new array with the specified component type and length.
Shortcut forjava.lang.reflect.Array.
newInstance
( componentType, length )
.
-
newArray
public static Object newArray(Class<?> componentType, int length, Object initial)
Creates a new array with the specified component type and length, initialized withinitial
.
-
newArray
public static Object newArray(int length, Object initial)
Creates a new array with the specified length, initialized withinitial
.- Returns:
newArray
( initial.getClass(), length, initial )
-
newArray
public static Object newArray(Class<?> componentType, int... dimensions)
Creates a new array with the specified component type and dimensions.
Shortcut forjava.lang.reflect.Array.
newInstance
( componentType, dimension... )
.
Example:da3x5 = newArray( Double.TYPE, { 3, 5 } )
-
set
public static Object set(Object[] array, int i, Object value)
Sets the value of thei
-th component ofarray
to the specified newvalue
.
In JXNset( array, i, value )
is used instead ofarray[i] = value
.
-
find
public static int find(Object[] array, Object o)
Searcharray
foro
.- Returns:
- first index
i
wherearray[i].equals(o)
or-1
if not found
-
find
public static int find(Object[] array, int fromIndex, Object o)
Searcharray
foro
starting fromfromIndex
.- Returns:
- first index
i
wherearray[i].equals(o)
or-1
if not found
-
doubleArray
public static Object doubleArray(int length)
Creates a new double array with the specified length. In JXN usedoubleArray(length)
instead ofnew double[length]
.
Shortcut fornewArray
( Double.TYPE, length )
.
-
doubleArray
public static Object doubleArray(int length, double initial)
Creates a new double array with the specified length, initialized withinitial
.
-
set
public static Object set(double[] array, int i, double value)
Shortcut forjava.lang.reflect.
Array.setDouble( Object array, int i, double value )
.
-
add
public static Object add(double[] array, int i, double value)
Addsvalue
toarray[i]
.
-
total
public static double total(double[] array)
Returns the sum of the values ofarray
.
-
cumulated
public static double[] cumulated(double[] array)
Returns a new array containing the partial (cumulated) sums of the values ofarray
.- Returns:
result[0] = array[0]; result[i] = result[i-1] + array[i]
fori = 1 ... n-1
-
differences
public static double[] differences(double[] array)
Returns a new array containing the differences of subsequent values ofarray
.- Returns:
result[i] = array[i+1] - array[i]
fori = 0 ... n-2
-
set
public static Object set(float[] array, int i, float value)
Shortcut forjava.lang.reflect.
Array.setFloat( Object array, int i, float value )
.
-
longArray
public static Object longArray(int length, long initial)
Creates a new long array with the specified length, initialized withinitial
.
-
set
public static Object set(long[] array, int i, long value)
Shortcut forjava.lang.reflect.
Array.setLong( Object array, int i, long value )
.
-
add
public static Object add(long[] array, int i, long value)
Addsvalue
toarray[i]
.
-
find
public static int find(long[] array, long value)
Searcharray
forvalue
.- Returns:
- first index
i
wherearray[i] == value
or-1
if not found
-
find
public static int find(long[] array, int fromIndex, long value)
Searcharray
forvalue
starting fromfromIndex
.- Returns:
- first index
i
wherearray[i] == value
or-1
if not found
-
total
public static long total(long[] array)
Returns the sum of the values ofarray
.
-
cumulated
public static long[] cumulated(long[] array)
Returns a new array containing the partial (cumulated) sums of the values ofarray
.- Returns:
result[0] = array[0]; result[i] = result[i-1] + array[i]
fori = 1 ... n-1
-
differences
public static long[] differences(long[] array)
Returns a new array containing the differences of subsequent values ofarray
.- Returns:
result[i] = array[i+1] - array[i]
fori = 0 ... n-2
-
intArray
public static Object intArray(int length)
Creates a new int array with the specified length. In JXN useintArray(length)
instead ofnew int[length]
.
Shortcut fornewArray
( Integer.TYPE, length )
.
-
intArray
public static Object intArray(int length, int initial)
Creates a new int array with the specified length, initialized withinitial
.
-
set
public static Object set(int[] array, int i, int value)
Shortcut forjava.lang.reflect.
Array.setInt( Object array, int i, int value )
.
-
add
public static Object add(int[] array, int i, int value)
Addsvalue
toarray[i]
.
-
find
public static int find(int[] array, int value)
Searcharray
forvalue
.- Returns:
- first index
i
wherearray[i] == value
or-1
if not found
-
find
public static int find(int[] array, int fromIndex, int value)
Searcharray
forvalue
starting fromfromIndex
.- Returns:
- first index
i
wherearray[i] == value
or-1
if not found
-
total
public static int total(int[] array)
Returns the sum of the values ofarray
.
-
cumulated
public static int[] cumulated(int[] array)
Returns a new array containing the partial (cumulated) sums of the values ofarray
.- Returns:
result[0] = array[0]; result[i] = result[i-1] + array[i]
fori = 1 ... n-1
-
differences
public static int[] differences(int[] array)
Returns a new array containing the differences of subsequent values ofarray
.- Returns:
result[i] = array[i+1] - array[i]
fori = 0 ... n-2
-
set
public static Object set(short[] array, int i, short value)
Shortcut forjava.lang.reflect.
Array.setShort( Object array, int i, short value )
.
-
byteArray
public static Object byteArray(int length)
Creates a new byte array with the specified length. In JXN usebyteArray(length)
instead ofnew byte[length]
.
Shortcut fornewArray
( Byte.TYPE, length )
.
-
byteArray
public static Object byteArray(int length, byte initial)
Creates a new byte array with the specified length, initialized withinitial
.
-
set
public static Object set(byte[] array, int i, byte value)
Shortcut forjava.lang.reflect.
Array.setByte( Object array, int i, byte value )
.
-
add
public static Object add(byte[] array, int i, byte value)
Addsvalue
toarray[i]
with overflow, if the result does not fit into byte.
-
find
public static int find(byte[] array, byte value)
Searcharray
forvalue
.- Returns:
- first index
i
wherearray[i] == value
or-1
if not found
-
find
public static int find(byte[] array, int fromIndex, byte value)
Searcharray
forvalue
starting fromfromIndex
.- Returns:
- first index
i
wherearray[i] == value
or-1
if not found
-
total
public static int total(byte[] array)
Returns theint
sum of the values ofarray
.
-
booleanArray
public static Object booleanArray(int length, boolean initial)
Creates a new boolean array with the specified length, initialized withinitial
.
-
set
public static Object set(boolean[] array, int i, boolean value)
Shortcut forjava.lang.reflect.
Array.setBoolean( Object array, int i, boolean value )
.
-
flip
public static Object flip(boolean[] array, int i)
Togglesarray[i]
.
-
find
public static int find(boolean[] array, boolean value)
Searcharray
forvalue
.- Returns:
- first index
i
wherearray[i] == value
or-1
if not found
-
find
public static int find(boolean[] array, int fromIndex, boolean value)
Searcharray
forvalue
starting fromfromIndex
.- Returns:
- first index
i
wherearray[i] == value
or-1
if not found
-
total
public static int total(boolean[] array)
Returns the number oftrue
values inarray
.
-
any
public static boolean any(boolean[] array)
Returns true, if at least one value inarray
is true.
-
all
public static boolean all(boolean[] array)
Returns true, if all values inarray
are true.
-
set
public static Object set(char[] array, int i, char value)
Shortcut forjava.lang.reflect.
Array.setChar( Object array, int i, char value )
.
-
find
public static int find(char[] array, char value)
Searcharray
forvalue
.- Returns:
- first index
i
wherearray[i] == value
or-1
if not found
-
find
public static int find(char[] array, int fromIndex, char value)
Searcharray
forvalue
starting fromfromIndex
.- Returns:
- first index
i
wherearray[i] == value
or-1
if not found
-
concat
public static Object concat(Object arr1, Object arr2)
Returns a new array containing the elements of arrayarr1
followed by the elements of arrayarr2
.
arr1
andarr2
may be primitive or object arrays but must be of compatible type.
Usesjava.lang.System.
arraycopy
.
-
concat
public static Object concat(Object... arrays)
Returns a new array containing the elements of all arrays passed as arguments.
arrays
may be primitive or object arrays but must be of compatible type.
Usesjava.lang.System.
arraycopy
.
Usage in jxn:concat( { arr1, arr2, arr3 } )
-
toArray
public static Object toArray(Object ao)
CallstoArray( ao, 0 )
.
-
toArray
public static Object toArray(Object ao, int mode)
Check, ifao
is an array or try to callao.toArray()
.
In addition toKmgStaticUtilities.toArray(java.lang.Object)
narrows the result type.- Parameters:
ao
- array or instance of a class that implements atoArray()
methodmode
- controlls what to do, if ao is not an array and atoArray()
method is not available for ao
-1 : throws Exception
0 : returnsnull
1 : returns array withao
as the single element
2 : returnsao
- Returns:
ao
, ifao
is an array else
ao.toArray()
, iftoArray()
method is available else
see parametermode
-
stringArray
public static String[] stringArray(String csvList, String delimChars)
Returns array of tokens fromStringTokenizer.nextToken()
.- Parameters:
delimChars
- passed to ajava.util.
StringTokenizer
( csvList, delimChars )
- See Also:
split(java.lang.String, java.lang.String)
,KmgStringTokenizer
-
stringArray
public static String[] stringArray(String csvList)
Deprecated.In JXN prefer{ "abc", "xyz" }
.
-
doubleArray
public static double[] doubleArray(String csvList)
Deprecated.In JXN prefer{ 2., 3., 5., 7. }
.
-
intArray
public static int[] intArray(String csvList)
Deprecated.In JXN prefer{ 123, 456, 789 }
.
-
getClass
public static Class getClass(Object ao)
Deprecated.No more needed: Simply callao.getClass()
. To calljava.lang.Object.getClass()
on the array elements ofao
useJxnObject.getClassArray(ao)
.Returns the class of an objectao
(workaround for array objects in JXN). The automatic array feature of JXN calls methods on the component objects of an array rather than on the array object itself. This inhibits the call of methods ofjava.lang.Object
especiallygetClass()
on an array object. In JXNao.getClass()
(other than in Java) returns ajava.lang.Class
[]
array containing the component types. As a workaround to get the class of an array objectgetClass(ao)
is used instead ofao.getClass()
.- Returns:
ao.getClass()
(java.lang.Object
)
-
hashCode
public static int hashCode(Object ao)
Deprecated.No more needed: Simply callao.hashCode()
. To calljava.lang.Object.hashCode()
on the array elements ofao
useJxnObject.hashCode( @JxnUnroll ao )
.Returns the hash code value ofao
(workaround for array objects in JXN). As described for thegetClass
method forao.hashCode()
in JXN in case of an arrayao
thehashCode
method is called on the array components ofao
rather than on the array object itself. As a workaroundhashCode(ao)
is used instead ofao.hashCode()
.- Returns:
ao.hashCode()
(java.lang.Object
)
-
equals
public static boolean equals(Object o1, Object o2)
Deprecated.No more needed: Simply callo1.equals(o2)
. To calljava.lang.Object.equals(Object)
on the array elements ofarr1
with argument arrayarr2
useJxnObject.equals( @JxnUnroll arr1, @JxnUnroll arr2 )
.Checks if two objects are equal(workaround for array objects in JXN). As described for the.getClass
method foro1.equals(o2)
in JXN in case of an arrayo1
theequals
method is called on the array components ofo1
rather than on the array object itself. As a workaroundequals(o1,o2)
is used instead ofo1.equals(o2)
to compare an array objecto1
to another objecto2
(for array objectsequals(o1,o2)
is true, ifo1 == o2
(both variableso1
ando2
refering to the same object))
-
__9_boolean_operators
protected void __9_boolean_operators()
-
not
public static boolean not(boolean x)
Represents the Java boolean operator. For a booleanx
in JXN-x
can be used instead ofnot(x)
.- Returns:
- ! x
-
and
public static boolean and(boolean x, boolean y)
Represents the Java boolean operator. For booleansx
andy
in JXNx*y
can be used instead ofand(x,y)
.- Returns:
- x
&&
y
-
or
public static boolean or(boolean x, boolean y)
Represents the Java boolean operator. For booleansx
andy
in JXNx+y
can be used instead ofor(x,y)
.- Returns:
- x
||
y
-
exor
public static boolean exor(boolean x, boolean y)
Represents the Java boolean operator. For booleansx
andy
in JXNx^y
can be used instead ofexor(x,y)
.- Returns:
- x ^ y (using the Java boolean exor operator !!)
-
_10_bitwise_operators
protected void _10_bitwise_operators()
-
not
public static long not(long x)
Represents the Java bitwise operator (for long).- Returns:
- ~x
-
not
public static int not(int x)
Represents the Java bitwise operator (for int).- Returns:
- ~x
-
and
public static long and(long x, long y)
Represents the Java bitwise operator (for long).- Returns:
- x & y
-
and
public static int and(int x, int y)
Represents the Java bitwise operator (for int).- Returns:
- x & y
-
or
public static long or(long x, long y)
Represents the Java bitwise operator (for long).- Returns:
- x | y
-
or
public static int or(int x, int y)
Represents the Java bitwise operator (for int).- Returns:
- x | y
-
exor
public static long exor(long x, long y)
Represents the Java bitwise operator (for long). Note: in jxn the ^ operator ist used to representpow(x,y)
.- Returns:
- x ^ y (using the Java bitwise exor operator !!)
-
exor
public static int exor(int x, int y)
Represents the Java bitwise operator (for int). Note: in jxn the ^ operator ist used to representpow(x,y)
.- Returns:
- x ^ y (using the Java bitwise exor operator !!)
-
left
public static long left(long x, int i)
Represents the Java bit shift operator (for long).- Returns:
- x << i
-
left
public static int left(int x, int i)
Represents the Java bit shift operator (for int).- Returns:
- x << i
-
right
public static long right(long x, int i)
Represents the Java bit shift operator (for long).- Returns:
- x >> i
-
right
public static int right(int x, int i)
Represents the Java bit shift operator (for int).- Returns:
- x >> i
-
right0
public static long right0(long x, int i)
Represents the Java bit shift operator (for long).- Returns:
- x >>> i
-
right0
public static int right0(int x, int i)
Represents the Java bit shift operator (for int).- Returns:
- x >>> i
-
_11_relational_operators
protected void _11_relational_operators()
-
eq
public static boolean eq(double x, double y)
Represents the Java relational operator.- Returns:
- x == y
-
eq
public static boolean eq(long x, long y)
Represents the Java relational operator.- Returns:
- x == y
-
eq
public static boolean eq(boolean x, boolean y)
Represents the Java relational operator.- Returns:
- x == y
-
ne
public static boolean ne(double x, double y)
Represents the Java relational operator.- Returns:
- x != y
-
ne
public static boolean ne(long x, long y)
Represents the Java relational operator.- Returns:
- x != y
-
ne
public static boolean ne(boolean x, boolean y)
Represents the Java relational operator.- Returns:
- x != y
-
lt
public static boolean lt(double x, double y)
Represents the Java relational operator.- Returns:
- x < y
-
lt
public static boolean lt(long x, long y)
Represents the Java relational operator.- Returns:
- x < y
-
le
public static boolean le(double x, double y)
Represents the Java relational operator.- Returns:
- x <= y
-
le
public static boolean le(long x, long y)
Represents the Java relational operator.- Returns:
- x <= y
-
gt
public static boolean gt(double x, double y)
Represents the Java relational operator.- Returns:
- x > y
-
gt
public static boolean gt(long x, long y)
Represents the Java relational operator.- Returns:
- x > y
-
ge
public static boolean ge(double x, double y)
Represents the Java relational operator.- Returns:
x >= y
-
ge
public static boolean ge(long x, long y)
Represents the Java relational operator.- Returns:
- x >= y
-
isSame
public static boolean isSame(Object x, Object y)
Returns true if x == y (references to the same (identical) instance).- Returns:
- x == y
- See Also:
Object.equals(java.lang.Object)
-
isNull
public static boolean isNull(Object o)
Returns true if o == null.- Returns:
- o == null.
-
isNull
public static boolean isNull(double x)
Allows the generic check of arbitrary variables (e.g.arguments passed to jxn files). A variable may be an object or a Java primitve. In case of a primitive theisNull(Object)
method does not match. Instead this method is called and always returns false;- Returns:
- always returns false
-
isPrimitiveOrJavaWrapper
public static boolean isPrimitiveOrJavaWrapper(Object x)
Used in jxn files to check the type ofx
. Called in jxn files forisPrimitiveOrJavaWrapper(x)
ifx
is an object reference (except Java primitive wrapper). Also consider:JxnObject
.getClass(x).isPrimitive()
(returnsfalse
for Java primitive wrapper).- Returns:
- false
-
isPrimitiveOrJavaWrapper
public static boolean isPrimitiveOrJavaWrapper(double x)
Used in jxn files to check the type ofx
. Called in jxn files forisPrimitiveOrJavaWrapper(x)
ifx
is a primitive or Java primitive wrapper. Also consider:JxnObject
.getClass(x).isPrimitive()
(returnsfalse
for Java primitive wrapper).- Returns:
- true
-
isArray
public static boolean isArray(Object o)
Returns true if o is an array (null returns false).
-
contains
public static boolean contains(String chars, char ch)
Returns true ifchars
containsch
.
-
_12_formula_switching
protected void _12_formula_switching()
-
sw
public static int sw(int ivar, double slider_switch)
Returns1
ifivar-0.5 <= slider_switch < ivar+0.5
else0
.
-
sw
public static double sw(boolean b, double yTrue, double yFalse)
ReturnsyTrue
, ifb
is true elseyFalse
.
-
sw
public static long sw(boolean b, long yTrue, long yFalse)
ReturnsyTrue
, ifb
is true elseyFalse
.
-
sw
public static int sw(boolean b, int yTrue, int yFalse)
ReturnsyTrue
, ifb
is true elseyFalse
.
-
sw
public static Object sw(boolean b, Object oTrue, Object oFalse)
ReturnsoTrue
, ifb
is true elseoFalse
.
-
sw
public static double sw(double x, double yLT, double yGE)
ReturnsyLT
, ifx < 0.
elseyGE
.
-
sw
public static long sw(double x, long yLT, long yGE)
ReturnsyLT
, ifx < 0.
elseyGE
.
-
sw
public static int sw(double x, int yLT, int yGE)
ReturnsyLT
, ifx < 0.
elseyGE
.
-
sw
public static double sw(double x, double yLT, double yEQ, double yGT)
ReturnsyLT
, ifx < 0.
elseyGT
, ifx > 0.
elseyEQ
.
-
sw
public static long sw(double x, long yLT, long yEQ, long yGT)
ReturnsyLT
, ifx < 0.
elseyGT
, ifx > 0.
elseyEQ
.
-
sw
public static int sw(double x, int yLT, int yEQ, int yGT)
ReturnsyLT
, ifx < 0.
elseyGT
, ifx > 0.
elseyEQ
.
-
sw
public static Object sw(double x, Object oLT, Object oEQ, Object oGT)
ReturnsoLT
, ifx < 0
elseoGT
, ifx > 0
elseoEQ
.
-
sw
public static double sw(double x, double eps, double yLower, double yInner, double yUpper)
ReturnsyLower
, ifx < -eps
elseyUpper
, ifx > eps
elseyInner
.
-
sw
public static Object sw(double x, double eps, Object oLower, Object oInner, Object oUpper)
ReturnsoLower
, ifx < -eps
elseoUpper
, ifx > eps
elseoInner
.
-
sw
public static double sw(double x, double xLower, double xUpper, double yLower, double yInner, double yUpper)
ReturnsyLower
, ifx < xLower
elseyUpper
, ifx > xUpper
elseyInner
.
-
sw
public static Object sw(double x, double xLower, double xUpper, Object oLower, Object oInner, Object oUpper)
ReturnsoLower
, ifx < xLower
elseoUpper
, ifx > xUpper
elseoInner
.
-
limit
public static double limit(double x, double xmin, double xmax)
Keepsx
withinxmin
andxmax
.- Returns:
xmin
, ifx < xmin
elsexmax
, ifx > xmax
elsex
.
-
limit
public static long limit(long x, long xmin, long xmax)
Keepsx
withinxmin
andxmax
.- Returns:
xmin
, ifx < xmin
elsexmax
, ifx > xmax
elsex
.
-
limit
public static int limit(int x, int xmin, int xmax)
Keepsx
withinxmin
andxmax
.- Returns:
xmin
, ifx < xmin
elsexmax
, ifx > xmax
elsex
.
-
clip
public static double clip(double x, double lower, double upper)
- Returns:
if( lower < upper ) x if lower <= x <= upper Double.NaN else else if( lower > upper ) Double.NaN if upper < x < lower x else else // lower == upper Double.NaN if lower == x == upper x else
- See Also:
JxnRealArrayAlgebra.clip(JxnRealArrayAlgebra, double, double)
-
-