Package io.sundr.utils
Class Strings
- java.lang.Object
-
- io.sundr.utils.Strings
-
public final class Strings extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStrings.ToString<X>
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringcamelCase(String name)Converts the given string to camelCase format.static StringcapitalizeFirst(String str)static Stringcompact(String name)Remove repeating strings that are appearing in the name.static StringdeCapitalizeFirst(String str)static StringgetPrefix(Iterable<String> items)static <T> StringgetPrefix(Iterable<T> items, Function<T,String> function)static Stringindent(String indent, String s)static intindexOfAlphabetic(String str)static booleanisNotNullOrEmpty(String str)static booleanisNullOrEmpty(String str)static <T> Stringjoin(Iterable<T> items, String delimiter)static <T> Stringjoin(Iterable<T> items, Function<T,String> function, String delimiter)static <T> Stringjoin(T[] items, String delimiter)static <T> Stringjoin(T[] items, Function<T,String> function, String delimiter)static StringloadResource(String resourceName)static StringloadResource(URL resourceUrl)static StringloadResourceQuietly(String resourceName)static StringloadResourceQuietly(URL resourceUrl)static StringprefixKeywords(String name)Adds an underscore to the specified String, if its a Java Keyword.static StringtoFieldName(String name)Converts the string into a safe field name.static StringtoPojoName(String name, String prefix, String suffix)Converts a name of an interface or abstract class to Pojo name.
-
-
-
Method Detail
-
isNullOrEmpty
public static boolean isNullOrEmpty(String str)
-
isNotNullOrEmpty
public static boolean isNotNullOrEmpty(String str)
-
indexOfAlphabetic
public static int indexOfAlphabetic(String str)
-
join
public static <T> String join(Iterable<T> items, Function<T,String> function, String delimiter)
-
loadResource
public static String loadResource(String resourceName) throws IOException
- Throws:
IOException
-
loadResource
public static String loadResource(URL resourceUrl) throws IOException
- Throws:
IOException
-
compact
public static final String compact(String name)
Remove repeating strings that are appearing in the name. This is done by splitting words (camel case) and using each word once.- Parameters:
name- The name to compact.- Returns:
- The compact name.
-
prefixKeywords
public static final String prefixKeywords(String name)
Adds an underscore to the specified String, if its a Java Keyword.- Parameters:
name- The specified string.- Returns:
- The specified string if not a keyword, the string prefixed with underscore otherwise.
-
toFieldName
public static final String toFieldName(String name)
Converts the string into a safe field name.- Parameters:
name- The field name.- Returns:
- The safe field name.
-
camelCase
public static final String camelCase(String name)
Converts the given string to camelCase format.This method takes a string input and converts it to camelCase format, where each word in the input string is capitalized (except the first word) and concatenated together without spaces. Non-alphanumeric characters are treated as word separators.
If the input string is
null,nullis returned. If the input string is empty or contains only non-alphanumeric characters, an empty string is returned.For example:
camelCase("helloWorld") returns "helloWorld" camelCase("hello_world") returns "helloWorld" camelCase("hello world") returns "helloWorld" camelCase("foo-bar-baz") returns "fooBarBaz" camelCase("123_456_789") returns "123456789" camelCase(" ") returns "" camelCase(null) returns null- Parameters:
name- the string to convert to camelCase- Returns:
- the input string converted to camelCase format, or
nullif the input string isnull, or an empty string if the input string is empty or contains only non-alphanumeric characters
-
toPojoName
public static final String toPojoName(String name, String prefix, String suffix)
Converts a name of an interface or abstract class to Pojo name. Remove leading "I" and "Abstract" or trailing "Interface".- Parameters:
name- The name to convert.prefix- The prefix to use if needed.suffix- The suffix to user if needed.- Returns:
- The converted name, if a conversion actually happened or the original name prefixed and suffixed otherwise.
-
-