| Constructor and Description |
|---|
Str(char ch)
Creates a new string from the character, and wraps that string.
|
Str(java.lang.String string)
Wraps the given string.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.Character |
charAt(int index)
Returns the character at the given index, or null if
index is out of range. |
java.lang.String |
chomp()
Removes a single end of line character, either \\n or \\r.
|
java.lang.String |
chompAll()
Removes multiple end of line characters, either \\n or \\r.
|
int |
compareTo(Str other)
Compares the two objects, including testing for null.
|
boolean |
contains(java.lang.Character ch)
Returns whether the string contains the character.
|
boolean |
endsWith(char ch)
Returns whether the wrapped string ends with the character
ch. |
boolean |
endsWith(java.lang.String str)
Returns whether the wrapped string ends with the string
str. |
java.lang.Boolean |
eq(java.lang.String other)
Returns whether the wrapped string is equal to the other.
|
java.lang.Boolean |
eqi(java.lang.String other)
Returns whether the wrapped string is equal to the other, without regard to case.
|
boolean |
equals(java.lang.Object obj)
Returns whether the given string is equal to this one.
|
boolean |
equals(java.lang.String other)
Returns whether the given string is equal to this one.
|
java.lang.Character |
first()
Returns the first character in the string, or null if the string is null or empty.
|
java.lang.Character |
get(int index)
An alias for Str#charAt.
|
java.lang.String |
get(java.lang.Integer fromIndex,
java.lang.Integer toIndex)
Same as
String#substring, but with the indices inclusive, like the Ruby syntax
str[4 .. |
protected java.lang.Integer |
getIndex(java.lang.Integer index)
Converts the index, which can be positive or negative, to one within range for this string.
|
java.lang.String |
getString()
Returns the wrapped string.
|
boolean |
gt(Str other)
Returns whether the wrapped string is greater than that of the other.
|
boolean |
gte(Str other)
Returns whether the wrapped string is greater than or equal to that of the other.
|
int |
hashCode()
Returns the hash code of the wrapped object.
|
java.lang.Integer |
indexOf(java.lang.Character ch)
Returns the index of the first occurance of the character in the string, or null if either
str or ch is null, or if the character is not in the string. |
boolean |
isEmpty()
Returns whether the wrapped string is null or of zero length.
|
static Str |
join(java.util.Collection<?> coll,
java.lang.String delim)
Creates a string from the collection, joined by
delim. |
static Str |
join(java.lang.Object[] ary,
java.lang.String delim)
Creates a string from the array, joined by
delim. |
java.lang.Character |
last()
Returns the first character in the string, or null if the string is null or empty.
|
java.lang.String |
left(int num)
Returns the leftmost
num characters of the string, not exceeding the length of
the string. |
int |
length()
Returns the length of the string, returning 0 if the wrapped string is null.
|
boolean |
lt(Str other)
Returns whether the wrapped string is less than that of the other.
|
boolean |
lte(Str other)
Returns whether the wrapped string is less than or equal to that of the other.
|
java.lang.String |
pad(char ch,
int length)
Returns a string starting with the
str parameter, with ch's
following the string to a length of length. |
java.lang.String |
pad(int length)
Pads with spaces.
|
java.lang.String |
padLeft(char ch,
int length)
Same as the
pad method, but applies the padding to the left-hand (leading) side
of the string. |
java.lang.String |
padLeft(int length)
Left-pads with spaces.
|
java.lang.String |
quote()
Quotes the string, using double quotes.
|
java.lang.String |
repeat(char ch,
int length)
Returns the character, repeated
num times. |
java.lang.String |
repeat(int num)
Returns the string, repeated
num times. |
java.lang.String |
right(int num)
Returns the rightmost
num characters of the string, not exceeding the length of
the string. |
java.lang.String |
snip(int len)
If
str is longer than length, then the returned string is cut at
the given length - 1, and appended with a dash, so snip("foobar", 4) is "foo-. |
java.lang.String[] |
split(char delim)
Returns an array of strings split at the character delimiter.
|
java.lang.String[] |
split(char delim,
int max)
Returns an array of strings split at the character delimiter.
|
java.lang.String[] |
split(java.lang.String delim)
Returns an array of strings split at the string delimiter.
|
java.lang.String[] |
split(java.lang.String delim,
int max)
Returns an array of strings split at the string delimiter.
|
boolean |
startsWith(char ch)
Returns whether the string
str begins with the character ch. |
boolean |
startsWith(java.lang.String str)
Returns whether the wrapped string begins with the string
str. |
java.lang.String |
str()
Returns the wrapped string.
|
java.lang.String |
substring(java.lang.Integer fromIndex,
java.lang.Integer toIndex)
Returns a substring from the string, with negatives indices applying to the distance from the
end of the string.
|
java.lang.String |
substringAfter(java.lang.Character ch)
Returns the substring from the
ch character to the end of the string. |
java.lang.String |
substringBefore(java.lang.Character ch)
Returns the substring before the
ch character. |
java.util.List<java.lang.String> |
toList()
Converts the string into a list, delimited by whitespace and commas.
|
java.lang.String |
unquote()
Unquotes the string, removing matching leading and trailing single or double quotes, if both
of either type wraps the string.
|
public Str(java.lang.String string)
public Str(char ch)
public static Str join(java.util.Collection<?> coll, java.lang.String delim)
delim. If coll is
null, then the wrapped string is null. If delim is null, it is treated as the
empty string.public static Str join(java.lang.Object[] ary, java.lang.String delim)
delim. If ary is null,
then the wrapped string is null. If delim is null, it is treated as the empty
string.public java.lang.String getString()
public java.lang.String str()
public boolean equals(java.lang.String other)
public boolean equals(java.lang.Object obj)
public java.lang.String[] split(char delim,
int max)
str is null.public java.lang.String[] split(java.lang.String delim,
int max)
str
is null.public java.lang.String[] split(char delim)
str is null.public java.lang.String[] split(java.lang.String delim)
str
is null.public java.util.List<java.lang.String> toList()
public java.lang.String pad(char ch,
int length)
str parameter, with ch's
following the string to a length of length.
Examples:
pad("abcd", '*', 8) -> "abcd****"
pad("abcd", '*', 3) -> "abcd"public java.lang.String padLeft(char ch,
int length)
pad method, but applies the padding to the left-hand (leading) side
of the string.
Examples:
pad("420", '*', 8) -> "*****420"
pad("1144", '*', 3) -> "1144"
public java.lang.String pad(int length)
public java.lang.String padLeft(int length)
public java.lang.String repeat(int num)
num times.public java.lang.String repeat(char ch,
int length)
num times.public java.lang.String left(int num)
num characters of the string, not exceeding the length of
the string. Unlike String#substring, does not throw the annoying IndexOutOfBoundsException.
Returns null if the input string is null. Returns an empty string if num is
negative.public java.lang.String right(int num)
num characters of the string, not exceeding the length of
the string. Unlike String#substring, does not throw the annoying IndexOutOfBoundsException.
Returns null if the wrapped string is null. Returns an empty string if num is
negative.public java.lang.Character charAt(int index)
index is out of range. If
index is negative, the character is the nth character from the end of the
string, where -1 is the last character in the string. If the wrapped string is null, then
null is returned.index - The index into the source string. Negative value goes from end backward.public java.lang.Character get(int index)
charAt(int)public java.lang.String substring(java.lang.Integer fromIndex,
java.lang.Integer toIndex)
fromIndex is null, the substring begins with the first
character. If toIndex is null, the substring ends with the last character. If
the indices are out of bounds, they will be restricted to the size of the string. The range
is inclusive: "foobar"[2 .. 4] == "oba", which is unlike the JDK
String#substring behavior, where the equivalent would be str.substring(2, 5).
If str is null, then null is returned.get(Integer, Integer)public java.lang.String substringAfter(java.lang.Character ch)
ch character to the end of the string. If the
string does not contain the given character, or if str or ch is
null, then null is returned. If ch is the last character, then an empty string
is returned.public java.lang.String substringBefore(java.lang.Character ch)
ch character. If the string does not contain
the given character, , or if str or ch is null, then null is
returned. If ch is the first character, then an empty string is returned.public java.lang.String get(java.lang.Integer fromIndex,
java.lang.Integer toIndex)
String#substring, but with the indices inclusive, like the Ruby syntax
str[4 .. 8]. This method the same as Str.substring.protected java.lang.Integer getIndex(java.lang.Integer index)
public boolean startsWith(char ch)
str begins with the character ch.
Returns false if the wrapped string is null.public boolean startsWith(java.lang.String str)
str. For
consistency with String. Returns false if the wrapped string is null.public boolean endsWith(char ch)
ch.
Returns false if the wrapped string is null.public boolean endsWith(java.lang.String str)
str. For
consistency with String. Returns false if the wrapped string is null.public java.lang.String chomp()
chompAll()public java.lang.String chompAll()
chomp()public boolean contains(java.lang.Character ch)
str or
ch is null, false is returned.public java.lang.Integer indexOf(java.lang.Character ch)
str or ch is null, or if the character is not in the string.public java.lang.Boolean eq(java.lang.String other)
public java.lang.Boolean eqi(java.lang.String other)
public java.lang.String snip(int len)
str is longer than length, then the returned string is cut at
the given length - 1, and appended with a dash, so snip("foobar", 4) is "foo-.
Returns null if str is null. Returns an empty string if length is
zero or less.public boolean isEmpty()
isEmpty in interface BoolisEmpty in class Obj<java.lang.String>Obj.isEmpty(),
Obj.isFalse()public int length()
public java.lang.String unquote()
public java.lang.String quote()
public int compareTo(Str other)
Comparingpublic int hashCode()
Objpublic boolean lt(Str other)
public boolean lte(Str other)
public boolean gt(Str other)
public boolean gte(Str other)
public java.lang.Character first()
public java.lang.Character last()