com.mizar.commons.math.util
Class MathUtils

java.lang.Object
  extended by com.mizar.commons.math.util.MathUtils

public class MathUtils
extends java.lang.Object


Field Summary
static double VERY_SMALL_NUMBER
           
 
Constructor Summary
protected MathUtils()
           
 
Method Summary
static double[] alterRange(double[] range, double percent)
          This method expands or shrinks a range specified as a double[4] array.
static java.lang.Number copy(java.lang.Number number)
           
static boolean existsIn(int[] tests, int[] numbers)
           
static boolean existsIn(int test, int[] numbers)
           
static boolean existsIn(long[] tests, long[] numbers)
           
static boolean existsIn(long test, long[] numbers)
           
static boolean existsIn(java.lang.Number[] tests, java.lang.Number[] numbers)
           
static boolean existsIn(java.lang.Number test, java.lang.Number[] numbers)
           
static boolean getBoolean(int num)
          Converts an int into a boolean
static boolean getBoolean(java.lang.Integer num)
          Converts an Integer into a boolean
static boolean getBoolean(long num)
          Converts a long into a boolean
static boolean getBoolean(java.lang.Long num)
           
static boolean getBoolean(java.lang.String logical)
          This function will attempt to parse a boolean value out of a string.
static int getDecimalPlaces(double dbVal)
          Taken, with modifications from http://www.codeproject.com/KB/cpp/Double.aspx
static java.lang.Double getDouble(java.lang.Number number)
           
static java.lang.Double getDoublePart(java.lang.String string)
           
static java.lang.Integer getIntegerPart(java.lang.String string)
           
static java.lang.Long getLong(java.lang.Number number)
           
static java.lang.Long getLongPart(java.lang.String string)
           
static java.lang.String getReadableByteSize(long bytes)
           
static boolean isBetween(double scalar_1, double scalar_2, double test)
           
static boolean isBetween(float scalar_1, float scalar_2, float test)
           
static boolean isBetween(int scalar_1, int scalar_2, int test)
           
static boolean isBetween(long scalar_1, long scalar_2, long test)
           
static boolean isEqualOrBetween(double scalar_1, double scalar_2, double test)
           
static boolean isEqualOrBetween(float scalar_1, float scalar_2, float test)
           
static boolean isEqualOrBetween(int scalar_1, int scalar_2, int test)
           
static boolean isEqualOrBetween(long scalar_1, long scalar_2, long test)
           
static void main(java.lang.String[] args)
           
static double max(double[] array)
          Searches an array of doubles and returns the largest element
static java.lang.Double max(java.lang.Double[] array)
          Searches an array of Double and returns the largest element
static float max(float[] array)
          Searches an array of floats and returns the largest element
static java.lang.Float max(java.lang.Float[] array)
          Searches an array of Float and returns the largest element
static int max(int[] array)
          Searches an array of ints and returns the largest element
static java.lang.Integer max(java.lang.Integer[] array)
          Searches an array of Integers and returns the largest element
static java.lang.Integer max(java.lang.Integer int1, java.lang.Integer int2)
          A null same max method for Integer.
static long max(long[] array)
          Searches an array of longs and returns the largest element
static java.lang.Long max(java.lang.Long[] array)
          Searches an array of Long and returns the largest element
static java.lang.Long max(java.lang.Long long1, java.lang.Long long2)
          A null same max method for Long.
static double min(double[] array)
          Searches an array of doubles and returns the smallest element
static java.lang.Double min(java.lang.Double[] array)
          Searches an array of Doubles and returns the smallest element
static float min(float[] array)
          Searches an array of floats and returns the smallest element
static java.lang.Float min(java.lang.Float[] array)
          Searches an array of Floats and returns the smallest element
static int min(int[] array)
          Searches an array of ints and returns the smallest element
static java.lang.Integer min(java.lang.Integer[] array)
          Searches an array of Integers and returns the smallest element
static java.lang.Integer min(java.lang.Integer int1, java.lang.Integer int2)
          A null same min method for Integer.
static long min(long[] array)
          Searches an array of longs and returns the smallest element
static java.lang.Long min(java.lang.Long[] array)
          Searches an array of Longs and returns the smallest element
static java.lang.Long min(java.lang.Long long1, java.lang.Long long2)
          A null same min method for Long.
static boolean nearlyOne(double value)
           
static boolean nearlyTheSame(double value1, double value2, double tolerance)
           
static boolean nearlyZero(double value)
           
static java.lang.Double[] objectify(double[] array)
           
static java.lang.Long[] objectify(long[] array)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERY_SMALL_NUMBER

public static double VERY_SMALL_NUMBER
Constructor Detail

MathUtils

protected MathUtils()
Method Detail

main

public static void main(java.lang.String[] args)

getBoolean

