[Minor] Move RootElementSearchResult.toSingleton() to super class SearchResult

This commit is contained in:
Robert von Burg 2018-12-04 11:17:45 +01:00
parent 22883faa0d
commit 55b762f2f1
2 changed files with 15 additions and 13 deletions

View File

@ -103,19 +103,6 @@ public class RootElementSearchResult<T extends StrolchRootElement> extends Searc
return this;
}
/**
* Returns the single element in the stream, or throws an {@link IllegalStateException} if the stream does not
* contain 1 and only 1 element
*
* @return the single element in the stream
*
* @throws IllegalStateException
* if not 1 and only 1 element is in the stream
*/
public T toSingleton(Supplier<String> errorMsgSupplier) throws IllegalStateException {
return this.stream.collect(CollectionsHelper.singletonCollector(errorMsgSupplier));
}
/**
* Transforms this search result to be a search result returning elements with the given visitor
*

View File

@ -7,9 +7,11 @@ import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import li.strolch.utils.collections.CollectionsHelper;
import li.strolch.utils.collections.Paging;
/**
@ -133,6 +135,19 @@ public class SearchResult<T> {
return Paging.asPage(this.stream.collect(Collectors.toList()), offset, limit);
}
/**
* Returns the single element in the stream, or throws an {@link IllegalStateException} if the stream does not
* contain 1 and only 1 element
*
* @return the single element in the stream
*
* @throws IllegalStateException
* if not 1 and only 1 element is in the stream
*/
public T toSingleton(Supplier<String> errorMsgSupplier) throws IllegalStateException {
return this.stream.collect(CollectionsHelper.singletonCollector(errorMsgSupplier));
}
/**
* Performs a simple for each on every element
*