mirror of
https://github.com/shekhargulati/strman-java.git
synced 2026-11-03 00:13:47 +00:00
@@ -624,6 +624,36 @@ public abstract class Strman {
|
|||||||
return value.length();
|
return value.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a new String starting with prepends
|
||||||
|
*
|
||||||
|
* @param value The input String
|
||||||
|
* @param prepends Strings to prepend
|
||||||
|
* @return The prepended String
|
||||||
|
*/
|
||||||
|
public static String prepend(final String value, final String... prepends) {
|
||||||
|
return prependArray(value, prepends);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a new String starting with prepends
|
||||||
|
*
|
||||||
|
* @param value The input String
|
||||||
|
* @param prepends Strings to prepend
|
||||||
|
* @return The prepended String
|
||||||
|
*/
|
||||||
|
public static String prependArray(final String value, final String[] prepends) {
|
||||||
|
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
|
||||||
|
if (prepends == null || prepends.length == 0) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
StringJoiner joiner = new StringJoiner("");
|
||||||
|
for (String prepend : prepends) {
|
||||||
|
joiner.add(prepend);
|
||||||
|
}
|
||||||
|
return joiner.toString() + value;
|
||||||
|
}
|
||||||
|
|
||||||
public static String decode(final String value, final int digits, final int radix) {
|
public static String decode(final String value, final int digits, final int radix) {
|
||||||
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
|
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
|
||||||
return Arrays
|
return Arrays
|
||||||
|
|||||||
@@ -481,4 +481,21 @@ public class StrmanTest {
|
|||||||
assertThat(leftTrim(" strman"), equalTo("strman"));
|
assertThat(leftTrim(" strman"), equalTo("strman"));
|
||||||
assertThat(leftTrim(" strman "), equalTo("strman "));
|
assertThat(leftTrim(" strman "), equalTo("strman "));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void prepend_shouldPrependStrings() throws Exception {
|
||||||
|
assertThat(prepend("r", "f", "o", "o", "b", "a"), equalTo("foobar"));
|
||||||
|
assertThat(prepend("foobar"), equalTo("foobar"));
|
||||||
|
assertThat(prepend("", "foobar"), equalTo("foobar"));
|
||||||
|
assertThat(prepend("bar", "foo"), equalTo("foobar"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void prependArray_shouldPrependStrings() throws Exception {
|
||||||
|
assertThat(prependArray("r", new String[]{"f", "o", "o", "b", "a"}), equalTo("foobar"));
|
||||||
|
assertThat(prependArray("foobar", new String[0]), equalTo("foobar"));
|
||||||
|
assertThat(prependArray("", new String[]{"foobar"}), equalTo("foobar"));
|
||||||
|
assertThat(prependArray("bar", new String[]{"foo"}), equalTo("foobar"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user