[Minor] Move RootElementSearchResult.toSingleton() to super class SearchResult
This commit is contained in:
parent
22883faa0d
commit
55b762f2f1
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue