Package utils

Class BuilderUtils

java.lang.Object
utils.BuilderUtils

public class BuilderUtils extends Object
Java class for manipulating StringBuilders as well as strings to allow string modification, reading and file writing operations.
Since:
27/07/2023
Author:
Nidhal Mareghni and Killian Monnier
  • Constructor Details

    • BuilderUtils

      public BuilderUtils()
  • Method Details

    • writeFileFromArray

      public static void writeFileFromArray(List<String> lines, String filePath)
      Writes lines to a file.
      Parameters:
      lines - the list of extracted rows
      filePath - the file path
    • writeFileFromBuilder

      public static void writeFileFromBuilder(StringBuilder builder, String filePath)
      Allows writing a file with a StringBuilder.
      Parameters:
      builder - the builder
    • appendStringBuilders

      public static void appendStringBuilders(StringBuilder sourceBuilder, StringBuilder targetBuilder, String beginOfLine, String endOfLine)
      Adding one builder to another.
      Parameters:
      sourceBuilder - the builder to add
      targetBuilder - the builder who receives
      beginOfLine - each line begins with this string
      endOfLine - each line ends with this string
    • readBuilderLines

      public static void readBuilderLines(StringBuilder builder, Consumer<String> line)
      Allows to read lines iteratively from a builder.
      Parameters:
      builder - the builder in question
      line - the lambda expression to run
    • readFileLines

      public static void readFileLines(String filepath, Consumer<String> line)
      Allows you to read the lines of a file and make changes to them.
      Parameters:
      filepath - file path
      line - lambda expression
    • extractPatternFromFile

      public static ArrayList<String> extractPatternFromFile(String filePath, String regex_pattern)
      Extract lines matching a certain pattern from the file.
      Parameters:
      filePath - file path
      regex_pattern - the recovery pattern
      Returns:
      list of rows extracted
    • extractFunctionName

      public static String extractFunctionName(String signature)
      Allows you to extract the name of a function.
      Parameters:
      signature - function signature
      Returns:
      the name of the function
    • extractParamTypesAndNames

      public static ArrayList<Pair<String,String>> extractParamTypesAndNames(String signature)
      Allows to extract the types and names of the parameters of a function in order of appearance.
      Parameters:
      signature - function signature
      Returns:
      the list of parameter types and names in order of appearance
    • extractParamNames

      public static List<String> extractParamNames(String signature)
      Allows to extract the names of the parameters of a function.
      Parameters:
      signature - function signature
      Returns:
      the list of parameter names
    • extractFunctionTypes

      public static ArrayList<String> extractFunctionTypes(String signature)
      Gives the types of the function's parameters and return from a line corresponding to the format of a function.
      Parameters:
      signature - function signature
      Returns:
      types list
    • getListWithoutBrackets

      public static String getListWithoutBrackets(List<String> list)
      Allows you to retrieve the values of a list without the [ ].
      Parameters:
      list - the list containing character strings
      Returns:
      a string of list values
    • removeSemicolon

      public static String removeSemicolon(String input)
      Delete it ; at the end of a line.
      Parameters:
      input - the line string
      Returns:
      the line without the semicolon
    • extractPairKeys

      public static <K, V> List<K> extractPairKeys(List<Pair<K,V>> pairList)
      Extract all the keys from a Pair type.
      Type Parameters:
      K - key
      V - value
      Parameters:
      pairList - list of pair
      Returns:
      list of keys of all the pairs
    • extractPairValues

      public static <K, V> List<V> extractPairValues(List<Pair<K,V>> pairList)
      Extract all the values from a Pair type.
      Type Parameters:
      K - key
      V - value
      Parameters:
      pairList - list of pair
      Returns:
      list of values of all the pairs
    • getKeyFromValue

      public static <K, V> K getKeyFromValue(Map<K,V> map, V value)
      Retrieves the key corresponding to the specified value from the given map.
      Type Parameters:
      K - the type of keys in the map
      V - the type of values in the map
      Parameters:
      map - the map containing key-value pairs
      value - the value whose key is to be retrieved
      Returns:
      the key associated with the specified value, or null if not found
    • modifyList

      public static List<String> modifyList(List<String> list, String target, String value)
      Modifies a list by replacing a target element with a new value.
      Parameters:
      list - the original list.
      target - the target element to be replaced.
      value - the new value to replace the target element.
      Returns:
      a new unmodifiable list with the target element replaced.
    • formattingLineList

      public static String formattingLineList(List<String> lines, String beginOfLine, String endOfLine)
      Format all the lines in the list and return the string formatted.
      Parameters:
      lines - list of lines
      beginOfLine - characters of begin of each line
      endOfLine - characters of end of each line
      Returns:
      the lines concatenated and formatted
    • formattingLine

      public static String formattingLine(String line, String beginOfLine, String endOfLine)
      Format the line and return the string formatted.
      Parameters:
      line - line
      beginOfLine - characters of begin of the line
      endOfLine - characters of end of the line
      Returns:
      the line formatted
    • replaceTypes

      public static String replaceTypes(Map<String,String> typesReplacement, String line)
      Replaces occurrences of types from the provided dictionary in the given line.
      Parameters:
      typesReplacement - a dictionary where keys are old types and values are new types.
      line - the input line of text containing type declarations.
      Returns:
      the line with replaced type occurrences.