|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsbrt.kernel.util.Util
public final class Util
This class contains static methods that perform utility functions.
Method Summary | ||
---|---|---|
static void |
debugPrintln(java.lang.Object o)
Prints the provided object to System.err , preceded by a carriage
return character. |
|
static boolean |
equal(double value1,
double value2,
double tolerance)
Indicates if the provided values are equal to each other, given the provided tolerance. |
|
static double[] |
getArray(java.util.Collection<? extends java.lang.Number> values)
Returns an array containing the values in the provided collection as doubles. |
|
static int[] |
getArray(java.util.Collection<java.lang.Integer> values)
Returns an array containing the values in the provided collection. |
|
static double[][] |
getArrays(java.util.Map<?,java.lang.Double> xValues,
java.util.Map<?,java.lang.Double> yValues)
Returns a 2 x n array containing the values from the provided
maps. |
|
static
|
getCommonElements(java.util.Collection<? extends E> c1,
java.util.Collection<? extends E> c2)
Returns a list of elements common to both provided collections. |
|
static
|
getDuplicates(java.util.Collection<E> c)
Returns a list of duplicate elements contained in the provided collection. |
|
static double |
getLargest(double v1,
double v2)
Returns the largest of the provided numbers. |
|
static int |
getLargest(int v1,
int v2)
Returns the largest of the provided numbers. |
|
static double |
getSmallest(double v1,
double v2)
Returns the smallest of the provided numbers. |
|
static int |
getSmallest(int v1,
int v2)
Returns the smallest of the provided numbers. |
|
static double[] |
getSorted(double[] values)
Returns a new array containing the values from the provided array in ascending numerical order. |
|
static int[] |
getSorted(int[] values)
Returns a new array containing the values from the provided array in ascending numerical order. |
|
static double[] |
getSortedArray(java.util.Collection<? extends java.lang.Number> values)
Returns a sorted array containing the values in the provided collection. |
|
static int[] |
getSortedArray(java.util.Collection<java.lang.Integer> values)
Returns a sorted array containing the values in the provided collection. |
|
static boolean |
isZero(double d)
Indicates if the provided value equals 0. |
|
static void |
main(java.lang.String[] args)
Used for testing purposes. |
|
static void |
nullCheck(java.lang.Object obj)
Ensures the provided object is not null. |
|
static boolean |
oppositeSign(double x1,
double x2)
Indicates if the provided numbers are of opposite sign. |
|
static boolean |
oppositeSign(int x1,
int x2)
Indicates if the provided numbers are of opposite sign. |
|
static void |
print(java.util.Collection<?> c)
Prints the elements of the provided collection to System.out ,
one per line. |
|
static java.lang.String |
widthFormat(java.lang.String string,
int maxWidth)
Attemps to format the provided string such that system-dependent newline characters appear no more than maxWidth characters
apart. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void nullCheck(java.lang.Object obj)
obj
- the object to check.
java.lang.NullPointerException
- if the provided argument is null
.public static int[] getSorted(int[] values)
values
- the array whose values are to be sorted.
public static double[] getSorted(double[] values)
values
- the array whose values are to be sorted.
public static double[] getArray(java.util.Collection<? extends java.lang.Number> values)
values
- a collection of double precision values.
Number.doubleValue()
public static int[] getArray(java.util.Collection<java.lang.Integer> values)
values
- a collection of double precision values.
public static double[] getSortedArray(java.util.Collection<? extends java.lang.Number> values)
values
- a collection of double precision values.
Arrays.sort(double[])
,
Number.doubleValue()
public static int[] getSortedArray(java.util.Collection<java.lang.Integer> values)
values
- a collection of double precision values.
Arrays.sort(int[])
public static double[][] getArrays(java.util.Map<?,java.lang.Double> xValues, java.util.Map<?,java.lang.Double> yValues)
2 x n
array containing the values from the provided
maps. The array at index 0
contains the x values, and the array
at index 1
contains the y values. The order of appearance of
values in these arrays is the same as that returned by an iterator over
xValues.entrySet()
. The key sets of the provided maps need not
be identical, but only the intersecting values will be considered when
filling the arrays. The lengths n
of these arrays equals the size
of the intersection of the key sets of the provided maps. Therefore, if
the provided maps contain identical keys, then n == xValues.size() &&
n == yValues.size()
evaluates to true
.
xValues
- keys mapped to values.yValues
- keys mapped to values.
2 x n
array containing the values from the provided
maps.public static boolean isZero(double d)
d
- the value to test.
Math.abs(d) < Double.MIN_VALUE;
.public static boolean equal(double value1, double value2, double tolerance)
value1
- a value.value2
- a value.tolerance
- the amount by which the provided values can differ
but still be considered equal.
Math.abs(value1 - value2) < tolerance;
public static java.lang.String widthFormat(java.lang.String string, int maxWidth)
maxWidth
characters
apart. This method is not robust.
string
- the string to format.maxWidth
- the ideal maximum distance between newline characters.
public static void debugPrintln(java.lang.Object o)
System.err
, preceded by a carriage
return character.
o
- the object to print.public static void print(java.util.Collection<?> c)
System.out
,
one per line.
c
- the collection to be printed.public static double getSmallest(double v1, double v2)
v1
- a numerical value.v2
- a numerical value.
public static double getLargest(double v1, double v2)
v1
- a numerical value.v2
- a numerical value.
public static int getSmallest(int v1, int v2)
v1
- an integer value.v2
- an integer value.
public static int getLargest(int v1, int v2)
v1
- an integer value.v2
- an integer value.
public static <E> java.util.List<E> getDuplicates(java.util.Collection<E> c)
E
- the element type.c
- a collection of elements.
public static <E> java.util.List<E> getCommonElements(java.util.Collection<? extends E> c1, java.util.Collection<? extends E> c2)
E
- the element type.c1
- a collection of elements.c2
- a collection of elements.
public static boolean oppositeSign(double x1, double x2)
x1
- a numerical value.x2
- a numerical value.
true
if one number is positive and the other negative;
false
otherwise.public static boolean oppositeSign(int x1, int x2)
x1
- an integer value.x2
- an integer value.
true
if one number is positive and the other negative;
false
otherwise.public static void main(java.lang.String[] args)
args
- ignored.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |