Class Utils
- java.lang.Object
-
- io.inversion.utils.Utils
-
public class Utils extends java.lang.ObjectCollection of utility methods designed to make java programming less verbose
-
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends java.util.Collection>
Tadd(T collection, java.lang.Object... items)Fluent override of Collections.addAll()static java.util.MapaddToMap(java.util.Map map, java.lang.Object... keyValuePairs)static java.util.ArrayListasList(java.lang.Object... objects)Similar to Arrays.asList but with raw ArrayList return type assuming that all objects don't have to be the same type.static java.util.LinkedHashMapasMap(java.lang.Object... keyValuePairs)Adds each even and old object as a key/value pair to a HashMapstatic java.util.HashSetasSet(java.lang.Object... objects)Similar to Arrays.asList but returning a raw HashSet assuming that all objects don't have to be the same type.static booleanatob(java.lang.Object str)Converst a string to a boolean.static doubleatod(java.lang.Object str)Convert a string to a double.static floatatof(java.lang.Object str)Convert a string to a float.static intatoi(java.lang.Object str)Convert a string to an integer.static longatol(java.lang.Object str)Convert a string to a long.static java.lang.StringbeautifyName(java.lang.String name)Try to make an attractive camelCase valid javascript variable name.static java.lang.StringbytesToHex(byte[] bytes)static java.lang.Stringcapitalize(java.lang.String str)static java.lang.Objectcast(java.lang.Class clazz, java.lang.String string)static booleancheckSame(java.lang.String str1, java.lang.String str2)static voidclose(java.lang.Object... toClose)Utility to call a close() method on supplied objects if it exists and completely ignore any exceptions.static booleancontainsToken(java.lang.String findThisToken, java.lang.String inThisString)Checks for a whole word case insensitive match offindThisTokenininThisStringstatic java.io.FilecreateTempFile(java.lang.String fileName)static java.util.Datedate(java.lang.String date)Attempts to parse a date with several usual formats.static java.util.Datedate(java.lang.String date, java.lang.String format)Faster way to apply a SimpleDateFormat without having to catch ParseExceptionstatic java.lang.Stringdequote(java.lang.String str)Removes all matching pairs of '"` characters from the start and end of a string.static java.lang.Stringdequote(java.lang.String str, char[] quoteChars)Removes all matching pairs of leading/trailingquoteCharsfrom the start and end of a string.static java.util.Setdisjunction(java.util.Collection a, java.util.Collection b)Returns the items of 'a' that are not in 'b' and the items of 'b' that are not in 'a'.static booleanempty(java.lang.Object... arr)static booleanendsWith(java.lang.CharSequence seq, java.lang.String end)String.endsWith surrogate for StringBuffer and StringBuilderstatic booleanequal(java.lang.Object obj1, java.lang.Object obj2)A null safe loose equality checker.static voiderror(java.lang.String message)Shortcut for throw new RuntimeException(message);static java.lang.RuntimeExceptionex(java.lang.String messageFormat, java.lang.Object... args)static java.lang.RuntimeExceptionex(java.lang.Throwable ex)static java.lang.RuntimeExceptionex(java.lang.Throwable cause, java.lang.String messageFormat, java.lang.Object... args)static java.util.List<java.lang.String>explode(java.lang.String delimiter, java.lang.String... pieces)Similar to String.split but trims whitespace and excludes empty stringsstatic <M extends java.util.Map<java.lang.String,?>>
Mfilter(M map, java.lang.String... tokensToRemove)Removes any keys that contain a whole word token contained in tokensToRemovestatic java.io.InputStreamfindInputStream(java.lang.Object caller, java.lang.String fileOrUrl)Attempts to locate the stream as a file, url, or classpath resourcestatic java.lang.StringfindSysEnvProp(java.lang.String... names)static java.lang.Objectfirst(java.util.List list)static java.lang.Stringformat(java.lang.String format, java.lang.Object... args)A heroically forgiving message string formatter.static java.lang.StringformatDate(java.util.Date date, java.lang.String format)Simple one liner to avoid verbosity of using SimpleDateFormatstatic java.lang.StringformatIso8601(java.util.Date date)static java.lang.ThrowablegetCause(java.lang.Throwable t)Tries to unwrap nested exceptions looking for the root causestatic java.lang.reflect.FieldgetField(java.lang.String fieldName, java.lang.Class clazz)Searches the inheritance hierarchy for a field with the the given name and makes sure it is settable via Field.setAccessible().static java.util.List<java.lang.reflect.Field>getFields(java.lang.Class clazz)Gets all the fields from from all classes in the inheritance hierarchy EXCEPT for any class who's packages starts with "java*".static java.lang.reflect.MethodgetMethod(java.lang.Class clazz, java.lang.String name)Searches the inheritance hierarchy for the first method of the given name (ignores case).static java.lang.ObjectgetProperty(java.lang.String name, java.lang.Object object)Tries to find a bean property getter then defaults to returning the Field valuestatic java.lang.StringgetShortCause(java.lang.Throwable t)static java.lang.StringgetShortCause(java.lang.Throwable t, int lines)static java.util.List<java.lang.String>getStackTraceLines(java.lang.Throwable stackTrace)static java.lang.StringgetStackTraceString(java.lang.Throwable stackTrace)static java.lang.StringgetSysEnvProp(java.lang.String name)static java.lang.StringgetSysEnvProp(java.lang.String name, java.lang.String defaultValue)static java.lang.Stringhash(byte[] bytes, java.lang.String algorithm)static byte[]hexToBytes(java.lang.String hexString)static java.lang.Stringimplode(java.lang.String glue, java.lang.Object... pieces)Concatenates non emptypiecesseparated byglueand intelligently flattens collections.static booleanin(java.lang.Object toFind, java.lang.Object... values)Checks to see iftoFindis invaluesarray using loose equality checkingstatic booleanisRegex(java.lang.String string)Checksstringfor wildcard control characters.static booleanisWildcard(java.lang.String str)static java.lang.Objectlast(java.util.List list)static java.lang.StringlimitLines(java.lang.String text, int limit)static java.lang.Stringmd5(byte[] bytes)static java.lang.Stringpad(java.lang.String input, int len)static java.util.DateparseIso8601(java.lang.String date)static java.util.LinkedHashMap<java.lang.String,java.lang.String>parseQueryString(java.lang.String query)static voidpipe(java.io.InputStream in, java.io.OutputStream out)Copy all data from src to dst and close the streamsstatic voidpipe(java.io.InputStream in, java.io.OutputStream out, boolean closeInputStream, boolean closeOutputStream)static java.lang.StringprintTable(java.util.List<java.util.List> table)static java.lang.Stringread(java.io.File file)Read the contents of a file to a stringstatic java.lang.Stringread(java.io.InputStream in)Read all of the stream to a string and close the stream.static java.lang.Stringread(java.lang.Object caller, java.lang.String fileOrUrl)Finds an input stream forfileOrUrland reads it into a stringstatic java.lang.StringreplaceVars(java.lang.String string, java.util.Map<java.lang.String,java.lang.Object> replacements)Replaces '{mapKeyName}' with 'mapValue' in the supplied string.static voidrethrow(java.lang.String message, java.lang.Throwable error)Throws the root cause of e as a RuntimeExceptionstatic voidrethrow(java.lang.Throwable error)Throws the root cause oferroras a RuntimeExceptionstatic introundUp(int num, int divisor)static java.lang.Stringsha1(byte[] bytes)static voidsleep(long milliseconds)Easy way to call Thread.sleep(long) without worrying about try/catch for InterruptedExceptionstatic java.lang.Stringslugify(java.lang.String str)Creates a lowercase url safe string.static java.util.List<java.lang.String>split(java.lang.String string, char splitOn, char... quoteChars)Breaks the string onsplitOnbut not when inside aquoteCharsquoted string.static java.lang.String[]splitLines(java.lang.String text)static booleanstartsWith(java.lang.CharSequence seq, java.lang.String start)String.startsWith surrogate for StringBuffer and StringBuilderstatic java.lang.StringsubstringAfter(java.lang.String string, java.lang.String breakAfterLast)static java.lang.StringsubstringBefore(java.lang.String string, java.lang.String breakBefore)static booleantestCompare(java.lang.String expected, java.lang.String actual)static longtime()Less typing to call System.currentTimeMillis()static java.math.BigDecimaltoDollarAmount(double amount)Turns a double value into a rounded double with 2 digits of precision 12.3334 -@gt; 12.33 23.0 -@gt; 23.00 45.677 -@gt; 45.68static java.lang.StringtoPluralForm(java.lang.String str)static java.lang.StringtoSingularForm(java.lang.String str)static booleanwildcardMatch(java.lang.String wildcard, java.lang.String string)Pattern matches the string using ? to indicate any one single value and * to indicate any 0-n multiple valuestatic java.lang.StringwildcardToRegex(java.lang.String wildcard)Converts a * and ? wildcard style patterns into regex style patternstatic voidwrite(java.io.File file, java.lang.String text)Write the string value to a filestatic voidwrite(java.lang.String file, java.lang.String text)Convenience overloading of write(File, String)
-
-
-
Method Detail
-
equal
public static boolean equal(java.lang.Object obj1, java.lang.Object obj2)A null safe loose equality checker.- Parameters:
obj1- an objectobj2- an object to compare to obj1- Returns:
- true when args are strictly equal or toString equal
-
in
public static boolean in(java.lang.Object toFind, java.lang.Object... values)Checks to see iftoFindis invaluesarray using loose equality checking- Parameters:
toFind- the object to findvalues- where to try and find it- Returns:
- true if toFind is loosely equal to any of
values
-
empty
public static boolean empty(java.lang.Object... arr)
- Parameters:
arr- an array of objects to check and see if any are not empty- Returns:
- false if any args are not null with a null safe toString().trim().length() @gt; 0
-
first
public static java.lang.Object first(java.util.List list)
-
last
public static java.lang.Object last(java.util.List list)
-
add
public static <T extends java.util.Collection> T add(T collection, java.lang.Object... items)Fluent override of Collections.addAll()- Type Parameters:
T- a subclass of Collection- Parameters:
collection- the collection to add items toitems- the items to add- Returns:
- the collection passed in
- See Also:
Collections.addAll(Collection, Object[])
-
endsWith
public static boolean endsWith(java.lang.CharSequence seq, java.lang.String end)String.endsWith surrogate for StringBuffer and StringBuilder- Parameters:
seq- the string to checkend- the ending to check for- Returns:
- true if seq ends with end
-
startsWith
public static boolean startsWith(java.lang.CharSequence seq, java.lang.String start)String.startsWith surrogate for StringBuffer and StringBuilder- Parameters:
seq- the string to checkstart- the starting substring to check for- Returns:
- true if seq ends with end
-
implode
public static java.lang.String implode(java.lang.String glue, java.lang.Object... pieces)Concatenates non emptypiecesseparated byglueand intelligently flattens collections.- Parameters:
glue- the joining stringpieces- the pieces to join- Returns:
- a concatenation of pieces separated by glue
-
explode
public static java.util.List<java.lang.String> explode(java.lang.String delimiter, java.lang.String... pieces)Similar to String.split but trims whitespace and excludes empty strings- Parameters:
delimiter- the split delimiterpieces- the strings to split- Returns:
- all non empty strings from all pieces
-
split
public static java.util.List<java.lang.String> split(java.lang.String string, char splitOn, char... quoteChars)Breaks the string onsplitOnbut not when inside aquoteCharsquoted string.- Parameters:
string- the string to splitsplitOn- the character to split onquoteChars- quote chars that invalidate the instance of slit char- Returns:
- the split parts
-
substringBefore
public static java.lang.String substringBefore(java.lang.String string, java.lang.String breakBefore)
-
substringAfter
public static java.lang.String substringAfter(java.lang.String string, java.lang.String breakAfterLast)
-
ex
public static java.lang.RuntimeException ex(java.lang.Throwable ex)
-
ex
public static java.lang.RuntimeException ex(java.lang.String messageFormat, java.lang.Object... args)
-
ex
public static java.lang.RuntimeException ex(java.lang.Throwable cause, java.lang.String messageFormat, java.lang.Object... args)
-
format
public static java.lang.String format(java.lang.String format, java.lang.Object... args)A heroically forgiving message string formatter.This method attempts to safely toString all of the args and replaces any "{}" characters with "%s" before formatting via String.format(String, Object[]).
Any Throwables in the args list will have their short cause string appended to the end of the formatted message.
If the format is invalid or contains too few or too many args, the method will make sure that all arg toStrings are in the output.
The goal here is to make sure that no matter what happens, you will get something useful out of this message if not exactly to the format spec.
- Parameters:
format- a string containing "{}" arg placeholders of formatted per java.util.Formatterargs- objects that will be replaced into theirformatplaceholders.- Returns:
- the formatted string
-
addToMap
public static java.util.Map addToMap(java.util.Map map, java.lang.Object... keyValuePairs)
-
asList
public static java.util.ArrayList asList(java.lang.Object... objects)
Similar to Arrays.asList but with raw ArrayList return type assuming that all objects don't have to be the same type.- Parameters:
objects- the objects to add- Returns:
- a new ArrayList containing
objects
-
asSet
public static java.util.HashSet asSet(java.lang.Object... objects)
Similar to Arrays.asList but returning a raw HashSet assuming that all objects don't have to be the same type.- Parameters:
objects- the objects to add- Returns:
- a new HashSet containing
objects
-
asMap
public static java.util.LinkedHashMap asMap(java.lang.Object... keyValuePairs)
Adds each even and old object as a key/value pair to a HashMap- Parameters:
keyValuePairs- a list of key/value pairs that should have an even number of elements- Returns:
- a new HashMap containing keyValuePairs
-
disjunction
public static java.util.Set disjunction(java.util.Collection a, java.util.Collection b)Returns the items of 'a' that are not in 'b' and the items of 'b' that are not in 'a'.
-
replaceVars
public static java.lang.String replaceVars(java.lang.String string, java.util.Map<java.lang.String,java.lang.Object> replacements)Replaces '{mapKeyName}' with 'mapValue' in the supplied string.- Parameters:
string-replacements-- Returns:
-
containsToken
public static boolean containsToken(java.lang.String findThisToken, java.lang.String inThisString)Checks for a whole word case insensitive match offindThisTokenininThisStringhttps://www.baeldung.com/java-regexp-escape-char https://stackoverflow.com/questions/7459263/regex-whole-word
- Parameters:
findThisToken- the string to findinThisString- in this other string- Returns:
- true if findThisToken exists as a whole world in inThisString
-
filter
public static <M extends java.util.Map<java.lang.String,?>> M filter(M map, java.lang.String... tokensToRemove)Removes any keys that contain a whole word token contained in tokensToRemove- Type Parameters:
M-- Parameters:
map-tokensToRemove-- Returns:
- the same map instance, filtered
-
dequote
public static java.lang.String dequote(java.lang.String str)
Removes all matching pairs of '"` characters from the start and end of a string.- Parameters:
str- the string to dequote- Returns:
- str with matched pairs of leading/trailing '"` characters removed
-
dequote
public static java.lang.String dequote(java.lang.String str, char[] quoteChars)Removes all matching pairs of leading/trailingquoteCharsfrom the start and end of a string.- Parameters:
str- the string to dequotequoteChars- characters to treat as quotes- Returns:
- str with matched pairs of leading/trailing quoteChars removed
-
toDollarAmount
public static java.math.BigDecimal toDollarAmount(double amount)
Turns a double value into a rounded double with 2 digits of precision 12.3334 -@gt; 12.33 23.0 -@gt; 23.00 45.677 -@gt; 45.68- Parameters:
amount- the amount to round- Returns:
- the amount rounded to two decimal places
-
roundUp
public static int roundUp(int num, int divisor)
-
atob
public static boolean atob(java.lang.Object str)
Converst a string to a boolean.Easier and null safe way to call Boolean.parseBoolean(str.trim()) that swallows exceptions.
- Parameters:
str- the string to parse as a boolean- Returns:
- true if the trimmed lower case str is "0" or "false"
-
atoi
public static int atoi(java.lang.Object str)
Convert a string to an integer.Easier null safe way to call Integer.parseInt(str.trim()) that swallows exceptions.
- Parameters:
str- the string to parse- Returns:
- the parsed value or -1 if the string does not parse
-
atol
public static long atol(java.lang.Object str)
Convert a string to a long.Easier null safe way to call Long.parseLong(str.trim()) that swallows exceptions.
- Parameters:
str- the string to parse- Returns:
- the parsed value or -1 if the string does not parse
-
atof
public static float atof(java.lang.Object str)
Convert a string to a float.Easier null safe way to call Float.parseFloat(str.trim()) that swallows exceptions.
- Parameters:
str- the string to parse- Returns:
- the parsed value or -1 if the string does not parse
-
atod
public static double atod(java.lang.Object str)
Convert a string to a double.Easier null safe way to call Double.parseDouble(str.trim()) that swallows exceptions.
- Parameters:
str- the string to parse- Returns:
- the parsed value or -1 if the string does not parse
-
slugify
public static java.lang.String slugify(java.lang.String str)
Creates a lowercase url safe string.- Parameters:
str- the string to slugify- Returns:
- the slugified string
-
sha1
public static java.lang.String sha1(byte[] bytes)
- Parameters:
bytes- the bytes to hash- Returns:
- Hash the bytes with SHA-1
-
md5
public static java.lang.String md5(byte[] bytes)
- Parameters:
bytes- the bytes to hash- Returns:
- Hash the bytes with MD5
-
hash
public static java.lang.String hash(byte[] bytes, java.lang.String algorithm)- Parameters:
bytes- the bytes to hashalgorithm- the hash algorithm- Returns:
- Hash the bytes with the given algorithm
-
time
public static long time()
Less typing to call System.currentTimeMillis()- Returns:
- the current time in milliseconds
-
parseIso8601
public static java.util.Date parseIso8601(java.lang.String date)
-
formatIso8601
public static java.lang.String formatIso8601(java.util.Date date)
-
formatDate
public static java.lang.String formatDate(java.util.Date date, java.lang.String format)Simple one liner to avoid verbosity of using SimpleDateFormat- Parameters:
date- the date to formatformat- the format- Returns:
- the formatted date
-
date
public static java.util.Date date(java.lang.String date, java.lang.String format)Faster way to apply a SimpleDateFormat without having to catch ParseException- Parameters:
date- the date string to formatformat- the format string- Returns:
- the formatted date
-
date
public static java.util.Date date(java.lang.String date)
Attempts to parse a date with several usual formats.Formats attempted:
- an ISO8601 data
- EEE MMM dd HH:mm:ss zzz yyyy
- then yyyy-MM-dd
- then MM/dd/yy
- then MM/dd/yyyy
- then yyyyMMdd
- Parameters:
date- the date string to parse- Returns:
- the parsed date
-
testCompare
public static boolean testCompare(java.lang.String expected, java.lang.String actual)
-
getCause
public static java.lang.Throwable getCause(java.lang.Throwable t)
Tries to unwrap nested exceptions looking for the root cause- Parameters:
t- the error to investigate- Returns:
- the recursively root cause
-
error
public static void error(java.lang.String message) throws java.lang.RuntimeExceptionShortcut for throw new RuntimeException(message);- Parameters:
message- the error message- Throws:
java.lang.RuntimeException- always
-
rethrow
public static void rethrow(java.lang.Throwable error) throws java.lang.RuntimeExceptionThrows the root cause oferroras a RuntimeException- Parameters:
error- error to rethrow- Throws:
java.lang.RuntimeException- always
-
rethrow
public static void rethrow(java.lang.String message, java.lang.Throwable error) throws java.lang.RuntimeExceptionThrows the root cause of e as a RuntimeException- Parameters:
message- the optional message to include in the RuntimeExceptionerror- the error to rethrow- Throws:
java.lang.RuntimeException- always
-
sleep
public static void sleep(long milliseconds) throws java.lang.RuntimeExceptionEasy way to call Thread.sleep(long) without worrying about try/catch for InterruptedException- Parameters:
milliseconds- the number of milliseconds to sleep- Throws:
java.lang.RuntimeException- if InterruptedException is thrown
-
getShortCause
public static java.lang.String getShortCause(java.lang.Throwable t)
-
getShortCause
public static java.lang.String getShortCause(java.lang.Throwable t, int lines)
-
getStackTraceLines
public static java.util.List<java.lang.String> getStackTraceLines(java.lang.Throwable stackTrace)
-
getStackTraceString
public static java.lang.String getStackTraceString(java.lang.Throwable stackTrace)
-
splitLines
public static java.lang.String[] splitLines(java.lang.String text)
-
limitLines
public static java.lang.String limitLines(java.lang.String text, int limit)
-
checkSame
public static boolean checkSame(java.lang.String str1, java.lang.String str2)
-
cast
public static java.lang.Object cast(java.lang.Class clazz, java.lang.String string)
-
getField
public static java.lang.reflect.Field getField(java.lang.String fieldName, java.lang.Class clazz)Searches the inheritance hierarchy for a field with the the given name and makes sure it is settable via Field.setAccessible().- Parameters:
fieldName- the field to findclazz- the class to find it in- Returns:
- the first Field found with name
-
getFields
public static java.util.List<java.lang.reflect.Field> getFields(java.lang.Class clazz)
Gets all the fields from from all classes in the inheritance hierarchy EXCEPT for any class who's packages starts with "java*".- Parameters:
clazz- the class to search- Returns:
- all Fields in the inheritance hierarchy other "java*" packages classes.
-
getMethod
public static java.lang.reflect.Method getMethod(java.lang.Class clazz, java.lang.String name)Searches the inheritance hierarchy for the first method of the given name (ignores case).No distinction is made for overloaded method names.
- Parameters:
clazz- the class to searchname- the name of a method to find- Returns:
- the first method with name
-
getProperty
public static java.lang.Object getProperty(java.lang.String name, java.lang.Object object)Tries to find a bean property getter then defaults to returning the Field value- Parameters:
name- the bean property value to findobject- the object to find it in- Returns:
- the value of the bean property with name
-
read
public static java.lang.String read(java.lang.Object caller, java.lang.String fileOrUrl)Finds an input stream forfileOrUrland reads it into a string- Parameters:
fileOrUrl- the resource to read- Returns:
- the content of
codeas a String - See Also:
findInputStream(Object, String)
-
read
public static java.lang.String read(java.io.InputStream in) throws java.lang.RuntimeExceptionRead all of the stream to a string and close the stream.- Parameters:
in- the data to stringify- Returns:
- the data from in as a string
- Throws:
java.lang.RuntimeException- when an IOException is thrown
-
read
public static java.lang.String read(java.io.File file) throws java.io.IOExceptionRead the contents of a file to a string- Parameters:
file- the file to read and stringify- Returns:
- the file text
- Throws:
java.io.IOException- when an IOException is thrown- See Also:
read(InputStream)
-
write
public static void write(java.io.File file, java.lang.String text) throws java.io.IOExceptionWrite the string value to a file- Parameters:
file- the file to writetext- the content to write- Throws:
java.io.IOException- if unable to create the parent directory or when IO fails
-
write
public static void write(java.lang.String file, java.lang.String text) throws java.io.IOExceptionConvenience overloading of write(File, String)- Parameters:
file- the file path to writetext- the text to write to the file- Throws:
java.io.IOException- when thrown- See Also:
write(File, String)
-
pipe
public static void pipe(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOExceptionCopy all data from src to dst and close the streams- Parameters:
in- the data to be writtenout- where the data should be written to- Throws:
java.io.IOException- when thrown
-
pipe
public static void pipe(java.io.InputStream in, java.io.OutputStream out, boolean closeInputStream, boolean closeOutputStream) throws java.io.IOException- Throws:
java.io.IOException
-
createTempFile
public static java.io.File createTempFile(java.lang.String fileName) throws java.io.IOException- Throws:
java.io.IOException
-
findInputStream
public static java.io.InputStream findInputStream(java.lang.Object caller, java.lang.String fileOrUrl) throws java.lang.RuntimeExceptionAttempts to locate the stream as a file, url, or classpath resource- Parameters:
fileOrUrl- a stream resource identifier- Returns:
- an input stream reading fileOrUrl
- Throws:
java.lang.RuntimeException- when and IOException is thrown
-
isRegex
public static boolean isRegex(java.lang.String string)
Checksstringfor wildcard control characters.- Parameters:
string-- Returns:
- true when
stringcontains a regex control character
-
isWildcard
public static boolean isWildcard(java.lang.String str)
- Parameters:
str- the string to chec to see if it is a wildcard pattern.- Returns:
- true if the string contains a * or a ?
-
wildcardMatch
public static boolean wildcardMatch(java.lang.String wildcard, java.lang.String string)Pattern matches the string using ? to indicate any one single value and * to indicate any 0-n multiple value- Parameters:
wildcard- a wildcard patternstring- the string to check to see if it matches the wildcard- Returns:
- true if string matches wildcard
-
wildcardToRegex
public static java.lang.String wildcardToRegex(java.lang.String wildcard)
Converts a * and ? wildcard style patterns into regex style pattern- Parameters:
wildcard- the wildcard expression to convert to a regex- Returns:
- a wildcard pattern converted to a regex
- See Also:
- Code example found here
-
parseQueryString
public static java.util.LinkedHashMap<java.lang.String,java.lang.String> parseQueryString(java.lang.String query)
-
findSysEnvProp
public static java.lang.String findSysEnvProp(java.lang.String... names)
-
getSysEnvProp
public static java.lang.String getSysEnvProp(java.lang.String name, java.lang.String defaultValue)
-
getSysEnvProp
public static java.lang.String getSysEnvProp(java.lang.String name)
-
close
public static void close(java.lang.Object... toClose)
Utility to call a close() method on supplied objects if it exists and completely ignore any exceptions.- Parameters:
toClose- the object to close.
-
toSingularForm
public static java.lang.String toSingularForm(java.lang.String str)
-
toPluralForm
public static java.lang.String toPluralForm(java.lang.String str)
-
capitalize
public static java.lang.String capitalize(java.lang.String str)
-
bytesToHex
public static java.lang.String bytesToHex(byte[] bytes)
-
hexToBytes
public static byte[] hexToBytes(java.lang.String hexString)
-
beautifyName
public static java.lang.String beautifyName(java.lang.String name)
Try to make an attractive camelCase valid javascript variable name.Lots of sql db designers use things like SNAKE_CASE_COLUMN_NAMES that look terrible as json property names.
- Parameters:
name- the to beautify- Returns:
- a camelCased version of
name - See Also:
- JSON property name
-
printTable
public static java.lang.String printTable(java.util.List<java.util.List> table)
-
pad
public static java.lang.String pad(java.lang.String input, int len)
-
-