java.lang.Object
es.upm.fi.cig.multictbnc.util.Util

public final class Util extends Object
Utility class.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Queue<String>
    Converts an array of strings into a queue of strings.
    static List<State>
    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.
    static <type> List<List<type>>
    combination(List<type> elements, int k)
    Returns all possible combinations of size 'k' of a given list of elements.
    static long
    Returns the first long in a String.
    static int
    Returns an int from a String.
    static long
    Returns a long from a String.
    static String[]
    Returns the path to the datasets given the folder of a experiment.
    static void
    fill2dArray(double[][] array, double value)
    Fills a two-dimensional double array with the provided double.
    static void
    fill3dArray(double[][][] array, double value)
    Fills a three-dimensional double array with the provided double.
    static <T> List<T>
    filter(List<T> a, List<T> b)
    Returns the elements of a list "a" except those in "b".
    static <T> List<T>
    filter(List<T> a, T b)
    Returns the elements of a list "a" except "b".
    static <k, v extends Comparable<v>>
    Map.Entry<k,v>
    Returns entry with the largest value of a Map.
    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 parameters
    static List<Integer>
    Get k random elements from an {\@code Integer} list.
    static <type> List<List<type>>
    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
    Kronecker delta function.
    static <typeNode extends Node>
    boolean
    listsOfNodeContainSameElements(List<typeNode> listA, List<typeNode> listB)
    Checks if two given lists of Node contain the same elements independently of their orders.
    static String[]
    listToArray(List<?> list)
    Transforms a list into an String array.
    static String[][]
    removeColumnArray(String[][] array, int idxColumnToRemove)
    Remove a column from an array.
    static String[]
    Returns the names of the subfolders in a certain folder.
    static void
    Sets the state of a given node and its parents from a State object.
    static <T> void
    shuffle(List<T> list, Long seed)
    Shuffles the elements of a list.
    static List<String>
    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).
    static Map<String,Double>
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • arrayToQueue

      public static Queue<String> arrayToQueue(String[] args)
      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

      public static List<State> 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.
      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

      public static <type> List<List<type>> combination(List<type> elements, int k)
      Returns all possible combinations of size 'k' of a given list of elements.
      Type Parameters:
      type - type of the elements
      Parameters:
      elements - list of elements
      k - size of the combinations
      Returns:
      all possible combinations of size 'k'
    • extractFirstLong

      public static long extractFirstLong(String string)
      Returns the first long in a String. Returns 0 if it was not possible to extract the number.
      Parameters:
      string - a String containing a long
      Returns:
      numbers in the String
    • extractInt

      public static int extractInt(String string)
      Returns an int from a String. Returns 0 if it was not possible to extract the number.
      Parameters:
      string - a String that includes numbers
      Returns:
      int in the String
    • extractPathExperimentDatasets

      public static String[] extractPathExperimentDatasets(String pathExperiment)
      Returns the path to the datasets given the folder of a experiment.
      Parameters:
      pathExperiment - path to the experiment folder
      Returns:
      dataset paths
    • retrieveSubfolders

      public static String[] retrieveSubfolders(String pathFolder)
      Returns the names of the subfolders in a certain folder.
      Parameters:
      pathFolder - path to the folder
      Returns:
      names of the subfolders
    • extractLong

      public static long extractLong(String string)
      Returns a long from a String. Returns 0 if it was not possible to extract the number.
      Parameters:
      string - a String that includes numbers
      Returns:
      long in the String
    • fill3dArray

      public static void fill3dArray(double[][][] array, double value)
      Fills a three-dimensional double array with the provided double.
      Parameters:
      array - a three-dimensional double array
      value - double used to fill the array
    • fill2dArray

      public static void fill2dArray(double[][] array, double value)
      Fills a two-dimensional double array with the provided double.
      Parameters:
      array - a two-dimensional double array
      value - double used to fill the array
    • filter

      public static <T> List<T> filter(List<T> a, List<T> b)
      Returns the elements of a list "a" except those in "b".
      Type Parameters:
      T - type of the elements
      Parameters:
      a - list
      b - list of elements to filter from "a"
      Returns:
      list of "a" without elements in "b"
    • filter

      public static <T> List<T> filter(List<T> a, T b)
      Returns the elements of a list "a" except "b".
      Type Parameters:
      T - type of the elements
      Parameters:
      a - list
      b - element to filter from the list
      Returns:
      list "a" without element "b"
    • getEntryLargestValue

      public static <k, v extends Comparable<v>> Map.Entry<k,v> getEntryLargestValue(Map<k,v> map)
      Returns entry with the largest value of a Map.
      Type Parameters:
      k - key type of the Map
      v - value type of the Map
      Parameters:
      map - a Map
      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 of double
      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 of double
      Returns:
      maximum value
    • getRandomElements

      public static List<Integer> getRandomElements(List<Integer> list, int k)
      Get k random elements from an {\@code Integer} list.
      Parameters:
      list - list of Integer
      k - number of int to retrieve
      Returns:
      list of selected random elements
    • getSubsets

      public static <type> List<List<type>> 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.
      Type Parameters:
      type - type of the elements
      Parameters:
      list - list of elements
      size - size of the subsets
      elementToIgnore - 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

      public static int kroneckerDelta(String[] a, String[] b)
      Kronecker delta function. It returns one if 'a' and 'b' are equal and zero otherwise.
      Parameters:
      a - a String
      b - a String
      Returns:
      1 if 'a' and 'b' are equal, 0 otherwise
    • listToArray

      public static String[] listToArray(List<?> list)
      Transforms a list into an String 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 of Node contain the same elements independently of their orders.
      Type Parameters:
      typeNode - subtype of the Node objects
      Parameters:
      listA - a list of Node
      listB - a list of Node
      Returns:
      true if the lists contain the same elements, false otherwise.
    • removeColumnArray

      public static String[][] removeColumnArray(String[][] array, int idxColumnToRemove)
      Remove a column from an array.
      Parameters:
      array - array which column should be removed
      idxColumnToRemove - index of the column to remove
      Returns:
      array without the selected column
    • setStateNodeAndParents

      public static void setStateNodeAndParents(DiscreteStateNode node, State statesNodes)
      Sets the state of a given node and its parents from a State object.
      Parameters:
      node - node whose state is changed
      statesNodes - State with the state of the node and its parents
    • shuffle

      public static <T> void shuffle(List<T> list, Long seed)
      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 shuffle
      seed - seed used to shuffle the sequences
    • stringToList

      public static List<String> 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).
      Parameters:
      listContent - string containing the list elements separated by semicolons
      Returns:
      list of strings, each representing an element from the input string
    • stringToMap

      public static Map<String,Double> 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.
      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-negative int
      b - non-negative int
      Returns:
      non-negative int uniquely associated with the provided pair of non-negative int
      See Also: