public final class M5StaticUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static double |
log2
The natural logarithm of 2.
|
static double |
SMALL
The small deviation allowed in double comparisons
|
Constructor and Description |
---|
M5StaticUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
backQuoteChars(java.lang.String string)
Converts carriage returns and new lines in a string into \r and \n.
|
static void |
checkForRemainingOptions(java.lang.String[] options)
Checks if the given array contains any non-empty options.
|
static java.lang.String |
convertNewLines(java.lang.String string)
Converts carriage returns and new lines in a string into \r and \n.
|
static java.lang.String |
doubleToString(double value,
int afterDecimalPoint)
Rounds a double and converts it into String.
|
static java.lang.String |
doubleToString(double value,
int width,
int afterDecimalPoint)
Rounds a double and converts it into a formatted decimal-justified String.
|
static boolean |
eq(double a,
double b)
Tests if a is equal to b.
|
static boolean |
getFlag(char flag,
java.lang.String[] options)
Checks if the given array contains the flag "-Char".
|
static java.lang.String |
getOption(char flag,
java.lang.String[] options)
Gets an option indicated by a flag "-Char" from the given array
of strings.
|
static boolean |
gr(double a,
double b)
Tests if a is smaller than b.
|
static boolean |
grOrEq(double a,
double b)
Tests if a is greater or equal to b.
|
static double |
info(int[] counts)
Computes entropy for an array of integers.
|
static java.lang.String |
joinOptions(java.lang.String[] optionArray)
Joins all the options in an option array into a single string,
as might be used on the command line.
|
static double |
log2(double a)
Returns the logarithm of a for base 2.
|
static int |
maxIndex(double[] doubles)
Returns index of maximum element in a given
array of doubles.
|
static int |
maxIndex(int[] ints)
Returns index of maximum element in a given
array of integers.
|
static double |
mean(double[] vector)
Computes the mean for an array of doubles.
|
static int |
minIndex(double[] doubles)
Returns index of minimum element in a given
array of doubles.
|
static int |
minIndex(int[] ints)
Returns index of minimum element in a given
array of integers.
|
static void |
normalize(double[] doubles)
Normalizes the doubles in the array by their sum.
|
static void |
normalize(double[] doubles,
double sum)
Normalizes the doubles in the array using the given value.
|
static java.lang.String |
padLeft(java.lang.String inString,
int length)
Pads a string to a specified length, inserting spaces on the left
as required.
|
static java.lang.String |
padRight(java.lang.String inString,
int length)
Pads a string to a specified length, inserting spaces on the right
as required.
|
static java.lang.String[] |
partitionOptions(java.lang.String[] options)
Returns the secondary set of options (if any) contained in
the supplied options array.
|
static java.lang.String |
quote(java.lang.String string)
Quotes a string if it contains special characters.
|
static java.lang.String |
removeSubstring(java.lang.String inString,
java.lang.String substring)
Removes all occurrences of a string from another string.
|
static java.lang.String |
replaceSubstring(java.lang.String inString,
java.lang.String subString,
java.lang.String replaceString)
Replaces with a new string, all occurrences of a string from
another string.
|
static int |
round(double value)
Rounds a double to the next nearest integer value.
|
static double |
roundDouble(double value,
int afterDecimalPoint)
Rounds a double to the given number of decimal places.
|
static boolean |
sm(double a,
double b)
Tests if a is smaller than b.
|
static boolean |
smOrEq(double a,
double b)
Tests if a is smaller or equal to b.
|
static int[] |
sort(double[] array)
Sorts a given array of doubles in ascending order and returns an
array of integers with the positions of the elements of the
original array in the sorted array.
|
static int[] |
sort(int[] array)
Sorts a given array of integers in ascending order and returns an
array of integers with the positions of the elements of the original
array in the sorted array.
|
static int[] |
stableSort(double[] array)
Sorts a given array of doubles in ascending order and returns an
array of integers with the positions of the elements of the original
array in the sorted array.
|
static double |
sum(double[] doubles)
Computes the sum of the elements of an array of doubles.
|
static int |
sum(int[] ints)
Computes the sum of the elements of an array of integers.
|
static double |
variance(double[] vector)
Computes the variance for an array of doubles.
|
static double |
xlogx(int c)
Returns c*log2(c) for a given integer value c.
|
public static double log2
public static double SMALL
public static java.lang.String removeSubstring(java.lang.String inString, java.lang.String substring)
inString
- the string to remove substrings from.substring
- the substring to remove.public static java.lang.String replaceSubstring(java.lang.String inString, java.lang.String subString, java.lang.String replaceString)
inString
- the string to replace substrings in.subString
- the substring to replace.replaceString
- the replacement substringpublic static java.lang.String padLeft(java.lang.String inString, int length)
inString
- the input stringlength
- the desired length of the output stringpublic static java.lang.String padRight(java.lang.String inString, int length)
inString
- the input stringlength
- the desired length of the output stringpublic static java.lang.String doubleToString(double value, int afterDecimalPoint)
value
- the double valueafterDecimalPoint
- the (maximum) number of digits permitted
after the decimal pointpublic static java.lang.String doubleToString(double value, int width, int afterDecimalPoint)
value
- the double valuewidth
- the width of the stringafterDecimalPoint
- the number of digits after the decimal pointpublic static boolean eq(double a, double b)
a
- a doubleb
- a doublepublic static void checkForRemainingOptions(java.lang.String[] options) throws java.lang.Exception
options
- strings an array of stringsjava.lang.Exception
- if there are any non-empty optionspublic static boolean getFlag(char flag, java.lang.String[] options) throws java.lang.Exception
flag
- the character indicating the flag.options
- strings the array of strings containing all the options.java.lang.Exception
- if an illegal option was foundpublic static java.lang.String getOption(char flag, java.lang.String[] options) throws java.lang.Exception
flag
- the character indicating the option.options
- the array of strings containing all the options.java.lang.Exception
- if the option indicated by the flag can't be foundpublic static java.lang.String quote(java.lang.String string)
string
- the string to be quotedpublic static java.lang.String backQuoteChars(java.lang.String string)
string
- the stringpublic static java.lang.String convertNewLines(java.lang.String string)
string
- the stringpublic static java.lang.String[] partitionOptions(java.lang.String[] options)
options
- the input array of optionspublic static java.lang.String joinOptions(java.lang.String[] optionArray)
optionArray
- the array of optionspublic static double info(int[] counts)
counts
- array of countspublic static boolean smOrEq(double a, double b)
a
- a doubleb
- a doublepublic static boolean grOrEq(double a, double b)
a
- a doubleb
- a doublepublic static boolean sm(double a, double b)
a
- a doubleb
- a doublepublic static boolean gr(double a, double b)
a
- a doubleb
- a doublepublic static double log2(double a)
a
- a doublepublic static int maxIndex(double[] doubles)
doubles
- the array of doublespublic static int maxIndex(int[] ints)
ints
- the array of integerspublic static double mean(double[] vector)
vector
- the arraypublic static int minIndex(int[] ints)
ints
- the array of integerspublic static int minIndex(double[] doubles)
doubles
- the array of doublespublic static void normalize(double[] doubles)
doubles
- the array of doublejava.lang.IllegalArgumentException
- if sum is Zero or NaNpublic static void normalize(double[] doubles, double sum)
doubles
- the array of doublesum
- the value by which the doubles are to be normalizedjava.lang.IllegalArgumentException
- if sum is zero or NaNpublic static int round(double value)
value
- the double valuepublic static double roundDouble(double value, int afterDecimalPoint)
value
- the double valueafterDecimalPoint
- the number of digits after the decimal pointpublic static int[] sort(int[] array)
array
- this array is not changed by the method!public static int[] sort(double[] array)
array
- this array is not changed by the method!public static int[] stableSort(double[] array)
array
- this array is not changed by the method!public static double variance(double[] vector)
vector
- the arraypublic static double sum(double[] doubles)
doubles
- the array of doublepublic static int sum(int[] ints)
ints
- the array of integerspublic static double xlogx(int c)
c
- an integer value