com.planet_ink.coffee_mud.core
Class CMath

java.lang.Object
  extended by com.planet_ink.coffee_mud.core.CMath

public class CMath
extends java.lang.Object

A core singleton class handling various mathematical operations and functions, especially dealing with explicit type conversions, and special string conversions and functions.


Nested Class Summary
static class CMath.CompiledFormula
          A class representing a a list of compiled operation in a complete formula.
static class CMath.CompiledOperation
          A class representing a single piece of a compiled operation.
 
Field Summary
static java.util.Random NotRandomHigh
          A class that extends Random, only it always returns the highest possible values for each method.
 
Method Summary
static java.lang.String abbreviateLong(long l)
          Returns an abbreviation of the given long, giving 2 significant digits after the decimal, and returning k, M, G, T, P, or E for the power base 1000.
static double abs(double d)
           
static float abs(float d)
           
static int abs(int val)
          Returns the absolute value (X>=0) of the given number
static long abs(long val)
          Returns the absolute value (X>=0) of the given number
static long absDiff(long x, long y)
          Returns the absolute difference between two numbers
static java.lang.String appendNumAppendage(int num)
          Append st,nd,rd for a number
static boolean banyset(int num, int bitmask)
          Returns true if any of the bits represented by the given bitmask are set in the given number.
static boolean banyset(long num, int bitmask)
          Returns true if any of the bits represented by the given bitmask are set in the given number.
static boolean banyset(long num, long bitmask)
          Returns true if any of the bits represented by the given bitmask are set in the given number.
static java.math.BigInteger bigMultiply(double l1, long l2)
          Generates a big integer from multiply two numbers, rounding when necessary
static java.math.BigInteger bigMultiply(long l1, long l2)
          Generates a big integer from multiply two longs
static int bitNumber(long mask)
          Returns the first set bit number of the bitmask given
static boolean bset(int num, int bitmask)
          Returns true if the given number has the bits represented by the given bitmask set.
static boolean bset(long num, int bitmask)
          Returns true if the given number has the bits represented by the given bitmask set.
static boolean bset(long num, long bitmask)
          Returns true if the given number has the bits represented by the given bitmask set.
static boolean bset(short num, short bitmask)
          Returns true if the given number has the bits represented by the given bitmask set.
static double ceiling(double d)
           
static float ceiling(float d)
           
static CMath.CompiledFormula compileMathExpression(java.lang.String formula)
          Pre-compiles an expression for faster evaluation later on.
static int convertFromRoman(java.lang.String s)
          Convert a number from roman numeral to integer.
static java.lang.String convertToRoman(int i)
          Convert an integer to its Roman Numeral equivalent Usage: Return=convertToRoman(Number)+".";
static double div(double a, double b)
          Divide a by b, making sure both are cast to doubles and that the return is precisely double.
static double div(double a, int b)
          Divide a by b, making sure both are cast to doubles and that the return is precisely double.
static double div(double a, long b)
          Divide a by b, making sure both are cast to doubles and that the return is precisely double.
static double div(int a, double b)
          Divide a by b, making sure both are cast to doubles and that the return is precisely double.
static double div(int a, int b)
          Divide a by b, making sure both are cast to doubles and that the return is precisely double.
static double div(long a, double b)
          Divide a by b, making sure both are cast to doubles and that the return is precisely double.
static double div(long a, long b)
          Divide a by b, making sure both are cast to doubles and that the return is precisely double.
static int dobit(int num, int bitmask, boolean setOrUnSet)
          Sets or Unsets those bits in the given number which are turned ON or OFF in the given bitmask.
protected  double doOperation(char operation, double finalValue, double curValue)
          Performs the operation between the finalValue and the curValue.
static int firstBitSetIndex(int bits)
          Returns the bit index (0 based) of the first bit set in the given mask.
static double floor(double d)
           
static float floor(float d)
           
static int[] getAllBitsSet(int bits)
          Returns the bit index (0 based) of the first bit set in the given mask.
static java.util.Map.Entry<java.lang.Integer,java.lang.String> getNumberFollowedByString(java.lang.String str)
          Returns a number/string pair built from a given string, if it is a string with a number followed by one or more characters.
static int[] getSeperateBitMasks(int mask)
          Given a bitmask, seperates the mask according to which bits are set and returns those original values in an array where each entry is the value of each bit
static long[] getSeperateBitMasks(long mask)
          Given a bitmask, seperates the mask according to which bits are set and returns those original values in an array where each entry is the value of each bit
static java.util.Map.Entry<java.lang.String,java.lang.Integer> getStringFollowedByNumber(java.lang.String str, boolean romanOK)
          If the given string is 1 or more characters followed by decimal digits, this will return a Map.Entry with those parts separated.
static double greater(double a, double b)
          Returns greater of two numbers
static int hexDigit(char c)
          Converts a single hex digit to an int
static CMath instance()
           
static boolean isBool(java.lang.String BOOL)
          Returns whether the given string is a boolean value Usage: if(isBool(CMD.substring(14)));
static boolean isDouble(java.lang.String DBL)
          Returns whether the given string is a double value Usage: if(isDouble(CMD.substring(14)));
