![JAR search and dependency download from the Maven repository](/logo.png)
sdmxdl.file.spi.SdmxFileReaderLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdmx-dl-api Show documentation
Show all versions of sdmx-dl-api Show documentation
Easily download official statistics - API
package sdmxdl.file.spi;
import java.lang.Iterable;
import java.lang.Long;
import java.lang.Override;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
/**
* Custom service loader for {@link sdmxdl.file.spi.SdmxFileReader}.
*
This class is thread-safe.
* Properties:
*
* - Quantifier: MULTIPLE
* - Fallback: null
* - Preprocessing: null
* - Mutability: NONE
* - Singleton: false
* - Name: null
* - Backend: null
* - Cleaner: null
*
*/
public final class SdmxFileReaderLoader {
private final Iterable source = ServiceLoader.load(SdmxFileReader.class);
private final List resource = doLoad();
private Spliterator spliterator() {
return new Spliterators.AbstractSpliterator(Long.MAX_VALUE, 0) {
final Iterator delegate = source.iterator();
@Override
public boolean tryAdvance(Consumer super SdmxFileReader> action) {
if (delegate.hasNext()) {
action.accept((SdmxFileReader) delegate.next());
return true;
}
return false;
}
};
}
private List doLoad() {
return StreamSupport.stream(spliterator(), false)
.collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
}
/**
* Gets a list of {@link sdmxdl.file.spi.SdmxFileReader} instances.
*
This method is thread-safe.
* @return the current non-null value
*/
public List get() {
return resource;
}
/**
* Gets a list of {@link sdmxdl.file.spi.SdmxFileReader} instances.
*
This is equivalent to the following code: new SdmxFileReaderLoader().get()
*
Therefore, the returned value might be different at each call.
*
This method is thread-safe.
* @return a non-null value
*/
public static List load() {
return new SdmxFileReaderLoader().get();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy