org.daisy.dotify.studio.api.PreviewMaker Maven / Gradle / Ivy
package org.daisy.dotify.studio.api;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.ServiceLoader;
import org.daisy.streamline.api.media.FileDetails;
public class PreviewMaker {
private final List providers;
public PreviewMaker() {
List tmp = new ArrayList<>();
for (PreviewProvider p : ServiceLoader.load(PreviewProvider.class)) {
tmp.add(p);
}
this.providers = Collections.unmodifiableList(tmp);
}
public static PreviewMaker newInstance() {
return new PreviewMaker();
}
public boolean supportsFormat(FileDetails format) {
return providers.stream()
.anyMatch(p->p.supportsFormat(format));
}
public Optional newPreview(FileDetails format) {
return providers.stream()
.filter(p->p.supportsFormat(format))
.findFirst()
.map(p->p.newPreview(format));
}
}