Package co.ecg.alpaca.commons.formatting
Class StringUtils
java.lang.Object
co.ecg.alpaca.commons.formatting.StringUtils
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClass to Handle Generation of Random Sets of BroadWorks Valid Characters -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringappendDomain(String string, String domain) Appends the provided domain to the given string following the '@' character.static voidappendFile(File f, StringBuilder sb) Appends the given file to a stringbuildercharacterCountMap(String text) static booleancheckAscendingDigits(char[] passcode, int length) Checks a string for ascending digits.static booleancheckDescendingDigits(char[] passcode, int length) Checks a string for descending digits.static intcountCharactersInString(String s, Byte... characterTypes) Counts the number of occurrences of character types within a provided String.static booleanstatic StringReturns the domain on the provided string if found otherwise null.static booleanhasAscendingOrDescendingSequentialSequence(String text, int length) Checks for ascending or descending sequential parts in a Stringstatic booleanhasContiguousSequence(String s, int maxContiguous) Checks if a string contains a contiguous sequence i.e.static booleanhasRepeatCharacters(String s, int maxRepeat) Checks if a string contains a certain amount of repeated characters.static booleanChecks if a string contains a repeating patternstatic booleanhasReversedPattern(String s, String toCheck) Checks if a string contains a reversed stringstatic booleanisEmpty(CharSequence cs) static booleanstatic booleanstatic booleanstatic booleanisValidEmail(String email) static StringjoinWithConjunction(List<String> elements, CharSequence cs, String conjunction) static StringnullToEmpty(String value) numbersAndRangesToNumberList(List<String> numbersAndRanges) numbersAndRangesToNumberList(List<String> numbersAndRanges, PhoneNumber.PhoneNumberFormat numberFormat) numbersAndRangesToNumberList.static StringremoveDomain(String string) Removes a domain on the provided string if foundstatic StringremoveDomainIfDefault(String userId, String defaultDomain) removeDomainIfDefault.static StringreplaceLast(String string, String substring, String replacement) Replace the last occurance of the substring with the provided replacement.static StringreturnUserWithDomain(String userId, String defaultDomain) Returns the UserID with the domain attached if neededstatic StringShuffles the characters of a Stringstatic StringtoBasicJson(String value)
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
removeDomainIfDefault
removeDomainIfDefault.
-
returnUserWithDomain
Returns the UserID with the domain attached if needed- Parameters:
userId- The user IDdefaultDomain- The default domain- Returns:
- the UserID with the domain attached
-
getDomain
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
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
Appends the provided domain to the given string following the '@' character.- Parameters:
string- The stringdomain- The domain to append- Returns:
- The string and domain appended
-
replaceLast
Replace the last occurance of the substring with the provided replacement.- Parameters:
string- The string to perform replacementsubstring- The substring to searchreplacement- The replacement for the substring- Returns:
- Return the new String
-
appendFile
Appends the given file to a stringbuilder- Parameters:
f- The file to appendsb- 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
Shuffles the characters of a String- Parameters:
z- The String to Shuffle- Returns:
- The Shuffled String or null if the input is null
-
hasRepeatCharacters
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
Checks if a string contains a contiguous sequence i.e. 1123 - 11 being the contiguous sequenceBW 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
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
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
Counts the number of occurrences of character types within a provided String.- Parameters:
s- The string to check.characterTypes- aByteobject.- 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- aListobject.- Returns:
- a
Listobject. - Throws:
PhoneNumberParseException- if any.
-
isInteger
-
isEmpty
-
isNumeric
-
joinWithConjunction
public static String joinWithConjunction(List<String> elements, CharSequence cs, String conjunction) -
exists
-
hasAscendingOrDescendingSequentialSequence
Checks for ascending or descending sequential parts in a StringExamples: - abcddjsfhjasg - abcd is sequential, so it returns true - ooadfuhfera - Returns false
- Parameters:
text- The text to checklength- The number of sequential characters in a row to check for- Returns:
- True if a sequence is found, false otherwise
-
isTrue
-
characterCountMap
-
isValidEmail
-
toBasicJson
-
nullToEmpty
-