java.lang.Object
es.upm.fi.cig.multictbnc.util.Util
Utility class.
-
Method Summary
Modifier and TypeMethodDescriptionarrayToQueue(String[] args) Converts an array of strings into a queue of strings.cartesianProduct(List<List<State>> statesVariables) Given a list of lists with the possible states of some variables, this method returns the Cartesian product between each of the possible states of each variable.static double[][]clone2DArray(double[][] array) Creates a deep copy of a two-dimensional double array.static double[][][]clone3DArray(double[][][] array) Creates a deep copy of a three-dimensional double array.combination(List<type> elements, int k) Returns all possible combinations of size 'k' of a given list of elements.static longextractFirstLong(String string) Returns the firstlongin aString.static intextractInt(String string) Returns anintfrom aString.static longextractLong(String string) Returns alongfrom aString.static String[]extractPathExperimentDatasets(String pathExperiment) Returns the path to the datasets given the folder of a experiment.static voidfill2dArray(double[][] array, double value) Fills a two-dimensionaldoublearray with the provideddouble.static voidfill3dArray(double[][][] array, double value) Fills a three-dimensionaldoublearray with the provideddouble.static <T> List<T>Returns the elements of a list "a" except those in "b".static <T> List<T>Returns the elements of a list "a" except "b".static <k,v extends Comparable<v>>
Map.Entry<k,v> getEntryLargestValue(Map<k, v> map) Returns entry with the largest value of aMap.static intgetIndexLargestValue(double[] array) Returns the index of the largest value in an array.static doublegetMaxValue(double... values) Returns the maximum value between those passed as parametersgetRandomElements(List<Integer> list, int k) Getkrandom elements from an {\@code Integer} list.getSubsets(List<type> list, int size, type elementToIgnore) Retrieves the possible subsets of a certain size from a given set of elements without including a certain element.static <T> booleanisArrayEmpty(T[] array) Checks if an array is empty.static intkroneckerDelta(String[] a, String[] b) Kronecker delta function.static <typeNode extends Node>
booleanlistsOfNodeContainSameElements(List<typeNode> listA, List<typeNode> listB) Checks if two given lists ofNodecontain the same elements independently of their orders.static String[]listToArray(List<?> list) Transforms a list into anStringarray.static String[][]removeColumnArray(String[][] array, int idxColumnToRemove) Remove a column from an array.static String[]retrieveSubfolders(String pathFolder) Returns the names of the subfolders in a certain folder.static voidsetStateNodeAndParents(DiscreteStateNode node, State statesNodes) Sets the state of a given node and its parents from aStateobject.static <T> voidShuffles the elements of a list.stringToList(String listContent) Extract a list of Strings from a String representation of a list with the format "element1,element2,element3" (commas are the delimiters).stringToMap(String mapContent) Extract a map from a String with the format "String:Double,String:Double", where the Strings are the keys and the doubles the values.static intszudzikFunction(int a, int b) Given two non-negative numbers, this method returns a non-negative integer that is uniquely associated with that pair.
-
Method Details
-
arrayToQueue
Converts an array of strings into a queue of strings.- Parameters:
args- the array of strings to be converted- Returns:
- a queue of strings containing the elements from the input array
-
cartesianProduct
Given a list of lists with the possible states of some variables, this method returns the Cartesian product between each of the possible states of each variable.- Parameters:
statesVariables- contains for each variable a list with its possible states- Returns:
- a list of as many states as possible combinations between the states of the variables
-
clone2DArray
public static double[][] clone2DArray(double[][] array) Creates a deep copy of a two-dimensional double array.- Parameters:
array- array to copy- Returns:
- copy of the array
-
clone3DArray
public static double[][][] clone3DArray(double[][][] array) Creates a deep copy of a three-dimensional double array.- Parameters:
array- array to copy- Returns:
- copy of the array
-
combination
Returns all possible combinations of size 'k' of a given list of elements.- Type Parameters:
type- type of the elements- Parameters:
elements- list of elementsk- size of the combinations- Returns:
- all possible combinations of size 'k'
-
extractFirstLong
Returns the firstlongin aString. Returns 0 if it was not possible to extract the number.- Parameters:
string- aStringcontaining along- Returns:
- numbers in the
String
-
extractInt
Returns anintfrom aString. Returns 0 if it was not possible to extract the number.- Parameters:
string- aStringthat includes numbers- Returns:
intin theString
-
extractPathExperimentDatasets
Returns the path to the datasets given the folder of a experiment.- Parameters:
pathExperiment- path to the experiment folder- Returns:
- dataset paths
-
retrieveSubfolders
Returns the names of the subfolders in a certain folder.- Parameters:
pathFolder- path to the folder- Returns:
- names of the subfolders
-
extractLong
Returns alongfrom aString. Returns 0 if it was not possible to extract the number.- Parameters:
string- aStringthat includes numbers- Returns:
longin theString
-
fill3dArray
public static void fill3dArray(double[][][] array, double value) Fills a three-dimensionaldoublearray with the provideddouble.- Parameters:
array- a three-dimensionaldoublearrayvalue-doubleused to fill the array
-
fill2dArray
public static void fill2dArray(double[][] array, double value) Fills a two-dimensionaldoublearray with the provideddouble.- Parameters:
array- a two-dimensionaldoublearrayvalue-doubleused to fill the array
-
filter
Returns the elements of a list "a" except those in "b".- Type Parameters:
T- type of the elements- Parameters:
a- listb- list of elements to filter from "a"- Returns:
- list of "a" without elements in "b"
-
filter
Returns the elements of a list "a" except "b".- Type Parameters:
T- type of the elements- Parameters:
a- listb- element to filter from the list- Returns:
- list "a" without element "b"
-
getEntryLargestValue
Returns entry with the largest value of aMap.- Type Parameters:
k- key type of theMapv- value type of theMap- Parameters:
map- aMap- Returns:
- entry of the largest value
-
getIndexLargestValue
public static int getIndexLargestValue(double[] array) Returns the index of the largest value in an array.- Parameters:
array- array ofdouble- Returns:
- index of the largest value
-
getMaxValue
public static double getMaxValue(double... values) Returns the maximum value between those passed as parameters- Parameters:
values- list ofdouble- Returns:
- maximum value
-
getRandomElements
Getkrandom elements from an {\@code Integer} list.- Parameters:
list- list ofIntegerk- number ofintto retrieve- Returns:
- list of selected random elements
-
getSubsets
Retrieves the possible subsets of a certain size from a given set of elements without including a certain element.- Type Parameters:
type- type of the elements- Parameters:
list- list of elementssize- size of the subsetselementToIgnore- element to ignore- Returns:
- list of subsets
-
isArrayEmpty
public static <T> boolean isArrayEmpty(T[] array) Checks if an array is empty.- Type Parameters:
T- type of the elements in the array- Parameters:
array- array- Returns:
trueif the array is empty,falseotherwise
-
kroneckerDelta
Kronecker delta function. It returns one if 'a' and 'b' are equal and zero otherwise.- Parameters:
a- aStringb- aString- Returns:
- 1 if 'a' and 'b' are equal, 0 otherwise
-
listToArray
Transforms a list into anStringarray.- Parameters:
list- list- Returns:
Stringarray
-
listsOfNodeContainSameElements
public static <typeNode extends Node> boolean listsOfNodeContainSameElements(List<typeNode> listA, List<typeNode> listB) Checks if two given lists ofNodecontain the same elements independently of their orders.- Type Parameters:
typeNode- subtype of theNodeobjects- Parameters:
listA- a list ofNodelistB- a list ofNode- Returns:
trueif the lists contain the same elements,falseotherwise.
-
removeColumnArray
Remove a column from an array.- Parameters:
array- array which column should be removedidxColumnToRemove- index of the column to remove- Returns:
- array without the selected column
-
setStateNodeAndParents
Sets the state of a given node and its parents from aStateobject.- Parameters:
node- node whose state is changedstatesNodes-Statewith the state of the node and its parents
-
shuffle
Shuffles the elements of a list. The seed is computed using the current system time if the provided one is null.- Type Parameters:
T- type of the elements to shuffle- Parameters:
list- list to shuffleseed- seed used to shuffle the sequences
-
stringToList
Extract a list of Strings from a String representation of a list with the format "element1,element2,element3" (commas are the delimiters).- Parameters:
listContent- string containing the list elements separated by semicolons- Returns:
- list of strings, each representing an element from the input string
-
stringToMap
Extract a map from a String with the format "String:Double,String:Double", where the Strings are the keys and the doubles the values.- Parameters:
mapContent- string containing key-value pairs separated by colons and commas- Returns:
- map where each key and value is extracted from the input string
-
szudzikFunction
public static int szudzikFunction(int a, int b) Given two non-negative numbers, this method returns a non-negative integer that is uniquely associated with that pair.- Parameters:
a- non-negativeintb- non-negativeint- Returns:
- non-negative
intuniquely associated with the provided pair of non-negativeint - See Also:
-