Use optionals for get by name and namespace

This commit is contained in:
René Pfeuffer
2018-07-11 13:42:09 +02:00
parent de3848b662
commit 617b98c6f3
5 changed files with 31 additions and 22 deletions

View File

@@ -41,6 +41,7 @@ import sonia.scm.TypeManager;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Collection;
import java.util.Optional;
//~--- JDK imports ------------------------------------------------------------
@@ -148,11 +149,10 @@ public interface RepositoryManager
@Override
public RepositoryHandler getHandler(String type);
default Repository getByNamespace(String namespace, String name) {
default Optional<Repository> getByNamespace(String namespace, String name) {
return getAll()
.stream()
.filter(r -> r.getName().equals(name) && r.getNamespace().equals(namespace))
.findFirst()
.orElse(null);
.findFirst();
}
}