static boolean isFloat(java.lang.String DBL)
          Returns whether the given string is a float value Usage: if(isFloat(CMD.substring(14)));
static boolean isInteger(java.lang.String INT)
          Returns whether the given string is a int value Usage: if(isInteger(CMD.substring(14)));
static boolean isLong(java.lang.String LONG)
          Returns whether the given string is a long value Usage: if(isLong(CMD.substring(14)));
static boolean isMathExpression(java.lang.String st)
          Returns whether the given string is a valid math expression (5 + 7)/2, etc.
static boolean isMathExpression(java.lang.String st, double[] vars)
          Returns whether the given string is a valid math expression (@x1 + 7)/2, etc.
static boolean isNumber(java.lang.String s)
          Returns true if the string is a number (float or int)
static boolean isNumberFollowedByString(java.lang.String str)
          Returns whether the given string is a number followed by 1 or more characters.
static boolean isPct(java.lang.String s)
          Returns true if the given string represents a percentage in the form X% where X is any real number.
static boolean isRomanDigit(char c)
          Return true if the char is a roman numeral digit
static boolean isRomanNumeral(java.lang.String s)
          Returns true if the string is a roman numeral
static boolean isSet(int number, int bitnumber)
          Returns true if the bitnumberth bit (0...) is set in the given number
static boolean isSet(long number, int bitnumber)
          Returns true if the bitnumberth bit (0...) is set in the given number
static double mul(double a, double b)
          Multiply a and b, making sure both are cast to doubles and that the return is precisely double.
static double mul(double a, int b)
          Multiply a and b, making sure both are cast to doubles and that the return is precisely double.
static double mul(double a, long b)
          Multiply a and b, making sure both are cast to doubles and that the return is precisely double.
static double mul(int a, double b)
          Multiply a and b, making sure both are cast to doubles and that the return is precisely double.
static int mul(int a, int b)
          Multiply a and b, making sure both are cast to doubles and that the return is precisely double.
static double mul(long a, double b)
          Multiply a and b, making sure both are cast to doubles and that the return is precisely double.
static long mul(long a, long b)
          Multiply a and b, making sure both are cast to doubles and that the return is precisely double.
static java.lang.String numAppendage(int num)
          Return st,nd,rd for a number
static int numberOfSetBits(int i)
          Returns how many bits are set in the given 32 bit int
static int numberOfSetBits(long i)
          Returns how many bits are set in the given 64 bit long
static int parseIntExpression(java.lang.String formula)
          Returns the result of evaluating the given math expression.
static int parseIntExpression(java.lang.String formula, double[] vars)
          Returns the result of evaluating the given math expression.
static long parseLongExpression(java.lang.String formula)
          Returns the result of evaluating the given math expression.
static long parseLongExpression(java.lang.String formula, double[] vars)
          Returns the result of evaluating the given math expression.
static double parseMathExpression(CMath.CompiledFormula list, double[] vars, double previous)
          Parse a pre-compiled expression.
static double parseMathExpression(CMath.CompiledFormula list, java.util.Random rand, double[] vars, double previous)
          Parse a pre-compiled expression.
static double parseMathExpression(java.lang.String formula)
          Returns the result of evaluating the given math expression.
static double parseMathExpression(java.lang.String formula, double[] vars)
          Returns the result of evaluating the given math expression.
static long pow(long x, long y)
          Raises x to the y power, making sure both are cast to doubles and that the return is rounded off.
static double random()
           
static void replaceVariables(java.lang.StringBuffer str, double[] values)
          Replaces @x1 type variables inside a stringbuffer with an actual value Not used in the main expression system, this is a stand alone function Also uniquely, supports @x numbers above 10.
static java.lang.String replaceVariables(java.lang.String str, double[] values)
          Replaces @x1 type variables inside a stringbuffer with an actual value Not used in the main expression system, this is a stand alone function Also uniquely, supports @x numbers above 10.
static long round(double d)
           
static long round(float d)
           
static boolean s_bool(java.lang.String BOOL)
          Returns the boolean value of a string without crashing Usage: int num=s_bool(CMD.substring(14));
static double s_double(java.lang.String DOUBLE)
          Returns the double value of a string without crashing Usage: dSize = WebIQBase.s_double(WebIQBase.getRes(AttStatsRes,"BlobSize"));
static float s_float(java.lang.String FLOAT)
          Returns the floating point value of a string without crashing Usage: lSize = WebIQBase.s_float(WebIQBase.getRes(AttStatsRes,"BlobSize"));
static int s_int(java.lang.String INT)
          Returns the integer value of a string without crashing Usage: int num=s_int(CMD.substring(14));
static int s_int(java.lang.String INT, int def)
          Returns the integer value of a string without crashing Usage: int num=s_int(CMD.substring(14));
static int s_intOf(java.lang.Object O)
          Converts the given object into an iteger, if it can
static long s_long(java.lang.String LONG)
          Returns the long value of a string without crashing Usage: lSize = WebIQBase.s_long(WebIQBase.getRes(AttStatsRes,"BlobSize"));
