Package org.okkam.awesome.utils
Class OkkamStrings
- java.lang.Object
-
- org.okkam.awesome.utils.OkkamStrings
-
public class OkkamStrings extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> StringBuilderappendAll(StringBuilder sb, T... elements)Append to the string Builder all elements.static <T> StringconcatRange(T[] arr, String separator, int from, int to)Generate a String by concatenating Array fields between 'from' and 'to' position.static <T> StringconcatRanges(T[] arr, String separator, int... ranges)Generate a String by concatenating Array fields between some position ranges.static Stringduplicate(String stringToDuplicate, int times)Duplicate the string n times.static booleanisEmptyAndNotNull(String string, boolean trim)Check if the string is empty and not null.static booleanisEmptyOrNull(String string, boolean trim)Check if the string is null or empty.static booleanisOneOf(String string, boolean trim, String... ors)Check if the string is one of the specified values.static booleannoOneIsEmptyOrNull(boolean trim, String... strings)Check if the strings are not empty and not blank.static <T> StringseparateArrayBy(T[] array, String separator)Generate a string based on array, with a specified separator.static <T> StringseparateTreeMapValuesBy(Map<T,String> map, String separator)Generate a string based on map values, with a specified separator.static String[]splitByChar(String stringToSplit, char charToSplit)Split a string by a char.static StringtrimIfNecessary(boolean trim, String src)Returns the trimmed string when not null and necessary (i.e.
-
-
-
Method Detail
-
isEmptyOrNull
public static boolean isEmptyOrNull(String string, boolean trim)
Check if the string is null or empty.- Parameters:
string- The input stringtrim- true to trim the input string (when not null)- Returns:
- The check result
-
isEmptyAndNotNull
public static boolean isEmptyAndNotNull(String string, boolean trim)
Check if the string is empty and not null.- Parameters:
string- The input stringtrim- true to trim the input string (when not null)- Returns:
- The check result
-
noOneIsEmptyOrNull
public static boolean noOneIsEmptyOrNull(boolean trim, String... strings)Check if the strings are not empty and not blank.- Parameters:
trim- true to trim the strings (when not empty)strings- The input strings- Returns:
- The check result
-
isOneOf
public static boolean isOneOf(String string, boolean trim, String... ors)
Check if the string is one of the specified values. String could also be null, in this case the method will return true if there's a null element in the passed array.- Parameters:
string- The input stringtrim- true to trim the strings to check for equalityors- The values to check- Returns:
- A boolean value depending on the result
-
trimIfNecessary
public static String trimIfNecessary(boolean trim, String src)
Returns the trimmed string when not null and necessary (i.e. trim is true).- Parameters:
trim- true to trim the passed stringsrc- the string to trim (maybe)- Returns:
- the trimmed string (if necessary). Return null if src is null.
-
appendAll
@SafeVarargs public static <T> StringBuilder appendAll(StringBuilder sb, T... elements)
Append to the string Builder all elements.- Type Parameters:
T- The elements type- Parameters:
sb- The string builderelements- The elements to append- Returns:
- The new string builder
-
separateArrayBy
public static <T> String separateArrayBy(T[] array, String separator)
Generate a string based on array, with a specified separator.- Type Parameters:
T- The array type- Parameters:
array- The input arrayseparator- The separator- Returns:
- The generated string
-
separateTreeMapValuesBy
public static <T> String separateTreeMapValuesBy(Map<T,String> map, String separator)
Generate a string based on map values, with a specified separator. Use a tree map to guarantee ordering.- Type Parameters:
T- The map key type- Parameters:
map- The input mapseparator- The separator- Returns:
- The generated string
-
splitByChar
public static String[] splitByChar(String stringToSplit, char charToSplit)
Split a string by a char.- Parameters:
stringToSplit- The string to be splitcharToSplit- The char used to split the string- Returns:
- The string array
-
concatRange
public static <T> String concatRange(T[] arr, String separator, int from, int to)
Generate a String by concatenating Array fields between 'from' and 'to' position.- Parameters:
arr- The array from which elements are obtainedseparator- The string used as separatorfrom- The starting positionto- The ending position- Returns:
- The concatenated string
-
concatRanges
public static <T> String concatRanges(T[] arr, String separator, int... ranges)
Generate a String by concatenating Array fields between some position ranges.- Parameters:
arr- The array from which elements are obtainedseparator- The string used as separatorranges- The pairs of ranges- Returns:
- The concatenated string
-
-