No need to initialize instance variable to its default value.
Inline local variable used only once.
Use this in ctor consistently.
Inline internal method.
@@ -44,12 +44,11 @@ public ServiceLoaderIterator(final Class<E> service) {
public ServiceLoaderIterator(final Class<E> service, final ClassLoader classLoader) {
this.service = service;
- final ServiceLoader<E> serviceLoader = ServiceLoader.load(service, classLoader);
- serviceLoaderIterator = serviceLoader.iterator();
- nextServiceLoader = null;
+ this.serviceLoaderIterator = ServiceLoader.load(service, classLoader).iterator();
}
- private boolean getNextServiceLoader() {
+ @Override
+ public boolean hasNext() {
while (nextServiceLoader == null) {
try {
if (!serviceLoaderIterator.hasNext()) {
@@ -68,14 +67,9 @@ private boolean getNextServiceLoader() {
return true;
}
- @Override
- public boolean hasNext() {
- return getNextServiceLoader();
- }
-
@Override
public E next() {
- if (!getNextServiceLoader()) {
+ if (!hasNext()) {
throw new NoSuchElementException("No more elements for service " + service.getName());
}
final E tempNext = nextServiceLoader;
