mirror of
https://github.com/shekhargulati/strman-java.git
synced 2026-10-20 14:34:04 +00:00
Fixed #23. Added support for repeat function
This commit is contained in:
@@ -744,6 +744,18 @@ public abstract class Strman {
|
||||
return value.replaceAll("\\s", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a repeated string given a multiplier.
|
||||
*
|
||||
* @param value The input String
|
||||
* @param multiplier Number of repeats
|
||||
* @return The String repeated
|
||||
*/
|
||||
public static String repeat(final String value, final int multiplier) {
|
||||
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
|
||||
return Stream.generate(() -> value).limit(multiplier).collect(joining());
|
||||
}
|
||||
|
||||
public static String decode(final String value, final int digits, final int radix) {
|
||||
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
|
||||
return Arrays
|
||||
|
||||
@@ -571,4 +571,13 @@ public class StrmanTest {
|
||||
};
|
||||
Arrays.stream(fixture).forEach(el -> assertThat(removeSpaces(el), equalTo("foobar")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repeat_shouldRepeatAStringNTimes() throws Exception {
|
||||
assertThat(repeat("1", 1), equalTo("1"));
|
||||
assertThat(repeat("1", 2), equalTo("11"));
|
||||
assertThat(repeat("1", 3), equalTo("111"));
|
||||
assertThat(repeat("1", 4), equalTo("1111"));
|
||||
assertThat(repeat("1", 5), equalTo("11111"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user