Class StringUtils

java.lang.Object
co.ecg.alpaca.commons.formatting.StringUtils

public class StringUtils extends Object
Utility class to house String utility methods that are not included in the Apache Commons StringUtils or are too specific in their requirements.
Version:
$Id: $Id
Author:
Matthew Keathley on 6/5/15
  • Constructor Details

    • StringUtils

      public StringUtils()
  • Method Details

    • removeDomainIfDefault

      public static String removeDomainIfDefault(String userId, String defaultDomain)

      removeDomainIfDefault.

      Parameters:
      userId - a String object.
      defaultDomain - a String object.
      Returns:
      a String object.
    • returnUserWithDomain

      public static String returnUserWithDomain(String userId, String defaultDomain)
      Returns the UserID with the domain attached if needed
      Parameters:
      userId - The user ID
      defaultDomain - The default domain
      Returns:
      the UserID with the domain attached
    • getDomain

      public static String getDomain(String string)
      Returns the domain on the provided string if found otherwise null.
      Parameters:
      string - The string to retrieve the domain
      Returns:
      The domain if available or null otherwise.
    • removeDomain

      public static String removeDomain(String string)
      Removes a domain on the provided string if found
      Parameters:
      string - The string to remove the domain
      Returns:
      The string with any domain removed.
    • appendDomain

      public static String appendDomain(String string, String domain)
      Appends the provided domain to the given string following the '@' character.
      Parameters:
      string - The string
      domain - The domain to append
      Returns:
      The string and domain appended
    • replaceLast

      public static String replaceLast(String string, String substring, String replacement)
      Replace the last occurance of the substring with the provided replacement.
      Parameters:
      string - The string to perform replacement
      substring - The substring to search
      replacement - The replacement for the substring
      Returns:
      Return the new String
    • appendFile

      public static void appendFile(File f, StringBuilder sb)
      Appends the given file to a stringbuilder
      Parameters:
      f - The file to append
      sb - The Stringbuilder to append to
    • checkAscendingDigits

      public static boolean checkAscendingDigits(char[] passcode, int length)
      Checks a string for ascending digits.
      Parameters:
      passcode - The string to check.
      length - The number of sequentially ascending characters to check for.
      Returns:
      True if the check passes, false it it fails.
    • checkDescendingDigits

      public static boolean checkDescendingDigits(char[] passcode, int length)
      Checks a string for descending digits.
      Parameters:
      passcode - The string to check.
      length - The number of sequentially descending characters to check for.
      Returns:
      True if the check passes, false it it fails.
    • shuffleString

      public static String shuffleString(String z)
      Shuffles the characters of a String
      Parameters:
      z - The String to Shuffle
      Returns:
      The Shuffled String or null if the input is null
    • hasRepeatCharacters

      public static boolean hasRepeatCharacters(String s, int maxRepeat)
      Checks if a string contains a certain amount of repeated characters.
      Parameters:
      s - The string to check.
      maxRepeat - The number of times a character is allowed to repeat
      Returns:
      True if the the string has more repeat character than allowed, false otherwise.
    • hasContiguousSequence

      public static boolean hasContiguousSequence(String s, int maxContiguous)
      Checks if a string contains a contiguous sequence i.e. 1123 - 11 being the contiguous sequence

      BW Passcode Rules: cannot contain the same digit more than N times in a row BW Password Rules: TBD

      Parameters:
      s - The string to check.
      maxContiguous - a int.
      Returns:
      True if the string has a contiguous sequence, false otherwise.
    • hasRepeatPattern

      public static boolean hasRepeatPattern(String s)
      Checks if a string contains a repeating pattern
      Parameters:
      s - The string to check.
      Returns:
      True if the string has a repeating pattern sequence, false otherwise.
    • hasReversedPattern

      public static boolean hasReversedPattern(String s, String toCheck)
      Checks if a string contains a reversed string
      Parameters:
      s - The string to check.
      toCheck - The string to check for the reverse of.
      Returns:
      True if the string has a reversed pattern sequence, false otherwise.
    • countCharactersInString

      public static int countCharactersInString(String s, Byte... characterTypes)
      Counts the number of occurrences of character types within a provided String.
      Parameters:
      s - The string to check.
      characterTypes - a Byte object.
      Returns:
      An int count of characters.
    • numbersAndRangesToNumberList

      public static List<String> numbersAndRangesToNumberList(List<String> numbersAndRanges) throws PhoneNumberParseException
      Throws:
      PhoneNumberParseException
    • numbersAndRangesToNumberList

      public static List<String> numbersAndRangesToNumberList(List<String> numbersAndRanges, PhoneNumber.PhoneNumberFormat numberFormat) throws PhoneNumberParseException

      numbersAndRangesToNumberList.

      Parameters:
      numbersAndRanges - a List object.
      Returns:
      a List object.
      Throws:
      PhoneNumberParseException - if any.
    • isInteger

      public static boolean isInteger(String s)
    • isEmpty

      public static boolean isEmpty(CharSequence cs)
    • isNumeric

      public static boolean isNumeric(CharSequence cs)
    • joinWithConjunction

      public static String joinWithConjunction(List<String> elements, CharSequence cs, String conjunction)
    • exists

      public static boolean exists(String text)
    • hasAscendingOrDescendingSequentialSequence

      public static boolean hasAscendingOrDescendingSequentialSequence(String text, int length)
      Checks for ascending or descending sequential parts in a String

      Examples: - abcddjsfhjasg - abcd is sequential, so it returns true - ooadfuhfera - Returns false

      Parameters:
      text - The text to check
      length - The number of sequential characters in a row to check for
      Returns:
      True if a sequence is found, false otherwise
    • isTrue

      public static boolean isTrue(String text)
    • characterCountMap

      public static HashMap<Character,Integer> characterCountMap(String text)
    • isValidEmail

      public static boolean isValidEmail(String email)
    • toBasicJson

      public static String toBasicJson(String value)
    • nullToEmpty

      public static String nullToEmpty(String value)