Package es.urjc.etsii.grafo.util
Class StringUtil
java.lang.Object
es.urjc.etsii.grafo.util.StringUtil
String Utils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Base 64 decode a string.static String
Base 64 decode a stringstatic String
b64encode
(byte[] bytes) Base 64 encode a byte arraystatic String
Base 64 encode a string.static String
Base 64 encode a stringstatic String
Generate secret using a SecureRandom.static String
generateSecret
(int size) Generate secret using a SecureRandomstatic int
levenshtein
(int[] lhs, int[] rhs) Calculate the minimum number of operations required to transform one array into another.static int
levenshtein
(int[] lhs, int limitlhs, int[] rhs, int limitrhs) Calculate the minimum number of operations required to transform one array into another.static int
levenshtein
(CharSequence lhs, CharSequence rhs) Calculate the minimum number of operations required to transform one string into another.static String
longestCommonPrefix
(String[] data) Find the longest common prefix given a list of strings.static String
longestCommonSuffix
(String[] data) Find the longest common suffix given a list of strings.static String
static String
Reverse string, ie, "abc" becomes "cba"
-
Constructor Details
-
StringUtil
public StringUtil()
-
-
Method Details
-
b64decode
Base 64 decode a string. Uses UTF-8- Parameters:
s
- String to decode- Returns:
- decoded string
-
b64decode
Base 64 decode a string- Parameters:
s
- String to decodecharset
- Charset to use- Returns:
- decoded string
-
b64encode
Base 64 encode a string. Uses UTF-8- Parameters:
s
- String to encode- Returns:
- encoded string
-
b64encode
Base 64 encode a string- Parameters:
s
- String to encodecharset
- Charset to use- Returns:
- encoded string
-
b64encode
Base 64 encode a byte array- Parameters:
bytes
- bytes to encode- Returns:
- encoded string
-
generateSecret
Generate secret using a SecureRandom- Parameters:
size
- size in bytes.- Returns:
- Base64 encoded secret.
-
generateSecret
Generate secret using a SecureRandom. Size defaults to 16 bytes.- Returns:
- Base64 encoded secret.
-
randomAlgorithmName
-
levenshtein
Calculate the minimum number of operations required to transform one string into another. In Levenshtein distance, valid operations are insert, remove and swap/replace. Adapted from: Wikibooks- Parameters:
lhs
- first stringrhs
- second string- Returns:
- minimum number of operations required to transform the first string into the second.
-
levenshtein
public static int levenshtein(int[] lhs, int[] rhs) Calculate the minimum number of operations required to transform one array into another. In Levenshtein distance, valid operations are insert, remove and swap/replace. Adapted from: Wikibooks- Parameters:
lhs
- first stringrhs
- second string- Returns:
- minimum number of operations required to transform the first string into the second.
-
levenshtein
public static int levenshtein(int[] lhs, int limitlhs, int[] rhs, int limitrhs) Calculate the minimum number of operations required to transform one array into another. In Levenshtein distance, valid operations are insert, remove and swap/replace. Adapted from: Wikibooks- Parameters:
lhs
- first stringrhs
- second string- Returns:
- minimum number of operations required to transform the first string into the second.
-
longestCommonPrefix
Find the longest common prefix given a list of strings. WARNING: The method will sort the array given as an argument, modifying it. Clone it before calling this method if this behaviour is not desired.- Parameters:
data
- Array of strings used to calculate common prefix- Returns:
- Longest common prefix for all strings given as argument
-
longestCommonSuffix
Find the longest common suffix given a list of strings.- Parameters:
data
- Array of strings used to calculate common prefix- Returns:
- Longest common prefix for all strings given as argument
-
reverse
Reverse string, ie, "abc" becomes "cba"- Parameters:
s
- string to reverse- Returns:
- reversed string
-