mirror of
https://github.com/shekhargulati/strman-java.git
synced 2026-10-20 14:34:04 +00:00
Fixed #25. Added support for reverse function
This commit is contained in:
@@ -774,6 +774,17 @@ public abstract class Strman {
|
||||
return value.toLowerCase().replace(search.toLowerCase(), newValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the input String
|
||||
*
|
||||
* @param value The input String
|
||||
* @return Reversed String
|
||||
*/
|
||||
public static String reverse(final String value) {
|
||||
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
|
||||
return new StringBuilder(value).reverse().toString();
|
||||
}
|
||||
|
||||
public static String decode(final String value, final int digits, final int radix) {
|
||||
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
|
||||
return Arrays
|
||||
|
||||
@@ -592,4 +592,14 @@ public class StrmanTest {
|
||||
assertThat(replace("FOO bar", "foo", "bar", false), equalTo("bar bar"));
|
||||
assertThat(replace("FOO bar foo", "foo", "bar", false), equalTo("bar bar bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reverse_shouldReverseInputString() throws Exception {
|
||||
assertThat(reverse(""), equalTo(""));
|
||||
assertThat(reverse("foo"), equalTo("oof"));
|
||||
assertThat(reverse("shekhar"), equalTo("rahkehs"));
|
||||
assertThat(reverse("bar"), equalTo("rab"));
|
||||
assertThat(reverse("foo_"), equalTo("_oof"));
|
||||
assertThat(reverse("f"), equalTo("f"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user