public static boolean getBoolean(java.lang.String logical)
This function will attempt to parse a boolean value out of a string. The string should be "true", "yes" or "y".

Parameters:
logical - possible boolean value
Returns:
true - if the logical represents boolean true

getBoolean

public static boolean getBoolean(long num)
Converts a long into a boolean

Parameters:
num - a long to check
Returns:
true - if num is not zero

getBoolean

public static boolean getBoolean(java.lang.Long num)
Parameters:
num - Long to check
Returns:
true - if num is not zero
See Also:
getBoolean(long num)

getBoolean

public static boolean getBoolean(int num)
Converts an int into a boolean

Parameters:
num - int to convert
Returns:
true - if num is not zero

getBoolean

public static boolean getBoolean(java.lang.Integer num)
Converts an Integer into a boolean

Parameters:
num -
Returns:
true if Integer is non-zero, false is zero

existsIn

public static boolean existsIn(java.lang.Number test,
                               java.lang.Number[] numbers)
Parameters:
test -
numbers -
Returns:

existsIn

public static boolean existsIn(java.lang.Number[] tests,
                               java.lang.Number[] numbers)
Parameters:
tests -
numbers -
Returns:

existsIn

public static boolean existsIn(long test,
                               long[] numbers)
Parameters:
test -
numbers -
Returns:

existsIn

public static boolean existsIn(long[] tests,
                               long[] numbers)
Parameters:
tests -
numbers -
Returns:

existsIn

public static boolean existsIn(int test,
                               int[] numbers)
Parameters:
test -
numbers -
Returns:

existsIn

public static boolean existsIn(int[] tests,
                               int[] numbers)
Parameters:
tests -
numbers -
Returns:

min

public static java.lang.Integer min(java.lang.Integer int1,
                                    java.lang.Integer int2)
A null same min method for Integer. If one or the other inputs are null then the non-null value is returned. If both values are null then zero is returned.

Parameters:
int1 -
int2 -
Returns:

max

public static java.lang.Integer max(java.lang.Integer int1,
                                    java.lang.Integer int2)
A null same max method for Integer. If one or the other inputs are null then the non-null value is returned. If both values are null then zero is returned.

Parameters:
int1 -
int2 -
Returns:

min

public static java.lang.Long min(java.lang.Long long1,
                                 java.lang.Long long2)
A null same min method for Long. If one or the other inputs are null then the non-null value is returned. If both values are null then zero is returned.

Parameters:
long1 -
long2 -
Returns:

max

public static java.lang.Long max(java.lang.Long long1,
                                 java.lang.Long long2)
A null same max method for Long. If one or the other inputs are null then the non-null value is returned. If both values are null then zero is returned.

Parameters:
long1 -
long2 -
Returns:

min

public static java.lang.Integer min(java.lang.Integer[] array)
Searches an array of Integers and returns the smallest element

Parameters:
array - Array to search
Returns:
minimum element in the array.

min

public static java.lang.Long min(java.lang.Long[] array)
Searches an array of Longs and returns the smallest element

Parameters:
array - Array to search
Returns:
minimum element in the array.

min

public static java.lang.Float min(java.lang.Float[] array)
Searches an array of Floats and returns the smallest element

Parameters:
array - Array to search
Returns:
minimum element in the array.

min

public static java.lang.Double min(java.lang.Double[] array)
Searches an array of Doubles and returns the smallest element

Parameters:
array - Array to search
Returns:
minimum element in the array.

min

public static int min(int[] array)
Searches an array of ints and returns the smallest element

Parameters:
array - Array to search
Returns:
minimum element in the array.

min

public static long min(long[] array)
Searches an array of longs and returns the smallest element

Parameters:
array - Array to search
Returns:
minimum element in the array.

min

public static float min(float[] array)
Searches an array of floats and returns the smallest element

Parameters:
array - Array to search
Returns:
minimum element in the array.

min

public static double min(double[] array)
Searches an array of doubles and returns the smallest element

Parameters:
array - Array to search
Returns:
minimum element in the array.

max

public static java.lang.Integer max(java.lang.Integer[] array)
Searches an array of Integers and returns the largest element

Parameters:
array - Array to search
Returns:
largest element in the array.

max

public static java.lang.Long max(java.lang.Long[] array)
Searches an array of Long and returns the largest element

Parameters:
array - Array to search
Returns:
largest element in the array.

max

public static java.lang.Float max(java.lang.Float[] array)
Searches an array of Float and returns the largest element

Parameters:
array - Array to search
Returns:
largest element in the array.

max

public static java.lang.Double max(java.lang.Double[] array)
Searches an array of Double and returns the largest element

Parameters:
array - Array to search
Returns:
largest element in the array.

max

public static int max(int[] array)
Searches an array of ints and returns the largest element

Parameters:
array - Array to search
Returns:
largest element in the array.

max

public static long max(long[] array)
Searches an array of longs and returns the largest element

