|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.senn.magic.util.StringUtils
public final class StringUtils
This class contains useful and fun methods for String
and text.
Field Summary | |
---|---|
static String |
OUTPUT_CONSOLE
Line break for console output: \n\r |
static String |
OUTPUT_HTML
Line break for html output: <br /> |
Method Summary | |
---|---|
static String |
backwards(String text)
Flip a text backwards. |
static boolean |
compare(String s1,
String s2,
boolean ignoreCase)
This method checks if 2 strings are the same, depending on the value of the ignoreCase variable. |
static Map<String,Integer> |
countChars(String text)
Get all characters used in a text and their respective count. |
static String |
getFillerText(int lineAmount,
String output)
Get a random filler text. |
static List<Integer> |
getOccurrences(String part,
String text,
boolean ignoreCase)
Get the indexes of the occurrences of a certain String inside another String . |
static int |
getOccurrencesCount(String part,
String text,
boolean ignoreCase)
Get the amount of occurrences of a certain String inside another String . |
static String |
invertUpperCaseLowerCase(String text)
Change all uppercase characters to lowercase and vice versa. |
static boolean |
isValid(String value)
Checks if a given String value is valid, meaning it is not null and the length > 0. |
static List<String> |
split(String text,
char separator)
Split a text using a single separator. |
static List<String> |
split(String text,
char[] separators)
Split a text using multiple separators at once. |
static List<String> |
split(String text,
List<String> separators)
Split a text using multiple separators at once. |
static List<String> |
split(String text,
String separator)
Split a text using a single separator. |
static List<String> |
split(String text,
String[] separators)
Split a text using multiple separators at once. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String OUTPUT_CONSOLE
public static final String OUTPUT_HTML
Method Detail |
---|
public static String backwards(String text)
text
- text to be reversed
String
- Your text flipped backwards.public static String getFillerText(int lineAmount, String output)
lineAmount
- number of lines you wantoutput
- choose one of the OUTPUT_constants to indicate what output format you're using.
- TextMagic.OUTPUT_CONSOLE = "\n\r"
- TextMagic.OUTPUT_HTML = "< br />"
String
- a number of filler lines.public static int getOccurrencesCount(String part, String text, boolean ignoreCase)
String
inside another String
.
part
- the piece of text you want the occurrences count fromtext
- the containing textignoreCase
- false for case sensitive
int
- the amount of occurrences foundpublic static List<Integer> getOccurrences(String part, String text, boolean ignoreCase)
String
inside another String
.
part
- the piece of text you want the occurrences fromtext
- the containing textignoreCase
- false for case sensitive
List
- the indexes of the occurrences foundpublic static List<String> split(String text, char[] separators)
TextMagic.split("a;b-c,d", new char[]{';', '-', ','}) => "a", "b", "c", "d"
TextMagic.split("a;b-c,d", new char[]{';', ','}) => "a", "b-c", "d"
text
- the piece of text you want to splitseparators
- a char array containing all separators
List
- a List
of String
-objects containing all splitted partspublic static List<String> split(String text, String[] separators)
TextMagic.split("a;b-c,d", new String[]{";", "-", ","}) => "a", "b", "c", "d"
TextMagic.split("a;b-c,d", new String[]{";", ","}) => "a", "b-c", "d"
text
- the piece of text you want to splitseparators
- a String array containing all separators
List
- a List
of String
-objects containing all splitted partspublic static List<String> split(String text, List<String> separators)
TextMagic.split("a;b-c,d", list) with list containing ";", "-", "," => "a", "b", "c", "d"
TextMagic.split("a;b-c,d", list) with list containing ";", "," => "a", "b-c", "d"
text
- the piece of text you want to splitseparators
- a List of Strings containing all separators
List
- a List
of String
-objects containing all splitted partspublic static List<String> split(String text, String separator)
TextMagic.split("a;b-c,d", "-") => "a;b", "c,d"
TextMagic.split("a;b-c,d", ";") => "a","b-c,d"
TextMagic.split("a;b-c,d", ";b-c") => "a",",d"
text
- the piece of text you want to splitseparator
- the separator you want to use
List
- a List
of String
-objects containing all splitted partspublic static List<String> split(String text, char separator)
TextMagic.split("a;b-c,d", 'b') => "a;", "-c,d"
text
- the piece of text you want to splitseparator
- the separator you want to use
List
- a List
of String
-objects containing all splitted partspublic static Map<String,Integer> countChars(String text)
TextMagic.countChars("abcdcba") => returns a Map
with a(2), b(2), c(2), d(1)
text
- the text you want to get all the characters and their respective count from
Map
- a Map
with String
as key and Integer
as value containing all characters + their countpublic static String invertUpperCaseLowerCase(String text)
TextMagic.countChars("ABCdef") => "abcDEF"
text
- the text you want to invert
String
- the same text as received through @param text
but invertedpublic static boolean isValid(String value)
String
value is valid, meaning it is not null
and the length > 0.
value
-
boolean
true
if the given String
is valid, false
if notpublic static boolean compare(String s1, String s2, boolean ignoreCase)
if(ignoreCase)
return s1.equalsIgnoreCase(s1);
else
return s1.equals(s2);
s1
- the first strings2
- the second stringignoreCase
- false
if you want a case sensitive comparison,
true
if you don't
boolean
- true
if the string values are equal,
false
if they're not
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |