public class ToolBox extends Object
| Constructor and Description |
|---|
ToolBox() |
| Modifier and Type | Method and Description |
|---|---|
static long |
binomial(int N,
int K)
Compute number of K-tuples of N elements
|
static String |
col2string(Collection<?> col,
int tab)
Multiline representation of a collection
|
static void |
configureLogging()
Configurates log4j loging
|
static String |
configureLogging(String logDir,
Properties properties)
Configure log4j logging
|
static String |
configureLogging(String logDir,
Properties properties,
boolean timeInFileName)
Configure log4j logging
|
static String |
configureLogging(String logDir,
Properties properties,
boolean timeInFileName,
boolean includeSystemOuts)
Configure log4j logging
|
static <K,V> String |
dict2string(Map<K,V> dict,
int tab)
Multiline representation of a dictionary
|
static boolean |
equals(Object o1,
Object o2) |
static Random |
getRandom()
Gets random number generator
|
static long |
getSeed()
Gets current seed
|
static <E> List<E> |
intersect(Collection<E> source1,
Collection<E> source2)
Returns intersection of two collections
|
static DataProperties |
loadProperties(File propertyFile)
Loads data properties.
|
static <E> void |
merge(List<E> target,
Collection<E> source)
Merge source with target
|
static <E> List<E> |
permutation(List<E> items,
int m,
long id)
Generate given permutation
|
static <E> Enumeration<Collection<E>> |
permutations(List<E> items,
int m)
Generate a list of all permutations of size m of the given list
|
static double |
random()
Generates random double number
|
static <E> E |
random(Collection<E> set)
Returns random element from the given set of elements
|
static int |
random(int limit)
Returns random number (int) from the set 0 .. limit - 1
|
static double |
rms(int n,
double x,
double x2)
Root mean square
|
static <E> Set<E> |
sample(List<E> items,
int m)
Create random sample (m-tuple) of given list of elements
|
static <E> Enumeration<Collection<E>> |
sample(List<E> items,
int m,
int count)
Generate a list of samples of the given list
|
static <E> Enumeration<Collection<E>> |
sample(List<E> preferred,
List<E> additional,
int m,
int count)
Generate a list of random samples combined of the given two lists
|
static void |
setSeed(long seed)
Sets seeds for
getRandom() and random()
methods. |
static void |
setupLogging(File logFile,
boolean debug)
Setup log4j logging
|
static <E> Collection<E> |
subSet(Collection<E> set,
double part)
Returns a randomly generated subset of the given set
|
static <E> Collection<E> |
subSet(Collection<E> set,
double part,
int minSize)
Returns a randomly generated subset of the given set
|
static <E> List<E> |
toList(E... obj)
Convert array of elements into a list
|
static String |
trim(String s,
int length)
Trim a string to have given length
|
public ToolBox()
public static int random(int limit)
limit - a limitpublic static <E> E random(Collection<E> set)
E - some typeset - collection of objectspublic static <E> Collection<E> subSet(Collection<E> set, double part)
E - some typeset - setpart - probability of selection of an element into the resultant
subsetpublic static <E> Collection<E> subSet(Collection<E> set, double part, int minSize)
E - some typeset - setpart - probability of selection of an element into the resultant
subsetminSize - minimal size of the returned subsetpublic static String trim(String s, int length)
s - a string to trimlength - a length to trim topublic static String col2string(Collection<?> col, int tab)
col - a collectiontab - tab sizepublic static <K,V> String dict2string(Map<K,V> dict, int tab)
K - a key classV - a value classdict - a maptab - tab sizepublic static double rms(int n, double x, double x2)
n - number of testsx - total value of all testsx2 - total value^2 of all testspublic static <E> void merge(List<E> target, Collection<E> source)
E - some objecttarget - target listsource - source listpublic static <E> List<E> intersect(Collection<E> source1, Collection<E> source2)
E - some objectsource1 - first collectionsource2 - second collectionpublic static void setSeed(long seed)
getRandom() and random()
methods.seed - random seedpublic static long getSeed()
public static Random getRandom()
public static double random()
public static void configureLogging()
public static void setupLogging(File logFile, boolean debug)
logFile - log filedebug - true if debug messages should be logged (use -Ddebug=true to enable debug message)public static String configureLogging(String logDir, Properties properties)
logDir - output folderproperties - some other log4j propertiespublic static String configureLogging(String logDir, Properties properties, boolean timeInFileName)
logDir - output folderproperties - some other log4j propertiestimeInFileName - if true log file is named debug_yyyy-MM-dd_(HH.mm.ss).log, it
is named debug.log otherwisepublic static String configureLogging(String logDir, Properties properties, boolean timeInFileName, boolean includeSystemOuts)
logDir - output folderproperties - some other log4j propertiestimeInFileName - if true log file is named debug_yyyy-MM-dd_(HH.mm.ss).log, it
is named debug.log otherwiseincludeSystemOuts - include system out and error in the logpublic static DataProperties loadProperties(File propertyFile)
propertyFile - a file to readpublic static <E> List<E> toList(E... obj)
obj - array of elementspublic static long binomial(int N, int K)
N - number of elements (e.g., number of room locations in a domain)K - size of a tuple (e.g., number of rooms a class needs)public static <E> Set<E> sample(List<E> items, int m)
items - list of elementsm - size of a tuplepublic static <E> List<E> permutation(List<E> items, int m, long id)
items - list of elementsm - size of a tuple (permutation)id - position of the permutation in the list of all permutations of m-tuples of the given list of elementspublic static <E> Enumeration<Collection<E>> sample(List<E> items, int m, int count)
items - list of elementsm - size of a samplecount - number of samplespublic static <E> Enumeration<Collection<E>> permutations(List<E> items, int m)
items - list of elementsm - size of a permutationpublic static <E> Enumeration<Collection<E>> sample(List<E> preferred, List<E> additional, int m, int count)
preferred - list of preferred elementsadditional - list of additional elementsm - size of a samplecount - number of samples