static int s_parseBitIntExpression(java.lang.String[] bits, java.lang.String val)
          Returns a int representing either the given value, or the 2^ power of the comma separated values in the order they appear in the given string list.
static long s_parseBitLongExpression(java.lang.String[] bits, java.lang.String val)
          Returns a long representing either the given value, or the 2^ power of the comma separated values in the order they appear in the given string list.
static int s_parseIntExpression(java.lang.String st)
          Returns the result of evaluating the given math expression.
static int s_parseIntExpression(java.lang.String st, double[] vars)
          Returns the result of evaluating the given math expression.
static int s_parseListIntExpression(java.lang.String[] descs, java.lang.String val)
          Returns a int representing either the given value, or the index of the value in the order they appear in the given string list.
static long s_parseListLongExpression(java.lang.String[] descs, java.lang.String val)
          Returns a long representing either the given value, or the index of the value in the order they appear in the given string list.
static long s_parseLongExpression(java.lang.String st)
          Returns the result of evaluating the given math expression.
static long s_parseLongExpression(java.lang.String st, double[] vars)
          Returns the result of evaluating the given math expression.
static double s_parseMathExpression(java.lang.String st)
          Returns the result of evaluating the given math expression.
static double s_parseMathExpression(java.lang.String st, double[] vars)
          Returns the result of evaluating the given math expression.
static double s_pct(java.lang.String s)
          Converts the given string to a floating point number, 1>=N>=0, representing the whole percentage of the string.
static short s_short(java.lang.String SHORT)
          Returns the short value of a string without crashing Usage: int num=s_short(CMD.substring(14));
static java.lang.Enum<? extends java.lang.Enum> s_valueOf(java.lang.Class<? extends java.lang.Enum> c, java.lang.String s)
          Returns the matching enum.
static java.lang.Enum<? extends java.lang.Enum> s_valueOf(java.lang.Class<? extends java.lang.Enum> c, java.lang.String s, java.lang.Enum<? extends java.lang.Enum> def)
          Returns the matching enum.
static java.lang.Object s_valueOf(java.lang.Object[] o, java.lang.String s)
          Returns which object in the object array is same as the string, when cast to a string.
static int setb(int num, int bitmask)
          Returns the given number, after having set the bits represented by the given bit mask.
static long setb(long num, int bitmask)
          Returns the given number, after having set the bits represented by the given bit mask.
static long setb(long num, long bitmask)
          Returns the given number, after having set the bits represented by the given bit mask.
static void setRand(java.util.Random rand)
          Replaces the internal Random object with the one passed in.
static double sqrt(double d)
           
static float sqrt(float d)
           
static int squared(int x)
          Returns x, squared, after being case to a double
static java.lang.String toPct(double d)
          Converts a percentage 1>d>0 to a string.
static java.lang.String toPct(java.lang.String s)
          Converts the string to a double percentage and then converts that back to a percentage.
static int unsetb(int num, int bitmask)
          Unsets those bits in the given number which are turned ON in the given bitmask.
static long unsetb(long num, int bitmask)
          Unsets those bits in the given number which are turned ON in the given bitmask.
static long unsetb(long num, long bitmask)
          Unsets those bits in the given number which are turned ON in the given bitmask.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NotRandomHigh

public static final java.util.Random NotRandomHigh
A class that extends Random, only it always returns the highest possible values for each method.

Method Detail

instance

public static final CMath instance()

abbreviateLong

public static java.lang.String abbreviateLong(long l)
Returns an abbreviation of the given long, giving 2 significant digits after the decimal, and returning k, M, G, T, P, or E for the power base 1000.

Parameters:
l - the long to abbreviate
Returns:
the abbreviated long

convertToRoman

public static final java.lang.String convertToRoman(int i)
Convert an integer to its Roman Numeral equivalent Usage: Return=convertToRoman(Number)+".";

Parameters:
i - Integer to convert
Returns:
String Converted integer

convertFromRoman

public static final int convertFromRoman(java.lang.String s)
Convert a number from roman numeral to integer.

Parameters:
s - the roman numeral string
Returns:
the int

numAppendage

public static final java.lang.String numAppendage(int num)
Return st,nd,rd for a number

Parameters:
num - the number
Returns:
the st,nd,rd appendage only

appendNumAppendage

public static final java.lang.String appendNumAppendage(int num)
Append st,nd,rd for a number

Parameters:
num - the number
Returns:
the number with st,nd,rd appendage only

isRomanDigit

public static final boolean isRomanDigit(char c)
Return true if the char is a roman numeral digit

Parameters:
c - the char
Returns:
true if is roman

isRomanNumeral

public static final boolean isRomanNumeral(java.lang.String s)
Returns true if the string is a roman numeral

Parameters:
s - the string to test
Returns:
true if a roman numeral, false otherwise

absDiff

public static final long absDiff(long x,
                                 long y)
Returns the absolute difference between two numbers

Parameters:
x - the first number
y - the second number
Returns:
the absolute difference (x-y)*(-1 if less than 0)

s_valueOf

public static final java.lang.Object s_valueOf(java.lang.Object[] o,
                                               java.lang.String s)
