Package co.ecg.alpaca.commons.formatting
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStringUtils.RandomSetGeneratorClass to Handle Generation of Random Sets of BroadWorks Valid Characters
-
Constructor Summary
Constructors Constructor Description StringUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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 stringbuilderstatic 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 StringgetDomain(String string)Returns the domain on the provided string if found otherwise null.static 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 booleanhasRepeatPattern(String s)Checks if a string contains a repeating patternstatic booleanhasReversedPattern(String s, String toCheck)Checks if a string contains a reversed stringstatic booleanisInteger(String s)static List<String>numbersAndRangesToNumberList(List<String> numbersAndRanges)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 StringshuffleString(String z)Shuffles the characters of a String
-
-
-
Method Detail
-
removeDomainIfDefault
public static String removeDomainIfDefault(String userId, String defaultDomain)
removeDomainIfDefault.
-
returnUserWithDomain
public static String returnUserWithDomain(String userId, String defaultDomain)
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
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 stringdomain- 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 replacementsubstring- The substring to searchreplacement- 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 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
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 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
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- aByteobject.- Returns:
- An int count of characters.
-
numbersAndRangesToNumberList
public static List<String> numbersAndRangesToNumberList(List<String> numbersAndRanges) throws PhoneNumberParseException
numbersAndRangesToNumberList.
- Parameters:
numbersAndRanges- aListobject.- Returns:
- a
Listobject. - Throws:
PhoneNumberParseException- if any.
-
isInteger
public static boolean isInteger(String s)
-
-