Parameters:
array - Array to search
Returns:
largest element in the array.

max

public static float max(float[] array)
Searches an array of floats and returns the largest element

Parameters:
array - Array to search
Returns:
largest element in the array.

max

public static double max(double[] array)
Searches an array of doubles and returns the largest element

Parameters:
array - Array to search
Returns:
largest element in the array.

isEqualOrBetween

public static boolean isEqualOrBetween(double scalar_1,
                                       double scalar_2,
                                       double test)
Parameters:
scalar_1 -
scalar_2 -
test - a value to test if it is between scalar_1 and scalar_2
Returns:
true if test is equal to either, or between scalar_1 and scalar_2
See Also:
isBetween(double, double, double)

isBetween

public static boolean isBetween(double scalar_1,
                                double scalar_2,
                                double test)
Parameters:
scalar_1 -
scalar_2 -
test - a value to test if it is between scalar_1 and scalar_2
Returns:
true if test is between scalar_1 and scalar_2
See Also:
isEqualOrBetween(double, double, double)

isEqualOrBetween

public static boolean isEqualOrBetween(float scalar_1,
                                       float scalar_2,
                                       float test)
Parameters:
scalar_1 -
scalar_2 -
test - a value to test if it is between scalar_1 and scalar_2
Returns:
true if test is equal to either, or between scalar_1 and scalar_2
See Also:
isBetween(double, double, double)

isBetween

public static boolean isBetween(float scalar_1,
                                float scalar_2,
                                float test)
Parameters:
scalar_1 -
scalar_2 -
test - a value to test if it is between scalar_1 and scalar_2
Returns:
true if test is between scalar_1 and scalar_2
See Also:
isEqualOrBetween(double, double, double)

isEqualOrBetween

public static boolean isEqualOrBetween(long scalar_1,
                                       long scalar_2,
                                       long test)
Parameters:
scalar_1 -
scalar_2 -
test - a value to test if it is between scalar_1 and scalar_2
Returns:
true if test is equal to either, or between scalar_1 and scalar_2
See Also:
isBetween(double, double, double)

isBetween

public static boolean isBetween(long scalar_1,
                                long scalar_2,
                                long test)
Parameters:
scalar_1 -
scalar_2 -
test - a value to test if it is between scalar_1 and scalar_2
Returns:
true if test is between scalar_1 and scalar_2
See Also:
isEqualOrBetween(double, double, double)

isEqualOrBetween

public static boolean isEqualOrBetween(int scalar_1,
                                       int scalar_2,
                                       int test)
Parameters:
scalar_1 -
scalar_2 -
test - a value to test if it is between scalar_1 and scalar_2
Returns:
true if test is equal to either, or between scalar_1 and scalar_2
See Also:
isBetween(double, double, double)

isBetween

public static boolean isBetween(int scalar_1,
                                int scalar_2,
                                int test)
Parameters:
scalar_1 -
scalar_2 -
test - a value to test if it is between scalar_1 and scalar_2
Returns:
true if test is between scalar_1 and scalar_2
See Also:
isEqualOrBetween(double, double, double)

copy

public static java.lang.Number copy(java.lang.Number number)
Parameters:
number -
Returns:
a copy of the value of number

nearlyOne

public static boolean nearlyOne(double value)

nearlyZero

public static boolean nearlyZero(double value)

nearlyTheSame

public static boolean nearlyTheSame(double value1,
                                    double value2,
                                    double tolerance)

alterRange

public static double[] alterRange(double[] range,
                                  double percent)
This method expands or shrinks a range specified as a double[4] array. It does not modify the original array.

Parameters:
range - a double[4] array organized as minx, maxx, miny, maxy
percent - should be greater than 1.0 to expand the range and less than 1.0 to shrink the range
Returns:
an altered range

objectify

public static java.lang.Double[] objectify(double[] array)

objectify

public static java.lang.Long[] objectify(long[] array)

getLongPart

public static java.lang.Long getLongPart(java.lang.String string)

getIntegerPart

public static java.lang.Integer getIntegerPart(java.lang.String string)

getDouble

public static java.lang.Double getDouble(java.lang.Number number)
Parameters:
number -
Returns:
a Double from any Number

getLong

public static java.lang.Long getLong(java.lang.Number number)
Parameters:
number -
Returns:
a Long from any Number

getDoublePart

public static java.lang.Double getDoublePart(java.lang.String string)

getDecimalPlaces

public static int getDecimalPlaces(double dbVal)
Taken, with modifications from http://www.codeproject.com/KB/cpp/Double.aspx

Parameters:
dbVal -
Returns:

getReadableByteSize

public static java.lang.String getReadableByteSize(long bytes)
Parameters:
long - value of the number of bytes to be converted
Returns:
String with bytes formatted in readable notation; e.g. 2.1 Gb