Skip to content

Commit

Permalink
call delegate #getService() when looking up single service
Browse files Browse the repository at this point in the history
as classes implementing `ServiceProvider` may define their own
custom behaviour, let the `ServiceProvider` instance itself fetch a single
service by name instead of using an own standard strategy (using the first one
returned by `#getServices(Class)`)

this way it is prevented that a `ServiceProvider` must load all services of the class
even if they are not generellay needed (including all side effects e.g. loading data
from remote services)
  • Loading branch information
theborakompanioni committed Oct 21, 2020
1 parent 9f64034 commit dd4cc06
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/main/java/javax/money/spi/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,14 @@ public static <T> Collection<T> getServices(Class<T> serviceType) {
}

/**
* Delegate method for {@link ServiceProvider#getServices(Class)}.
* Delegate method for {@link ServiceProvider#getService(Class)}.
*
* @param serviceType the service type.
* @return the service found, or {@code null}.
* @see ServiceProvider#getServices(Class)
*/
public static <T> T getService(Class<T> serviceType) {
List<T> services = getServiceProvider().getServices(serviceType);
return services
.stream()
.findFirst()
.orElse(null);
return getServiceProvider().getService(serviceType);
}

}

0 comments on commit dd4cc06

Please sign in to comment.