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 class
Class to Handle Generation of Random Sets of BroadWorks Valid Characters -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
appendDomain
(String string, String domain) Appends the provided domain to the given string following the '@' character.static void
appendFile
(File f, StringBuilder sb) Appends the given file to a stringbuildercharacterCountMap
(String text) static boolean
checkAscendingDigits
(char[] passcode, int length) Checks a string for ascending digits.static boolean
checkDescendingDigits
(char[] passcode, int length) Checks a string for descending digits.static int
countCharactersInString
(String s, Byte... characterTypes) Counts the number of occurrences of character types within a provided String.static boolean
static String
Returns the domain on the provided string if found otherwise null.static boolean
hasAscendingOrDescendingSequentialSequence
(String text, int length) Checks for ascending or descending sequential parts in a Stringstatic boolean
hasContiguousSequence
(String s, int maxContiguous) Checks if a string contains a contiguous sequence i.e.static boolean
hasRepeatCharacters
(String s, int maxRepeat) Checks if a string contains a certain amount of repeated characters.static boolean
Checks if a string contains a repeating patternstatic boolean
hasReversedPattern
(String s, String toCheck) Checks if a string contains a reversed stringstatic boolean
isEmpty
(CharSequence cs) static boolean
static boolean
static boolean
static boolean
isValidEmail
(String email) static String
joinWithConjunction
(List<String> elements, CharSequence cs, String conjunction) static String
nullToEmpty
(String value) numbersAndRangesToNumberList
(List<String> numbersAndRanges) numbersAndRangesToNumberList
(List<String> numbersAndRanges, PhoneNumber.PhoneNumberFormat numberFormat) numbersAndRangesToNumberList.static String
removeDomain
(String string) Removes a domain on the provided string if foundstatic String
removeDomainIfDefault
(String userId, String defaultDomain) removeDomainIfDefault.static String
replaceLast
(String string, String substring, String replacement) Replace the last occurance of the substring with the provided replacement.static String
returnUserWithDomain
(String userId, String defaultDomain) Returns the UserID with the domain attached if neededstatic String
Shuffles the characters of a Stringstatic String
toBasicJson
(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
- aByte
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
- aList
object.- Returns:
- a
List
object. - 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
-