jlibs.core.lang
Class StringUtil

java.lang.Object
  extended by jlibs.core.lang.StringUtil

public class StringUtil
extends Object

Author:
Santhosh Kumar T

Constructor Summary
StringUtil()
           
 
Method Summary
static String capitalize(String str)
          Converts first character in str to uppercase.
static boolean equalsIgnoreCase(String s1, String s2)
           
static String fromLiteral(String str)
           
static String[] getTokens(String str, String delim, boolean trim)
          Splits given string into tokens with delimiters specified.
static boolean isEmpty(CharSequence str)
          returns true if str is null or its length is zero
static boolean isWhitespace(CharSequence str)
          returns true if str is null or it contains only whitespaces.
static
<T> String
join(Iterator<T> iter)
           
static
<T> String
join(Iterator<T> iter, String separator)
           
static
<T> String
join(Iterator<T> iter, String separator, Convertor<T,String> convertor)
           
static
<T> String
join(T[] array)
           
static
<T> String
join(T[] array, String separator)
           
static
<T> String
join(T[] array, String separator, Convertor<T,String> convertor)
           
static String ordinalize(int number)
          Turns a non-negative number into an ordinal string used to denote the position in an ordered sequence, such as 1st, 2nd, 3rd, 4th
static String suggest(Filter<String> filter, String pattern, boolean tryEmptyVar)
          the pattern specified must have variable part ${i} example: test${i}.txt it will find a string using pattern, which is accepted by the specified filter.
static int[] toCodePoints(String str)
           
static String toLiteral(char ch, boolean useRaw)
           
static String toLiteral(CharSequence str, boolean useRaw)
           
static String toString(Object obj)
          if obj is null, returns empty string.
static String underscore(String camelCaseWord)
          Makes an underscored form from the expression in the string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtil

public StringUtil()
Method Detail

equalsIgnoreCase

public static boolean equalsIgnoreCase(String s1,
                                       String s2)

toString

public static String toString(Object obj)
if obj is null, returns empty string. otherwise returns obj.toString()


isEmpty

public static boolean isEmpty(CharSequence str)
returns true if str is null or its length is zero


isWhitespace

public static boolean isWhitespace(CharSequence str)
returns true if str is null or it contains only whitespaces.

Character.isWhitespace(char) is used to test for whitespace


getTokens

public static String[] getTokens(String str,
                                 String delim,
                                 boolean trim)
Splits given string into tokens with delimiters specified. It uses StringTokenizer for tokenizing.

Parameters:
str - string to be tokenized
delim - delimiters used for tokenizing
trim - trim the tokens
Returns:
non-null token array

suggest

public static String suggest(Filter<String> filter,
                             String pattern,
                             boolean tryEmptyVar)
the pattern specified must have variable part ${i} example: test${i}.txt it will find a string using pattern, which is accepted by the specified filter. if tryEmptyVar is true, it searches in order: test.txt, test2.txt, test3.txt and so on if tryEmptyVar is false, it searches in order: test1.txt, test2.txt, test3.txt and so on

See Also:
FileUtil.findFreeFile(java.io.File dir, String pattern, boolean tryEmptyVar)

capitalize

public static String capitalize(String str)
Converts first character in str to uppercase.

This method can be called on string of any length.

Parameters:
str - string to be converted
Returns:
string with first letter changed to uppercase

underscore

public static String underscore(String camelCaseWord)
Makes an underscored form from the expression in the string.

Examples:

 underscore("activeRecord")     // "active_record"
 underscore("ActiveRecord")     // "active_record"
 underscore("firstName")        // "first_name"
 underscore("FirstName")        // "first_name"
 underscore("name")             // "name"
 

Parameters:
camelCaseWord - the camel-cased word that is to be converted;
Returns:
a lower-cased version of the input, with separate words delimited by the underscore character.

ordinalize

public static String ordinalize(int number)
Turns a non-negative number into an ordinal string used to denote the position in an ordered sequence, such as 1st, 2nd, 3rd, 4th

Parameters:
number - the non-negative number
Returns:
the string with the number and ordinal suffix

toCodePoints

public static int[] toCodePoints(String str)

join

public static <T> String join(T[] array)

join

public static <T> String join(T[] array,
                              String separator)

join

public static <T> String join(T[] array,
                              String separator,
                              Convertor<T,String> convertor)

join

public static <T> String join(Iterator<T> iter)

join

public static <T> String join(Iterator<T> iter,
                              String separator)

join

public static <T> String join(Iterator<T> iter,
                              String separator,
                              Convertor<T,String> convertor)

toLiteral

public static String toLiteral(char ch,
                               boolean useRaw)

toLiteral

public static String toLiteral(CharSequence str,
                               boolean useRaw)

fromLiteral

public static String fromLiteral(String str)


Copyright © 2018. All rights reserved.