public class Common
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.text.DecimalFormat |
fixedPoint
For numbers with four fraction digits.
|
static java.util.Random |
random
The common RNG.
|
static java.text.DecimalFormat |
scientific
For numbers in a power format.
|
| Constructor and Description |
|---|
Common() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
appendExtension(java.lang.String fileName,
java.lang.String defaultExtension)
Add a file extension, if the file name doesn't yet have one.
|
static <E> java.util.List<E> |
asList(E[] a)
Returns the array elements in list form.
|
static java.lang.String |
cutHeadAtLast(java.lang.String terms,
char c)
Eliminates the substring before the last occurrence of 'c'
including 'c'.
|
static java.lang.String |
cutLeadChar(java.lang.String s,
char c)
Eliminates the potential leading char 'c' in string 's'.
|
static java.lang.String |
cutTailAtLast(java.lang.String terms,
char c)
Eliminates the substring after the last occurrence of 'c'
including 'c'.
|
static double |
getDuration(double timeStamp)
Returns the time passed since the given time stamp.
|
static int |
getMaxIndex(double[] values)
Returns the index of the max value of an array.
|
static int |
getMaxIndex(java.util.List<java.lang.Double> values)
Returns the index of the max value of a Double list.
|
static java.util.Random |
getRandom()
Returns the common random number generator.
|
static double |
getRandom(double low,
double high)
Returns a random value from the interval [low, high).
|
static char |
getSeparatorChar(java.lang.String s)
Determines the separator character in a given string.
|
static double |
getTimeStamp()
Returns the current time stamp in milli-seconds.
|
static boolean |
inRange(int val,
int low,
int high)
Checks if the given value is in the given range.
|
static double |
limitToRange(double val,
double low,
double high)
Limits a value to the given boundaries.
|
static <E> void |
replace(java.util.List<E> list,
E a,
E b)
Replaces element a with element b in the list.
|
static java.lang.String |
stripOff(java.lang.String s,
char c)
Strips off all characters 'c' in string 's'.
|
static <E> void |
swap(java.util.List<E> l,
int a,
int b)
Swaps the objects at the given positions in the list.
|
public static java.util.Random random
public static java.text.DecimalFormat fixedPoint
public static java.text.DecimalFormat scientific
public static int getMaxIndex(double[] values)
values - the arraypublic static int getMaxIndex(java.util.List<java.lang.Double> values)
values - the arraypublic static double getTimeStamp()
public static double getDuration(double timeStamp)
timeStamp - a time stamp in millisecondspublic static double limitToRange(double val,
double low,
double high)
val - a valuelow - lower boundaryhigh - upper boundarypublic static boolean inRange(int val,
int low,
int high)
val - a valuelow - lower boundary (included)high - upper boundary (excluded)public static java.util.Random getRandom()
public static double getRandom(double low,
double high)
low - the lower bound (included)high - the upper bound (excluded)public static java.lang.String cutHeadAtLast(java.lang.String terms,
char c)
terms - a stringc - the delimiting characterpublic static java.lang.String cutTailAtLast(java.lang.String terms,
char c)
c - the delimiting characterterms - a Stringpublic static java.lang.String cutLeadChar(java.lang.String s,
char c)
c - the possibly leading characters - a stringpublic static java.lang.String stripOff(java.lang.String s,
char c)
c - the character to be eraseds - a stringpublic static char getSeparatorChar(java.lang.String s)
s - a string containing separatorspublic static <E> java.util.List<E> asList(E[] a)
a - an arraypublic static <E> void replace(java.util.List<E> list,
E a,
E b)
list - a lista - element to be replacedb - element to be insertedpublic static <E> void swap(java.util.List<E> l,
int a,
int b)
l - a lista - index of object Ab - index of object Bpublic static java.lang.String appendExtension(java.lang.String fileName,
java.lang.String defaultExtension)
If the file name is fully enclosed in double quotes ("), remove them, but
don't append an extension.
If the file name already has another extension, don't change it.
If the filename only consists of a path, too bad; ext is appended anyway.
Also, ignore path elements that precede the file name.
fileName - The file name to append the extension to.defaultExtension - The extension to add, if necessary.