Returns which object in the object array is same as the string, when cast to a string.

Parameters:
o - array of objects
s - the string to look
Returns:
the object or null

numberOfSetBits

public static int numberOfSetBits(long i)
Returns how many bits are set in the given 64 bit long

Parameters:
i - the long to count bits in
Returns:
the number of bits set

numberOfSetBits

public static int numberOfSetBits(int i)
Returns how many bits are set in the given 32 bit int

Parameters:
i - the int to count bits in
Returns:
the number of bits set

s_valueOf

public static final java.lang.Enum<? extends java.lang.Enum> s_valueOf(java.lang.Class<? extends java.lang.Enum> c,
                                                                       java.lang.String s)
Returns the matching enum. Case Sensitive!

Parameters:
c - the enum class to look in
s - the string to look
Returns:
the enum or null

s_valueOf

public static final java.lang.Enum<? extends java.lang.Enum> s_valueOf(java.lang.Class<? extends java.lang.Enum> c,
                                                                       java.lang.String s,
                                                                       java.lang.Enum<? extends java.lang.Enum> def)
Returns the matching enum. Case Sensitive!

Parameters:
c - the enum class to look in
s - the string to look
def - the value to use when null
Returns:
the enum

isNumber

public static final boolean isNumber(java.lang.String s)
Returns true if the string is a number (float or int)

Parameters:
s - the string to test
Returns:
true if a number, false otherwise

div

