mirror of
https://github.com/shekhargulati/strman-java.git
synced 2026-10-15 11:14:04 +00:00
@@ -1117,7 +1117,7 @@ public abstract class Strman {
|
||||
* @param separator The separator to use
|
||||
* @return Concatenated String
|
||||
*/
|
||||
public static String join(final String[] strings, final String separator) {
|
||||
public static String join(final String[] strings, final String separator) throws IllegalArgumentException {
|
||||
if (strings == null) {
|
||||
throw new IllegalArgumentException("Input array 'strings' can't be null");
|
||||
}
|
||||
@@ -1131,6 +1131,39 @@ public abstract class Strman {
|
||||
return joiner.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the first character of string to upper case and the remaining to lower case.
|
||||
*
|
||||
* @param input The string to capitalize
|
||||
* @return The capitalized string
|
||||
*/
|
||||
public static String capitalize(final String input) throws IllegalArgumentException {
|
||||
if (input == null) {
|
||||
throw new IllegalArgumentException("input can't be null");
|
||||
}
|
||||
if (input.length() == 0) {
|
||||
return "";
|
||||
}
|
||||
return head(input).toUpperCase() + tail(input).toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the first character of string to lower case.
|
||||
*
|
||||
* @param input The string to convert
|
||||
* @return The converted string
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public static String lowerFirst(final String input) throws IllegalArgumentException {
|
||||
if (input == null) {
|
||||
throw new IllegalArgumentException("input can't be null");
|
||||
}
|
||||
if (input.length() == 0) {
|
||||
return "";
|
||||
}
|
||||
return head(input).toLowerCase() + tail(input);
|
||||
}
|
||||
|
||||
private static void validate(String value, Predicate<String> predicate, final Supplier<String> supplier) {
|
||||
if (predicate.test(value)) {
|
||||
throw new IllegalArgumentException(supplier.get());
|
||||
|
||||
@@ -912,4 +912,21 @@ public class StrmanTest {
|
||||
String[] emptyArray = {};
|
||||
assertThat(join(emptyArray, ","), is(equalTo("")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void capitalize_shouldCapitalizeFirstCharacterOfString() throws Exception {
|
||||
String[] strings = {
|
||||
"FRED",
|
||||
"fRED",
|
||||
"fred"
|
||||
};
|
||||
Arrays.stream(strings).forEach(el -> assertThat(String.format("%s should be Fred", el), capitalize(el), equalTo("Fred")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lowerFirst_shouldLowercasedFirstCharacterOfString() throws Exception {
|
||||
assertThat(lowerFirst("FRED"),is(equalTo("fRED")));
|
||||
assertThat(lowerFirst("fred"),is(equalTo("fred")));
|
||||
assertThat(lowerFirst("Fred"),is(equalTo("fred")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user