Package utils
Class BuilderUtils
java.lang.Object
utils.BuilderUtils
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
appendStringBuilders
(StringBuilder sourceBuilder, StringBuilder targetBuilder, String beginOfLine, String endOfLine) Adding one builder to another.static String
extractFunctionName
(String signature) Allows you to extract the name of a function.extractFunctionTypes
(String signature) Gives the types of the function's parameters and return from a line corresponding to the format of a function.static <K,
V> List <K> extractPairKeys
(List<Pair<K, V>> pairList) Extract all the keys from aPair
type.static <K,
V> List <V> extractPairValues
(List<Pair<K, V>> pairList) Extract all the values from aPair
type.extractParamNames
(String signature) Allows to extract the names of the parameters of a function.extractParamTypesAndNames
(String signature) Allows to extract the types and names of the parameters of a function in order of appearance.extractPatternFromFile
(String filePath, String regex_pattern) Extract lines matching a certain pattern from the file.static String
formattingLine
(String line, String beginOfLine, String endOfLine) Format the line and return the string formatted.static String
formattingLineList
(List<String> lines, String beginOfLine, String endOfLine) Format all the lines in the list and return the string formatted.static <K,
V> K getKeyFromValue
(Map<K, V> map, V value) Retrieves the key corresponding to the specified value from the given map.static String
getListWithoutBrackets
(List<String> list) Allows you to retrieve the values of a list without the [ ].modifyList
(List<String> list, String target, String value) Modifies a list by replacing a target element with a new value.static void
readBuilderLines
(StringBuilder builder, Consumer<String> line) Allows to read lines iteratively from a builder.static void
readFileLines
(String filepath, Consumer<String> line) Allows you to read the lines of a file and make changes to them.static String
removeSemicolon
(String input) Delete it ; at the end of a line.static String
replaceTypes
(Map<String, String> typesReplacement, String line) Replaces occurrences of types from the provided dictionary in the given line.static void
writeFileFromArray
(List<String> lines, String filePath) Writes lines to a file.static void
writeFileFromBuilder
(StringBuilder builder, String filePath) Allows writing a file with a StringBuilder.
-
Constructor Details
-
BuilderUtils
public BuilderUtils()
-
-
Method Details
-
writeFileFromArray
Writes lines to a file.- Parameters:
lines
- the list of extracted rowsfilePath
- the file path
-
writeFileFromBuilder
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 addtargetBuilder
- the builder who receivesbeginOfLine
- each line begins with this stringendOfLine
- each line ends with this string
-
readBuilderLines
Allows to read lines iteratively from a builder.- Parameters:
builder
- the builder in questionline
- the lambda expression to run
-
readFileLines
Allows you to read the lines of a file and make changes to them.- Parameters:
filepath
- file pathline
- lambda expression
-
extractPatternFromFile
Extract lines matching a certain pattern from the file.- Parameters:
filePath
- file pathregex_pattern
- the recovery pattern- Returns:
- list of rows extracted
-
extractFunctionName
Allows you to extract the name of a function.- Parameters:
signature
- function signature- Returns:
- the name of the function
-
extractParamTypesAndNames
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
Allows to extract the names of the parameters of a function.- Parameters:
signature
- function signature- Returns:
- the list of parameter names
-
extractFunctionTypes
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
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
Delete it ; at the end of a line.- Parameters:
input
- the line string- Returns:
- the line without the semicolon
-
extractPairKeys
Extract all the keys from aPair
type.- Type Parameters:
K
- keyV
- value- Parameters:
pairList
- list of pair- Returns:
- list of keys of all the pairs
-
extractPairValues
Extract all the values from aPair
type.- Type Parameters:
K
- keyV
- value- Parameters:
pairList
- list of pair- Returns:
- list of values of all the pairs
-
getKeyFromValue
Retrieves the key corresponding to the specified value from the given map.- Type Parameters:
K
- the type of keys in the mapV
- the type of values in the map- Parameters:
map
- the map containing key-value pairsvalue
- the value whose key is to be retrieved- Returns:
- the key associated with the specified value, or
null
if not found
-
modifyList
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
Format all the lines in the list and return the string formatted.- Parameters:
lines
- list of linesbeginOfLine
- characters of begin of each lineendOfLine
- characters of end of each line- Returns:
- the lines concatenated and formatted
-
formattingLine
Format the line and return the string formatted.- Parameters:
line
- linebeginOfLine
- characters of begin of the lineendOfLine
- characters of end of the line- Returns:
- the line formatted
-
replaceTypes
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.
-