Resolved#71

This commit is contained in:
Shekhar Gulati
2016-08-24 12:11:04 +05:30
parent f282dddca3
commit 21f8bb9f8e
2 changed files with 47 additions and 3 deletions
+31
View File
@@ -1164,6 +1164,37 @@ public abstract class Strman {
return head(input).toLowerCase() + tail(input);
}
/**
* Verifies whether String is enclosed by encloser
*
* @param input The input String
* @param encloser String which encloses input String
* @return true if enclosed false otherwise
*/
public static boolean isEnclosedBetween(final String input, final String encloser) {
return isEnclosedBetween(input, encloser, encloser);
}
/**
* Verifies whether String is enclosed by encloser
*
* @param input The input String
* @param leftEncloser String which encloses input String
* @return true if enclosed false otherwise
*/
public static boolean isEnclosedBetween(final String input, final String leftEncloser, String rightEncloser) {
if (input == null) {
throw new IllegalArgumentException("input can't be null");
}
if (leftEncloser == null) {
throw new IllegalArgumentException("leftEncloser can't be null");
}
if (rightEncloser == null) {
throw new IllegalArgumentException("rightEncloser can't be null");
}
return input.startsWith(leftEncloser) && input.endsWith(rightEncloser);
}
private static void validate(String value, Predicate<String> predicate, final Supplier<String> supplier) {
if (predicate.test(value)) {
throw new IllegalArgumentException(supplier.get());