public class S extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
S.Buffer
A `S.Buffer` is OSGL's implementation of JDK's
StringBuilder with additional method to track
the state of the instance, i.e. |
static class |
S.F |
| Modifier and Type | Field and Description |
|---|---|
static String |
COMMON_SEP
A commonly used separator: [,;:\\s]+
|
static String |
HSEP
The invisible separator used by program: " "
|
static int |
IGNORECASE
equal modifier: specify
equal comparison
should ignore leading and after spaces. |
static int |
IGNORESPACE
equal modifier: specify
equal comparison
should be case insensitive |
| Constructor and Description |
|---|
S() |
| Modifier and Type | Method and Description |
|---|---|
static String |
after(String s0,
String search) |
static String |
after(String s0,
String search,
boolean first) |
static String |
afterFirst(String s0,
String search) |
static String |
afterLast(String s0,
String search) |
static boolean |
allBlank(String... sa)
Check if all of the specified string is
blank |
static boolean |
allEmpty(String... sa)
Alias of
isAllEmpty(String...) |
static boolean |
anyBlank(String... sa)
Check if anyone of the specified string is
blank |
static boolean |
anyEmpty(String... sa)
Alias of
isAnyEmpty(String...) |
static String |
before(String s0,
String search) |
static String |
before(String s0,
String search,
boolean last) |
static String |
beforeFirst(String s0,
String search) |
static String |
beforeLast(String s0,
String search) |
static boolean |
blank(String s)
Determine if a string is all blank or empty or null
|
static S.Buffer |
buffer()
Returns a
S.Buffer instance. |
static S.Buffer |
buffer(boolean o) |
static S.Buffer |
buffer(byte o) |
static S.Buffer |
buffer(char o) |
static S.Buffer |
buffer(double o) |
static S.Buffer |
buffer(float o) |
static S.Buffer |
buffer(int o) |
static S.Buffer |
buffer(long o) |
static S.Buffer |
buffer(Object o) |
static S.Buffer |
buffer(short o) |
static S.Buffer |
buffer(String s) |
static StringBuilder |
builder()
Returns the ThreadLocal StringBuilder instance with length set to 0
|
static StringBuilder |
builder(boolean o) |
static StringBuilder |
builder(byte o) |
static StringBuilder |
builder(char o) |
static StringBuilder |
builder(double o) |
static StringBuilder |
builder(float o) |
static StringBuilder |
builder(int o) |
static StringBuilder |
builder(long o) |
static StringBuilder |
builder(Object o) |
static StringBuilder |
builder(short o) |
static StringBuilder |
builder(String s) |
static String |
camelCase(CharSequence s) |
static String |
capFirst(String s) |
static String |
concat(Object[] oa) |
static String |
concat(Object o1,
Object o2) |
static String |
concat(Object o1,
Object o2,
Object o3) |
static String |
concat(Object o1,
Object o2,
Object o3,
Object o4) |
static String |
concat(Object o1,
Object o2,
Object o3,
Object o4,
Object o5) |
static String |
concat(Object o1,
Object o2,
Object o3,
Object o4,
Object o5,
Object... extra) |
static String |
concat(String[] sa) |
static String |
concat(String s1,
String s2) |
static String |
concat(String s1,
String s2,
String s3) |
static String |
concat(String s1,
String s2,
String s3,
String s4) |
static String |
concat(String s1,
String s2,
String s3,
String s4,
String s5) |
static String |
concat(String s1,
String s2,
String s3,
String s4,
String s5,
String... extra) |
static int |
count(String s,
String search)
Count how many times a search string occurred in the give string
|
static int |
count(String s,
String search,
boolean overlap)
Count how many times a search string occurred in the give string
|
static String |
cutOff(String s,
int max)
Return a string no longer than specified max length.
|
static String |
dashed(CharSequence s) |
static String |
decodeBase64(String string) |
static String |
decodeBASE64(String str)
Decode Base64 encoded string
|
static String |
dos2unix(String s) |
static boolean |
empty(String s)
Determine if a string is empty or null
|
static String |
encodeBase64(String str) |
static String |
encodeBASE64(String str)
Encode a string using Base64 encoding
|
static boolean |
endsWith(String string,
char suffix) |
static boolean |
endsWith(String string,
String suffix) |
static String |
ensureEndsWith(String string,
char suffix) |
static String |
ensureEndsWith(String string,
String suffix) |
static String |
ensureStartsWith(String string,
char prefix) |
static String |
ensureStartsWith(String string,
String prefix) |
static boolean |
eq(String s1,
String s2)
alias of
equal(String, String) |
static boolean |
eq(String s1,
String s2,
int modifier)
Alias of
equal(String, String, int) |
static boolean |
equal(int modifier,
String... sa)
Check if all strings are equal to each other
|
static boolean |
equal(String s1,
String s2)
Return true if 2 strings are equals to each other without
ignore space and case sensitive.
|
static boolean |
equal(String s1,
String s2,
int modifier)
Return true if 2 strings are equals to each other as per rule specified
|
static String |
fileExtension(String fileName)
Get the extension of a filename
|
static String |
first(String s,
int n)
Return the string of first N chars.
|
static String |
fmt(String tmpl) |
static String |
fmt(String tmpl,
Object... args)
A handy alias for
String.format(String, Object...) |
static boolean |
isAllBlank(String... sa)
Alias of
allBlank(String...) |
static boolean |
isAllEmpty(String... sa)
Check if all of the specified string is
empty |
static boolean |
isAnyBlank(String... sa)
Alias of
anyBlank(String...) |
static boolean |
isAnyEmpty(String... sa)
Check if anyone of the specified string is
empty |
static boolean |
isBlank(String s)
alias of
blank(String) |
static boolean |
isEmpty(String s)
alias of
empty(String) |
static boolean |
isEqual(String s1,
String s2)
alias of
eq(String, String) |
static boolean |
isEqual(String s1,
String s2,
int modifier)
Alias of
equal(String, String, int) |
static boolean |
isIntOrLong(String s)
Check if a string is integer or long
|
static boolean |
isNotBlank(String s)
Antonym of
blank(String) |
static boolean |
isNotEmpty(String s)
alias of
notEmpty(String) |
static String |
join(String s,
int times)
Join a string for n times
|
static String |
join(String separator,
Iterable<?> iterable)
Join a list of object into a string
|
static String |
join(String separator,
String... list)
Join an array of strings into a string
|
static String |
join(String separator,
String s,
int times)
Join a string by separator for n times
|
static String |
join(String separator,
String prefix,
String suffix,
Iterable<?> iterable)
Join a list of object into a string, prefix and suffix will be added if supplied
|
static String |
join(String separator,
String prefix,
String suffix,
Iterable<?> iterable,
boolean quoted,
boolean separateFixes)
Join a list of object into a string, prefix and suffix will be added if supplied
|
static String |
last(String s,
int n)
Return last n chars
|
static int |
len(String s1) |
static int |
len(String s1,
String... sa) |
static String |
lowerFirst(String s) |
static String |
lpad(String s,
char c,
int number)
Alias of
padLeft(String, char, int) |
static String |
lpad(String s,
int number)
Alias of
padLeft(String, int) |
static String |
maxLength(String s,
int max)
Return a string no longer than specified max length.
|
static boolean |
neq(String s1,
String s2)
Antonym of
equal(String, String) |
static boolean |
neq(String s1,
String s2,
int modifier)
Antonym of
equal(String, String, int) |
static S.Buffer |
newBuffer()
Returns an new
S.Buffer instance |
static S.Buffer |
newBuffer(byte o) |
static S.Buffer |
newBuffer(char o) |
static S.Buffer |
newBuffer(double o) |
static S.Buffer |
newBuffer(float o) |
static S.Buffer |
newBuffer(int o) |
static S.Buffer |
newBuffer(long o) |
static S.Buffer |
newBuffer(Object o) |
static S.Buffer |
newBuffer(short o) |
static S.Buffer |
newBuffer(String s) |
static StringBuilder |
newBuilder()
Return an new StringBuilder instance
|
static StringBuilder |
newBuilder(byte o) |
static StringBuilder |
newBuilder(char o) |
static StringBuilder |
newBuilder(double o) |
static StringBuilder |
newBuilder(float o) |
static StringBuilder |
newBuilder(int o) |
static StringBuilder |
newBuilder(long o) |
static StringBuilder |
newBuilder(Object o) |
static StringBuilder |
newBuilder(short o) |
static StringBuilder |
newBuilder(String s) |
static S.Buffer |
newSizedBuffer(int size)
Return an new
S.Buffer instance with predefined size specified |
static StringBuilder |
newSizedBuilder(int capacity) |
static boolean |
noBlank(String... sa)
Antonym of
anyBlank(String...) |
static boolean |
noEmpty(String... sa)
Antonym of
anyEmpty(String...) |
static boolean |
notBlank(String s)
Antonym of
blank(String) |
static boolean |
notEmpty(String s)
Antonym of
empty(String) |
static boolean |
notEqual(String s1,
String s2)
Return false if 2 strings are equals to each other
|
static String |
padLeft(String s,
char c,
int number)
Left pad a string with character specified
|
static String |
padLeft(String s,
int number)
Left pad a string with number of space specified
|
static String |
padRight(String s,
char c,
int number)
Right pad a string with character specified
|
static String |
padRight(String s,
int number)
Right pad a string with number of space specified
|
static String |
pathConcat(String prefix,
char sep,
String suffix) |
static String |
quote(String s,
char quote) |
static String |
quote(String s,
String quote) |
static String |
random() |
static String |
random(int len)
Generate random string.
|
static String |
rpad(String s,
char c,
int number)
Alias of
padRight(String, char, int) |
static String |
rpad(String s,
int number)
Alias of
padRight(String, int) |
static S.Buffer |
sizedBuffer(int size) |
static StringBuilder |
sizedBuilder(int capacity)
Deprecated.
|
static boolean |
startsWith(String string,
char prefix) |
static boolean |
startsWith(String string,
String prefix) |
static Str |
str(char... ca) |
static Str |
str(Object o) |
static String |
string(Object o) |
static String |
string(Object o,
boolean quoted)
Get string representation of an object instance
|
static String |
strip(Object o,
String prefix,
String suffix)
Strip the prefix and suffix from an object's String representation and
return the result
|
static String |
times(char c,
int times)
Return a string composed of `times` of char `c`
|
static String |
times(String s,
int times)
Alias of
join(String, int) |
static String |
trim(String s)
Null safety trim
|
static String |
underscore(CharSequence s) |
static String |
unix2dos(String s) |
static String |
unsafeCapFirst(String s) |
static String |
urlDecode(String s) |
static String |
urlEncode(String s)
perform URL encoding on a giving string
|
static String |
uuid() |
public static final String HSEP
public static final String COMMON_SEP
public static final int IGNORECASE
equal comparison
should ignore leading and after spaces. i.e. it will call trim()
method on strings before comparisonpublic static final int IGNORESPACE
equal comparison
should be case insensitivepublic static final String fmt(String tmpl, Object... args)
String.format(String, Object...)tmpl - the message templateargs - the message argumentspublic static boolean isEmpty(String s)
empty(String)s - the string to be checkedpublic static boolean empty(String s)
s - the string to be checkedpublic static boolean blank(String s)
s - the string to be checkedpublic static boolean isBlank(String s)
blank(String)s - the string to be checkedpublic static boolean isNotEmpty(String s)
notEmpty(String)s - the string to be checkeds is null or emptypublic static boolean notEmpty(String s)
empty(String)s - the string to be checkeds is not null or emptypublic static boolean notBlank(String s)
blank(String)s - the string to be checkeds is not null or empty or all in blankpublic static boolean isNotBlank(String s)
blank(String)s - the string to be checkeds is not null or empty or all in blankpublic static boolean isAllEmpty(String... sa)
emptysa - the string to be checkedpublic static boolean allEmpty(String... sa)
isAllEmpty(String...)sa - the strings to be checkedpublic static boolean isAllBlank(String... sa)
allBlank(String...)sa - the strings to be checkedpublic static boolean allBlank(String... sa)
blanksa - the strings to be checkedpublic static boolean isAnyEmpty(String... sa)
emptysa - the strings to be checkedtrue if anyone of the specified string is emptypublic static boolean anyEmpty(String... sa)
isAnyEmpty(String...)sa - the strings to be checkedtrue if anyone of the specified string is emptypublic static boolean isAnyBlank(String... sa)
anyBlank(String...)sa - the strings to be checkedtrue if anyone of the specified string is blankpublic static boolean anyBlank(String... sa)
blanksa - the strings to be checkedtrue if anyone of the specified string is blankpublic static boolean noEmpty(String... sa)
anyEmpty(String...)sa - the strings to be checkedfalse if anyone of the specified string is emptypublic static boolean noBlank(String... sa)
anyBlank(String...)sa - the strings to be checkedfalse if anyone of the specified string is emptypublic static boolean isIntOrLong(String s)
s - the stringtrue if the string is integer or longpublic static String first(String s, int n)
If n is negative number, then return a string of the first N chars
If n is larger than the length of the string, then return the string
s - the string from which the first `n` chars will be returnedn - the number of chars to be returned from `s`public static int len(String s1)
public static String concat(String s1, String s2, String s3, String s4, String s5, String... extra)
public static String concat(Object o1, Object o2, Object o3, Object o4, Object o5, Object... extra)
public static boolean endsWith(String string, char suffix)
public static boolean startsWith(String string, char prefix)
public static String join(String separator, Iterable<?> iterable)
separator - the symbol used to separate the listed itmesiterable - a list of object instancespublic static String join(String separator, String prefix, String suffix, Iterable<?> iterable)
separator - the symbols used to separate the listed items and prefix and suffixprefix - the symbols prepended to the beginning of the item listsuffix - the symbols appended to the end of the item listiterable - an iterablepublic static String join(String separator, String prefix, String suffix, Iterable<?> iterable, boolean quoted, boolean separateFixes)
separator - the symbols used to separate the listed items and prefix and suffixprefix - the symbols prepended to the beginning of the item listsuffix - the symbols appended to the end of the item listiterable - an iterablequoted - if true then each listed item will be quoted with quotation markseparateFixes - if false then no separator after prefix and no separator before suffixpublic static String join(String separator, String... list)
separator - the symbol used to separate the listed itmeslist - the array of stringspublic static String join(String separator, String s, int times)
separator - the separators - the string to be joinedtimes - the times the string to be joinedpublic static String join(String s, int times)
s - the string to be joinedtimes - the times the string to be joinedpublic static String times(String s, int times)
join(String, int)s - the string to be joinedtimes - the times the string to be joinedpublic static String times(char c, int times)
c - the charactertimes - the number of times the c in the string returnedpublic static String cutOff(String s, int max)
Return a string no longer than specified max length.
If the string supplied is longer than the specified max length then only it's part that is less than the max length returned, appended with "..."
s - the original stringmax - the maximum length of the resultpublic static String maxLength(String s, int max)
Return a string no longer than specified max length.
If the string supplied is longer than the specified max length then only it's part that is less than the max length returned, appended with "..."
s - the original stringmax - the maximum length of the resultpublic static String last(String s, int n)
s - the string from which last `n` chars will be returnedn - the number of chars should be returned from `s`public static String trim(String s)
s - the string to be trimedpublic static int count(String s, String search)
s - string to be searchedsearch - the search tokenpublic static int count(String s, String search, boolean overlap)
s - string to be searchedsearch - the search tokenoverlap - specify if it should take overlap into considerationspublic static String camelCase(CharSequence s)
public static String underscore(CharSequence s)
public static String dashed(CharSequence s)
public static boolean eq(String s1, String s2)
equal(String, String)s1 - string 1s2 - string 2true if s1 equals to s2public static boolean eq(String s1, String s2, int modifier)
equal(String, String, int)s1 - string 1s2 - String 2modifier - could be combination of IGNORESPACE or IGNORECASEpublic static boolean neq(String s1, String s2)
equal(String, String)s1 - string 1s2 - string 2true if s1 doesn't equal to s2public static boolean neq(String s1, String s2, int modifier)
equal(String, String, int)s1 - string 1s2 - string 2modifier - could be combination of IGNORESPACE or IGNORECASEtrue if s1 doesn't equal to s2 as per modifierpublic static boolean equal(String s1, String s2)
s1 - string 1s2 - string 2true if s1 equals to s2public static boolean notEqual(String s1, String s2)
s1 - string 1s2 - string 2public static boolean isEqual(String s1, String s2)
eq(String, String)s1 - string 1s2 - string 2true if s1 equals to s2public static boolean equal(String s1, String s2, int modifier)
s1 - string 1s2 - String 2modifier - could be combination of IGNORESPACE or IGNORECASEpublic static boolean equal(int modifier,
String... sa)
modifier - specify whether ignore space or case sensitivesa - the list of stringstrue if all strings are equal to each other as per modifier specifiedpublic static boolean isEqual(String s1, String s2, int modifier)
equal(String, String, int)s1 - string 1s2 - string 2modifier - the modifier could be combination of IGNORESPACE or IGNORECASEtrue if s1 equals to s2 as per modifierpublic static String strip(Object o, String prefix, String suffix)
For example:
Object o = "xxBByy";
String s = S.strip(o, "xx", "yy")
At the end above code, s should be "BB"
o - the object to which string representation will be usedprefix - the prefixsuffix - the suffixpublic static String padLeft(String s, char c, int number)
s - the stringc - the characternumber - the number of character to pad to the leftpublic static String padLeft(String s, int number)
s - the stringnumber - the number of space to left pad to `s`public static String lpad(String s, char c, int number)
padLeft(String, char, int)s - the stringc - the charnumber - number of char to be left pad to `s`public static String lpad(String s, int number)
padLeft(String, int)s - the stringnumber - the number of space to left pad to `s`public static String padRight(String s, char c, int number)
s - the stringc - the characternumber - the number of character to pad to the leftpublic static String padRight(String s, int number)
s - the stringnumber - the number of space to right pad to `s`public static String rpad(String s, char c, int number)
padRight(String, char, int)s - the stringc - the charnumber - number of char to be left pad to `s`public static String rpad(String s, int number)
padRight(String, int)s - the stringnumber - the number of space to left pad to `s`public static String decodeBASE64(String str)
str - the string to be decodedpublic static String encodeBASE64(String str)
str - the string to be encodedpublic static String urlEncode(String s)
s - the string to be encodedpublic static String fileExtension(String fileName)
fileName - the (supposed) file namepublic static String uuid()
public static String random(int len)
len - the number of chars in the returned stringpublic static final String random()
public static final String string(Object o, boolean quoted)
o - the instance to be displayedquoted - whether display quotation markpublic static Str str(char... ca)
public static S.Buffer newSizedBuffer(int size)
S.Buffer instance with predefined size specifiedsize - the initial capacity of the bufferpublic static S.Buffer sizedBuffer(int size)
public static S.Buffer newBuffer()
S.Buffer instancepublic static S.Buffer newBuffer(byte o)
public static S.Buffer newBuffer(short o)
public static S.Buffer newBuffer(char o)
public static S.Buffer newBuffer(int o)
public static S.Buffer newBuffer(float o)
public static S.Buffer newBuffer(long o)
public static S.Buffer newBuffer(double o)
public static S.Buffer buffer()
S.Buffer instance. If the thread local instance is consumed already
then return it. Otherwise, return an new `Buffer` instancepublic static S.Buffer buffer(boolean o)
public static S.Buffer buffer(byte o)
public static S.Buffer buffer(short o)
public static S.Buffer buffer(char o)
public static S.Buffer buffer(int o)
public static S.Buffer buffer(float o)
public static S.Buffer buffer(long o)
public static S.Buffer buffer(double o)
public static StringBuilder newBuilder()
public static StringBuilder newBuilder(byte o)
public static StringBuilder newBuilder(short o)
public static StringBuilder newBuilder(char o)
public static StringBuilder newBuilder(int o)
public static StringBuilder newBuilder(float o)
public static StringBuilder newBuilder(long o)
public static StringBuilder newBuilder(double o)
public static StringBuilder newBuilder(Object o)
public static StringBuilder newBuilder(String s)
public static StringBuilder builder()
public static StringBuilder builder(boolean o)
public static StringBuilder builder(byte o)
public static StringBuilder builder(short o)
public static StringBuilder builder(char o)
public static StringBuilder builder(int o)
public static StringBuilder builder(float o)
public static StringBuilder builder(long o)
public static StringBuilder builder(double o)
public static StringBuilder builder(Object o)
public static StringBuilder builder(String s)
@Deprecated public static StringBuilder sizedBuilder(int capacity)
public static StringBuilder newSizedBuilder(int capacity)
Copyright © 2017. All Rights Reserved.