diff --git a/java/connector-framework/src/main/java/org/identityconnectors/common/StringUtil.java b/java/connector-framework/src/main/java/org/identityconnectors/common/StringUtil.java index b9f56c13..a0d8fe43 100644 --- a/java/connector-framework/src/main/java/org/identityconnectors/common/StringUtil.java +++ b/java/connector-framework/src/main/java/org/identityconnectors/common/StringUtil.java @@ -28,9 +28,11 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Objects; import java.util.Properties; import java.util.Random; import java.util.regex.Matcher; +import java.util.stream.Stream; /** * String Utilities. @@ -612,4 +614,22 @@ public static String join(final Object[] array, final char separator, final int } return buf.toString(); } + + public static boolean allNotNull(final Object... values) { + return values != null && Stream.of(values).noneMatch(Objects::isNull); + } + + public static String substringBetween(final String str, final String open, final String close) { + if (!allNotNull(str, open, close)) { + return null; + } + final int start = str.indexOf(open); + if (start != -1) { + final int end = str.indexOf(close, start + open.length()); + if (end != -1) { + return str.substring(start + open.length(), end); + } + } + return null; + } }