Class StringUtil

java.lang.Object
es.urjc.etsii.grafo.util.StringUtil

public class StringUtil extends Object
String Utils
  • Constructor Details

    • StringUtil

      public StringUtil()
  • Method Details

    • b64decode

      public static String b64decode(String s)
      Base 64 decode a string. Uses UTF-8
      Parameters:
      s - String to decode
      Returns:
      decoded string
    • b64decode

      public static String b64decode(String s, Charset charset)
      Base 64 decode a string
      Parameters:
      s - String to decode
      charset - Charset to use
      Returns:
      decoded string
    • b64encode

      public static String b64encode(String s)
      Base 64 encode a string. Uses UTF-8
      Parameters:
      s - String to encode
      Returns:
      encoded string
    • b64encode

      public static String b64encode(String s, Charset charset)
      Base 64 encode a string
      Parameters:
      s - String to encode
      charset - Charset to use
      Returns:
      encoded string
    • b64encode

      public static String b64encode(byte[] bytes)
      Base 64 encode a byte array
      Parameters:
      bytes - bytes to encode
      Returns:
      encoded string
    • generateSecret

      public static String generateSecret(int size)
      Generate secret using a SecureRandom
      Parameters:
      size - size in bytes.
      Returns:
      Base64 encoded secret.
    • generateSecret

      public static String generateSecret()
      Generate secret using a SecureRandom. Size defaults to 16 bytes.
      Returns:
      Base64 encoded secret.
    • randomAlgorithmName

      public static String randomAlgorithmName()
    • levenshtein

      public static int levenshtein(CharSequence lhs, CharSequence rhs)
      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 string
      rhs - 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 string
      rhs - 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 string
      rhs - second string
      Returns:
      minimum number of operations required to transform the first string into the second.
    • longestCommonPrefix

      public static String longestCommonPrefix(String[] data)
      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

      public static String longestCommonSuffix(String[] data)
      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

      public static String reverse(String s)
      Reverse string, ie, "abc" becomes "cba"
      Parameters:
      s - string to reverse
      Returns:
      reversed string