import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.function.*;
class Ideone
{
{
StringUtil.indexOf("hello, world", 'l')
.DoIfSuccess(foundIndex -> {
});
}
}
class StringUtil {
public static ResultOfIndexOf indexOf
(String haystack,
char needle
) { for (int i = 0; i < haystack.length(); ++i)
if (haystack.charAt(i) == needle)
return new ResultOfIndexOf(i);
return new ResultOfIndexOf();
}
}
class ResultOfIndexOf {
private final boolean isFound;
private final int foundIndex;
ResultOfIndexOf() {
this(false, 0);
}
ResultOfIndexOf(int foundIndex) {
this(true, foundIndex);
}
private ResultOfIndexOf(boolean isFound, int foundIndex) {
this.isFound = isFound;
this.foundIndex = foundIndex;
}
public void DoIfSuccess(Consumer<Integer> postAction) {
if (isFound && postAction != null)
postAction.accept(foundIndex);
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CmltcG9ydCBqYXZhLnV0aWwuZnVuY3Rpb24uKjsKCmNsYXNzIElkZW9uZQp7CglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbiAoU3RyaW5nW10gYXJncykgdGhyb3dzIGphdmEubGFuZy5FeGNlcHRpb24KCXsKCQlTdHJpbmdVdGlsLmluZGV4T2YoImhlbGxvLCB3b3JsZCIsICdsJykKCQkJLkRvSWZTdWNjZXNzKGZvdW5kSW5kZXggLT4gewoJCQkJU3lzdGVtLm91dC5wcmludGxuKFN0cmluZy5mb3JtYXQoImluZGV4PSVkIiwgZm91bmRJbmRleCkpOwoJCQl9KTsKCX0KfQoKY2xhc3MgU3RyaW5nVXRpbCB7CglwdWJsaWMgc3RhdGljIFJlc3VsdE9mSW5kZXhPZiBpbmRleE9mKFN0cmluZyBoYXlzdGFjaywgY2hhciBuZWVkbGUpIHsKCQlmb3IgKGludCBpID0gMDsgaSA8IGhheXN0YWNrLmxlbmd0aCgpOyArK2kpCgkJCWlmIChoYXlzdGFjay5jaGFyQXQoaSkgPT0gbmVlZGxlKQoJ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