This commit is contained in:
mattbradburyr3 2023-01-29 17:23:49 +00:00
parent f1cf6e13aa
commit 1fb18290ca

View File

@ -6,18 +6,18 @@ import java.util.List;
import java.util.concurrent.Callable;
import java.util.function.Predicate;
import java.util.stream.Collectors;
//
//public final class CorDappHelpers {
// public static <T> T findAndExpectExactlyOne(Collection<T> collection, Predicate<? super T> filterFn, String exceptionMsg)
// {
// Collection<T> results = collection.stream().filter(filterFn).collect(Collectors.toList());
// if(results.size() != 1){
// throw new RuntimeException(exceptionMsg);
// }
// return results.iterator().next();
// }
//
// public static <T> T findAndExpectExactlyOne(Collection<T> collection, String exceptionMsg) {
// return findAndExpectExactlyOne(collection, e -> true, exceptionMsg);
// }
//}
public final class CorDappHelpers {
public static <T> T findAndExpectExactlyOne(Collection<T> collection, Predicate<? super T> filterFn, String exceptionMsg)
{
Collection<T> results = collection.stream().filter(filterFn).collect(Collectors.toList());
if(results.size() != 1){
throw new RuntimeException(exceptionMsg);
}
return results.iterator().next();
}
public static <T> T findAndExpectExactlyOne(Collection<T> collection, String exceptionMsg) {
return findAndExpectExactlyOne(collection, e -> true, exceptionMsg);
}
}