public static final double div(double a,
                               double b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the dividend
b - the divisor
Returns:
the quotient

div

public static final double div(double a,
                               int b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the dividend
b - the divisor
Returns:
the quotient

div

public static final double div(int a,
                               double b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the dividend
b - the divisor
Returns:
the quotient

div

public static final double div(double a,
                               long b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the dividend
b - the divisor
Returns:
the quotient

div

public static final double div(long a,
                               double b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the dividend
b - the divisor
Returns:
the quotient

mul

public static final double mul(double a,
                               double b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the first number
b - the second number
Returns:
the retult of multiplying a and b

mul

public static final double mul(double a,
                               int b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the first number
b - the second number
Returns:
the retult of multiplying a and b

mul

public static final double mul(int a,
                               double b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the first number
b - the second number
Returns:
the retult of multiplying a and b

mul

public static final double mul(double a,
                               long b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the first number
b - the second number
Returns:
the retult of multiplying a and b

mul

public static final double mul(long a,
                               double b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the first number
b - the second number
Returns:
the retult of multiplying a and b

mul

public static final long mul(long a,
                             long b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the first number
b - the second number
Returns:
the retult of multiplying a and b

mul

public static final int mul(int a,
                            int b)
Multiply a and b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the first number
b - the second number
Returns:
the retult of multiplying a and b

div

public static final double div(long a,
                               long b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the dividend
b - the divisor
Returns:
the quotient

div

public static final double div(int a,
                               int b)
Divide a by b, making sure both are cast to doubles and that the return is precisely double.

Parameters:
a - the dividend
b - the divisor
Returns:
the quotient

pow

public static final long pow(long x,
                             long y)
Raises x to the y power, making sure both are cast to doubles and that the return is rounded off.

Parameters:
x - the base number
y - the power
Returns:
x to the y power, rounded off

squared

public static final int squared(int x)
Returns x, squared, after being case to a double

Parameters:
x - the number to square
Returns:
x, squared, and rounded off.

bset

public static final boolean bset(short num,
                                 short bitmask)
Returns true if the given number has the bits represented by the given bitmask set.

Parameters:
num - the number
bitmask - the bit mask
Returns:
true if the bits are set, false otherwise

bset

public static final boolean bset(int num,
                                 int bitmask)
Returns true if the given number has the bits represented by the given bitmask set.

Parameters:
num - the number
bitmask - the bit mask
Returns:
true if the bits are set, false otherwise

bset

public static final boolean bset(long num,
                                 long bitmask)
Returns true if the given number has the bits represented by the given bitmask set.

Parameters:
num - the number
bitmask - the bit mask
Returns:
true if the bits are set, false otherwise

bset

public static final boolean bset(long num,
                                 int bitmask)
Returns true if the given number has the bits represented by the given bitmask set.

Parameters:
num - the number
bitmask - the bit mask
Returns:
true if the bits are set, false otherwise

setb

public static final int setb(int num,
                             int bitmask)
Returns the given number, after having set the bits represented by the given bit mask.

Parameters:
num - the number
bitmask - the bitmask
Returns:
the number | the bitmask

banyset

public static final boolean banyset(int num,
                                    int bitmask)
Returns true if any of the bits represented by the given bitmask are set in the given number.

Parameters:
num - the given number
bitmask - the bitmask of bits to check
Returns:
true if any bits from the mask are set

banyset

public static final boolean banyset(long num,
                                    long bitmask)
Returns true if any of the bits represented by the given bitmask are set in the given number.

Parameters:
num - the given number
bitmask - the bitmask of bits to check
Returns:
true if any bits from the mask are set

banyset

public static final boolean banyset(long num,
                                    int bitmask)
Returns true if any of the bits represented by the given bitmask are set in the given number.

Parameters:
num - the given number
bitmask - the bitmask of bits to check
Returns:
true if any bits from the mask are set

setb

public static final long setb(long num,
                              int bitmask)
Returns the given number, after having set the bits represented by the given bit mask.

Parameters:
num - the number
bitmask - the bitmask
Returns:
the number | the bitmask

setb

public static final long setb(long num,
                              long bitmask)
Returns the given number, after having set the bits represented by the given bit mask.

Parameters:
num - the number
bitmask - the bitmask
Returns:
the number | the bitmask

unsetb

public static final int unsetb(int num,
                               int bitmask)
Unsets those bits in the given number which are turned ON in the given bitmask.

Parameters:
num - the given number
bitmask - the given bitmask
Returns:
the number without the bitmasks bits turned on.

dobit

public static final int dobit(int num,
                              int bitmask,
                              boolean setOrUnSet)
Sets or Unsets those bits in the given number which are turned ON or OFF in the given bitmask.

Parameters:
num - the given number
bitmask - the given bitmask
setOrUnSet - true to set the bit, false otherwise
Returns:
the number with or without the bitmasks bits turned on.

unsetb

public static final long unsetb(long num,
                                long bitmask)
Unsets those bits in the given number which are turned ON in the given bitmask.

Parameters:
num - the given number
bitmask - the given bitmask
Returns:
the number without the bitmasks bits turned on.

unsetb

public static final long unsetb(long num,
                                int bitmask)
Unsets those bits in the given number which are turned ON in the given bitmask.

Parameters:
num - the given number
bitmask - the given bitmask
Returns:
the number without the bitmasks bits turned on.

firstBitSetIndex

public static final int firstBitSetIndex(int bits)
Returns the bit index (0 based) of the first bit set in the given mask.

Parameters:
bits - the bits to check
Returns:
the first bit set, as an index (1=0, 2=1, 4=2, 8=3, etc..)

getAllBitsSet

public static final int[] getAllBitsSet(int bits)
Returns the bit index (0 based) of the first bit set in the given mask.

Parameters:
bits - the bits to check
Returns:
the first bit set, as an index (1=0, 2=1, 4=2, 8=3, etc..)

getSeperateBitMasks

public static final int[] getSeperateBitMasks(int mask)
Given a bitmask, seperates the mask according to which bits are set and returns those original values in an array where each entry is the value of each bit

Parameters:
mask - the mask to seperate
Returns:
an entry for every set bit

getSeperateBitMasks

public static final long[] getSeperateBitMasks(long mask)
Given a bitmask, seperates the mask according to which bits are set and returns those original values in an array where each entry is the value of each bit

Parameters:
mask - the mask to seperate
Returns:
an entry for every set bit

isSet

public static final boolean isSet(int number,
                                  int bitnumber)
Returns true if the bitnumberth bit (0...) is set in the given number

Parameters:
number - the given number
bitnumber - the bit to check (0,1,2...)
Returns:
true if the given bitnumberth bit is set

isPct

public static final boolean isPct(java.lang.String s)
Returns true if the given string represents a percentage in the form X% where X is any real number.

Parameters:
s - the string to check
Returns:
true if it is a percentage, false otherwise

replaceVariables

public static final void replaceVariables(java.lang.StringBuffer str,
                                          double[] values)
Replaces @x1 type variables inside a stringbuffer with an actual value Not used in the main expression system, this is a stand alone function Also uniquely, supports @x numbers above 10. Values are *1* indexed!!

Parameters:
str - the stringbuffer to assess
values - values to replace each variable with

replaceVariables

public static final java.lang.String replaceVariables(java.lang.String str,
                                                      double[] values)
Replaces @x1 type variables inside a stringbuffer with an actual value Not used in the main expression system, this is a stand alone function Also uniquely, supports @x numbers above 10. Values are *1* indexed!!

Parameters:
str - the stringbuffer to assess
values - values to replace each variable with
Returns:
the string with values replaced.

hexDigit

public static final int hexDigit(char c)
Converts a single hex digit to an int

Parameters:
c - the hex digit, maybe
Returns:
the int representation

s_pct

public static final double s_pct(java.lang.String s)
Converts the given string to a floating point number, 1>=N>=0, representing the whole percentage of the string. The string format is either X or X%, where 100>=X>=0 If the format is bad, 0.0 is returned.

Parameters:
s - the string to convert
Returns:
the string converted to a real number

toPct

public static final java.lang.String toPct(double d)
Converts a percentage 1>d>0 to a string.

Parameters:
d - the number to convert
Returns:
the percentage string.

toPct

public static final java.lang.String toPct(java.lang.String s)
Converts the string to a double percentage and then converts that back to a percentage.

Parameters:
s - the string number
Returns:
the percentage %

isSet

public static final boolean isSet(long number,
                                  int bitnumber)
Returns true if the bitnumberth bit (0...) is set in the given number

Parameters:
number - the given number
bitnumber - the bit to check (0,1,2...)
Returns:
true if the given bitnumberth bit is set

isMathExpression

public static final boolean isMathExpression(java.lang.String st)
Returns whether the given string is a valid math expression (5 + 7)/2, etc. Does this by evaluating the expression and returning false if an error is found. No variables are allowed.

Parameters:
st - the possible math expression
Returns:
true if it is a math expression

isMathExpression

public static final boolean isMathExpression(java.lang.String st,
                                             double[] vars)
Returns whether the given string is a valid math expression (@x1 + 7)/2, etc. Does this by evaluating the expression and returning false if an error is found. All necessary variables MUST be included (@x1=vars[0])

Parameters:
st - the possible math expression
vars - the 0 based variables
Returns:
true if it is a math expression

s_parseMathExpression

public static final double s_parseMathExpression(java.lang.String st)
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variable @xx will refer to current computed value. Returns 0.0 on any parsing error

Parameters:
st - a full math expression string
Returns:
the result of the expression

s_parseMathExpression

public static final double s_parseMathExpression(java.lang.String st,
                                                 double[] vars)
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variables are included as @x1, etc.. The given variable values list is 0 based, so @x1 = vars[0]. Variable @xx will refer to current computed value. Returns 0.0 on any parsing error

Parameters:
st - a full math expression string
vars - the 0 based variables
Returns:
the result of the expression

s_parseLongExpression

public static final long s_parseLongExpression(java.lang.String st)
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variable @xx will refer to current computed value. Rounds the result to a long. Returns 0 on any parsing error

Parameters:
st - a full math expression string
Returns:
the result of the expression

s_parseLongExpression

public static final long s_parseLongExpression(java.lang.String st,
                                               double[] vars)
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variables are included as @x1, etc.. The given variable values list is 0 based, so @x1 = vars[0]. Variable @xx will refer to current computed value. Rounds the result to a long. Returns 0 on any parsing error

Parameters:
st - a full math expression string
vars - the 0 based variables
Returns:
the result of the expression

s_parseIntExpression

public static final int s_parseIntExpression(java.lang.String st)
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variable @xx will refer to current computed value. Round the result to an integer. Returns 0 on any parsing error

Parameters:
st - a full math expression string
Returns:
the result of the expression

s_parseIntExpression

public static final int s_parseIntExpression(java.lang.String st,
                                             double[] vars)
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variables are included as @x1, etc.. The given variable values list is 0 based, so @x1 = vars[0]. Variable @xx will refer to current computed value. Rounds the result to an integer. Returns 0 on any parsing error

Parameters:
st - a full math expression string
vars - the 0 based variables
Returns:
the result of the expression

compileMathExpression

public static final CMath.CompiledFormula compileMathExpression(java.lang.String formula)
Pre-compiles an expression for faster evaluation later on.

Parameters:
formula - the math expression as a string
Returns:
the pre-compiled expression
Throws:
java.lang.ArithmeticException - a parse error, typically arithmetic
See Also:
parseMathExpression(CompiledFormula, double[], double)

parseMathExpression

public static final double parseMathExpression(CMath.CompiledFormula list,
                                               double[] vars,
                                               double previous)
Parse a pre-compiled expression. Requires a vars variable of at least 10 entries to ensure NO exceptions (other than /0).

Parameters:
list - the pre-compiled expression
vars - the variable values
previous - the previous value, for operators that require it
Returns:
the final value
See Also:
compileMathExpression(StreamTokenizer, boolean)

parseMathExpression

public static final double parseMathExpression(CMath.CompiledFormula list,
                                               java.util.Random rand,
                                               double[] vars,
                                               double previous)
Parse a pre-compiled expression. Requires a vars variable of at least 10 entries to ensure NO exceptions (other than /0).

Parameters:
list - the pre-compiled expression
rand - the random number generator to use
vars - the variable values
previous - the previous value, for operators that require it
Returns:
the final value
See Also:
compileMathExpression(StreamTokenizer, boolean)

doOperation

protected double doOperation(char operation,
                             double finalValue,
                             double curValue)
Performs the operation between the finalValue and the curValue.

Parameters:
operation - +, -, etc..
finalValue - the left hand number
curValue - the right hand number
Returns:
the result of the operation

parseLongExpression

public static final long parseLongExpression(java.lang.String formula)
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variable @xx will refer to current computed value. Rounds the result to a long Throws an exception on any parsing error

Parameters:
formula - a full math expression string
Returns:
the result of the expression

parseLongExpression

public static final long parseLongExpression(java.lang.String formula,
                                             double[] vars)
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variables are included as @x1, etc.. The given variable values list is 0 based, so @x1 = vars[0]. Variable @xx will refer to current computed value. Rounds the result to a long Throws an exception on any parsing error

Parameters:
formula - a full math expression string
vars - the 0 based variables
Returns:
the result of the expression

parseIntExpression

public static final int parseIntExpression(java.lang.String formula)
                                    throws java.lang.ArithmeticException
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variable @xx will refer to current computed value. Rounds the result to an integer. Throws an exception on any parsing error

Parameters:
formula - a full math expression string
Returns:
the result of the expression
Throws:
java.lang.ArithmeticException - a parse error, typically arithmetic

parseIntExpression

public static final int parseIntExpression(java.lang.String formula,
                                           double[] vars)
                                    throws java.lang.ArithmeticException
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variables are included as @x1, etc.. The given variable values list is 0 based, so @x1 = vars[0]. Variable @xx will refer to current computed value. Rounds the result to an integer. Throws an exception on any parsing error

Parameters:
formula - a full math expression string
vars - the 0 based variables
Returns:
the result of the expression
Throws:
java.lang.ArithmeticException - a parse error, typically arithmetic

parseMathExpression

public static final double parseMathExpression(java.lang.String formula)
                                        throws java.lang.ArithmeticException
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variable @xx will refer to current computed value. Throws an exception on any parsing error

Parameters:
formula - a full math expression string
Returns:
the result of the expression
Throws:
java.lang.ArithmeticException - a parsing error

parseMathExpression

public static final double parseMathExpression(java.lang.String formula,
                                               double[] vars)
                                        throws java.lang.ArithmeticException
Returns the result of evaluating the given math expression. An expression can be a double or int number, or a full expression using ()+-/*?<>. Variables are included as @x1, etc.. The given variable values list is 0 based, so @x1 = vars[0]. Variable @xx will refer to current computed value. Throws an exception on any parsing error

Parameters:
formula - a full math expression string
vars - the 0 based variables
Returns:
the result of the expression
Throws:
java.lang.ArithmeticException - a parsing error

s_long

public static final long s_long(java.lang.String LONG)
Returns the long value of a string without crashing Usage: lSize = WebIQBase.s_long(WebIQBase.getRes(AttStatsRes,"BlobSize"));

Parameters:
LONG - String to convert
Returns:
long Long value of the string

s_float

public static final float s_float(java.lang.String FLOAT)
Returns the floating point value of a string without crashing Usage: lSize = WebIQBase.s_float(WebIQBase.getRes(AttStatsRes,"BlobSize"));

Parameters:
FLOAT - String to convert
Returns:
Float value of the string

s_double

public static final double s_double(java.lang.String DOUBLE)
Returns the double value of a string without crashing Usage: dSize = WebIQBase.s_double(WebIQBase.getRes(AttStatsRes,"BlobSize"));

Parameters:
DOUBLE - String to convert
Returns:
double Double value of the string

abs

public static final int abs(int val)
Returns the absolute value (X>=0) of the given number

Parameters:
val - the number
Returns:
the absolute value of the number

bitNumber

public static final int bitNumber(long mask)
Returns the first set bit number of the bitmask given

Parameters:
mask - the bit mask given.
Returns:
the first set bit number of the bitmask given

abs

public static final long abs(long val)
Returns the absolute value (X>=0) of the given number

Parameters:
val - the number
Returns:
the absolute value of the number

s_bool

public static final boolean s_bool(java.lang.String BOOL)
Returns the boolean value of a string without crashing Usage: int num=s_bool(CMD.substring(14));

Parameters:
BOOL - Boolean value of string
Returns:
int Boolean value of the string

isBool

public static final boolean isBool(java.lang.String BOOL)
Returns whether the given string is a boolean value Usage: if(isBool(CMD.substring(14)));

Parameters:
BOOL - Boolean value of string
Returns:
whether it is a boolean

s_int

public static final int s_int(java.lang.String INT)
Returns the integer value of a string without crashing Usage: int num=s_int(CMD.substring(14));

Parameters:
INT - Integer value of string
Returns:
int Integer value of the string

s_intOf

public static final int s_intOf(java.lang.Object O)
Converts the given object into an iteger, if it can

Parameters:
O - the object to try and convert
Returns:
the int, if possible

s_int

public static final int s_int(java.lang.String INT,
                              int def)
Returns the integer value of a string without crashing Usage: int num=s_int(CMD.substring(14));

Parameters:
INT - Integer value of string
def - default value if the given string is not an int
Returns:
int Integer value of the string

s_short

public static final short s_short(java.lang.String SHORT)
Returns the short value of a string without crashing Usage: int num=s_short(CMD.substring(14));

Parameters:
SHORT - Short value of string
Returns:
short Short value of the string

isLong

public static final boolean isLong(java.lang.String LONG)
Returns whether the given string is a long value Usage: if(isLong(CMD.substring(14)));

Parameters:
LONG - Long value of string
Returns:
whether it is a long

isInteger

public static final boolean isInteger(java.lang.String INT)
Returns whether the given string is a int value Usage: if(isInteger(CMD.substring(14)));

Parameters:
INT - Integer value of string
Returns:
whether it is a int

isFloat

public static final boolean isFloat(java.lang.String DBL)
Returns whether the given string is a float value Usage: if(isFloat(CMD.substring(14)));

Parameters:
DBL - float value of string
Returns:
whether it is a float

s_parseBitIntExpression

public static final int s_parseBitIntExpression(java.lang.String[] bits,
                                                java.lang.String val)
Returns a int representing either the given value, or the 2^ power of the comma separated values in the order they appear in the given string list. Usage: if(s_parseBitIntExpression(CMDS,CMD.substring(14)));

Parameters:
bits - the ordered string values from 0-whatever.
val - the expression, or list of string values
Returns:
the int value, or 0

s_parseBitLongExpression

public static final long s_parseBitLongExpression(java.lang.String[] bits,
                                                  java.lang.String val)
Returns a long representing either the given value, or the 2^ power of the comma separated values in the order they appear in the given string list. Usage: if(s_parseBitLongExpression(CMDS,CMD.substring(14)));

Parameters:
bits - the ordered string values from 0-whatever.
val - the expression, or list of string values
Returns:
the long value, or 0

setRand

public static final void setRand(java.util.Random rand)
Replaces the internal Random object with the one passed in. Intended to be used for debugging purposes only.

Parameters:
rand - the random object to use

s_parseListLongExpression

public static final long s_parseListLongExpression(java.lang.String[] descs,
                                                   java.lang.String val)
Returns a long representing either the given value, or the index of the value in the order they appear in the given string list. Usage: if(s_parseListLongExpression(CMDS,CMD.substring(14)));

Parameters:
descs - the ordered string values from 0-whatever.
val - the expression, or list of string values
Returns:
the long value, or 0

s_parseListIntExpression

public static final int s_parseListIntExpression(java.lang.String[] descs,
                                                 java.lang.String val)
Returns a int representing either the given value, or the index of the value in the order they appear in the given string list. Usage: if(s_parseListIntExpression(CMDS,CMD.substring(14)));

Parameters:
descs - the ordered string values from 0-whatever.
val - the expression, or list of string values
Returns:
the int value, or 0

isDouble

public static final boolean isDouble(java.lang.String DBL)
Returns whether the given string is a double value Usage: if(isDouble(CMD.substring(14)));

Parameters:
DBL - double value of string
Returns:
whether it is a double

isNumberFollowedByString

public static final boolean isNumberFollowedByString(java.lang.String str)
Returns whether the given string is a number followed by 1 or more characters.

Parameters:
str - the string to check
Returns:
true if its a numstring.

getNumberFollowedByString

public static final java.util.Map.Entry<java.lang.Integer,java.lang.String> getNumberFollowedByString(java.lang.String str)
Returns a number/string pair built from a given string, if it is a string with a number followed by one or more characters. Returns null if the given string does not match that criteria

Parameters:
str - the string to check
Returns:
a Math.Entry pair of the separated number/string.

getStringFollowedByNumber

public static final java.util.Map.Entry<java.lang.String,java.lang.Integer> getStringFollowedByNumber(java.lang.String str,
                                                                                                      boolean romanOK)
If the given string is 1 or more characters followed by decimal digits, this will return a Map.Entry with those parts separated. If the string is characters followed by a roman numeral digits, it will return a Map.Entry with those parts separated. Otherwise, it will return a Map.Entry with the string and a null integer.

Parameters:
str - the string to check
romanOK - true to check for roman numerals, false to just check for decimal
Returns:
the Map.Entry

round

public static final long round(double d)
Parameters:
d - the real number
Returns:
the rounded number as a long
See Also:
Math.round(double)

round

public static final long round(float d)
Parameters:
d - the real number
Returns:
the rounded number as a long
See Also:
Math.round(float)

abs

public static final double abs(double d)
Parameters:
d - the real number
Returns:
the absolute value of the number
See Also:
Math.abs(double)

abs

public static final float abs(float d)
Parameters:
d - the real number
Returns:
the absolute value of the number
See Also:
Math.abs(float)

random

public static final double random()
Returns:
a random number
See Also:
Math.random()

floor

public static final double floor(double d)
Parameters:
d - the number to get the floor of
Returns:
the floor of the given number
See Also:
Math.floor(double), ceiling(double)

floor

public static final float floor(float d)
Parameters:
d - the number to get the floor of
Returns:
the floor of the given number
See Also:
Math.floor(double), ceiling(double)

ceiling

public static final double ceiling(double d)
Parameters:
d - the number to get the ceiling of
Returns:
the ceiling of the given number
See Also:
Math.ceil(double), floor(double)

ceiling

public static final float ceiling(float d)
Parameters:
d - the number to get the ceiling of
Returns:
the ceiling of the given number
See Also:
Math.ceil(double), floor(float)

sqrt

public static final double sqrt(double d)
Parameters:
d - the number to get the square root of
Returns:
the square root of the given number
See Also:
Math.sqrt(double)

sqrt

public static final float sqrt(float d)
Parameters:
d - the number to get the square root of
Returns:
the square root of the given number
See Also:
Math.sqrt(double)

greater

public static final double greater(double a,
                                   double b)
Returns greater of two numbers

Parameters:
a - first number
b - second number
Returns:
greater of the two

bigMultiply

public static final java.math.BigInteger bigMultiply(long l1,
                                                     long l2)
Generates a big integer from multiply two longs

Parameters:
l1 - the first long
l2 - the second long
Returns:
the big big integer

bigMultiply

public static final java.math.BigInteger bigMultiply(double l1,
                                                     long l2)
Generates a big integer from multiply two numbers, rounding when necessary

Parameters:
l1 - the first number
l2 - the second number
Returns:
the big big integer