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 long
extractFirstLong
(String string) Returns the firstlong
in aString
.static int
extractInt
(String string) Returns anint
from aString
.static long
extractLong
(String string) Returns along
from aString
.static String[]
extractPathExperimentDatasets
(String pathExperiment) Returns the path to the datasets given the folder of a experiment.static void
fill2dArray
(double[][] array, double value) Fills a two-dimensionaldouble
array with the provideddouble
.static void
fill3dArray
(double[][][] array, double value) Fills a three-dimensionaldouble
array 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 int
getIndexLargestValue
(double[] array) Returns the index of the largest value in an array.static double
getMaxValue
(double... values) Returns the maximum value between those passed as parametersgetRandomElements
(List<Integer> list, int k) Getk
random 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> boolean
isArrayEmpty
(T[] array) Checks if an array is empty.static int
kroneckerDelta
(String[] a, String[] b) Kronecker delta function.static <typeNode extends Node>
booleanlistsOfNodeContainSameElements
(List<typeNode> listA, List<typeNode> listB) Checks if two given lists ofNode
contain the same elements independently of their orders.static String[]
listToArray
(List<?> list) Transforms a list into anString
array.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 void
setStateNodeAndParents
(DiscreteStateNode node, State statesNodes) Sets the state of a given node and its parents from aState
object.static <T> void
Shuffles 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 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.
-
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 firstlong
in aString
. Returns 0 if it was not possible to extract the number.- Parameters:
string
- aString
containing along
- Returns:
- numbers in the
String
-
extractInt
Returns anint
from aString
. Returns 0 if it was not possible to extract the number.- Parameters:
string
- aString
that includes numbers- Returns:
int
in 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 along
from aString
. Returns 0 if it was not possible to extract the number.- Parameters:
string
- aString
that includes numbers- Returns:
long
in theString
-
fill3dArray
public static void fill3dArray(double[][][] array, double value) Fills a three-dimensionaldouble
array with the provideddouble
.- Parameters:
array
- a three-dimensionaldouble
arrayvalue
-double
used to fill the array
-
fill2dArray
public static void fill2dArray(double[][] array, double value) Fills a two-dimensionaldouble
array with the provideddouble
.- Parameters:
array
- a two-dimensionaldouble
arrayvalue
-double
used 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 theMap
v
- 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
Getk
random elements from an {\@code Integer} list.- Parameters:
list
- list ofInteger
k
- number ofint
to 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:
true
if the array is empty,false
otherwise
-
kroneckerDelta
Kronecker delta function. It returns one if 'a' and 'b' are equal and zero otherwise.- Parameters:
a
- aString
b
- aString
- Returns:
- 1 if 'a' and 'b' are equal, 0 otherwise
-
listToArray
Transforms a list into anString
array.- Parameters:
list
- list- Returns:
String
array
-
listsOfNodeContainSameElements
public static <typeNode extends Node> boolean listsOfNodeContainSameElements(List<typeNode> listA, List<typeNode> listB) Checks if two given lists ofNode
contain the same elements independently of their orders.- Type Parameters:
typeNode
- subtype of theNode
objects- Parameters:
listA
- a list ofNode
listB
- a list ofNode
- Returns:
true
if the lists contain the same elements,false
otherwise.
-
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 aState
object.- Parameters:
node
- node whose state is changedstatesNodes
-State
with 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-negativeint
b
- non-negativeint
- Returns:
- non-negative
int
uniquely associated with the provided pair of non-negativeint
- See Also:
-