eu.bitwalker.useragentutils.version.fetcher.SequentialVersionFetcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of user-agent-utils Show documentation
Show all versions of user-agent-utils Show documentation
Utility classes to handle user-agents.
The newest version!
package eu.bitwalker.useragentutils.version.fetcher;
import eu.bitwalker.useragentutils.Version;
/**
* Implementation of {@link VersionFetcher} that holds a list of other {@link VersionFetcher}
* and calls them sequentially until any of them manages to find version.
*
* @author alexr
*/
public class SequentialVersionFetcher implements VersionFetcher {
private final VersionFetcher[] fetchers;
public SequentialVersionFetcher(VersionFetcher first, VersionFetcher... others) {
fetchers = new VersionFetcher[others.length + 1];
fetchers[0] = first;
System.arraycopy(others, 0, fetchers, 1, others.length);
}
@Override
public Version version(String str) {
for (VersionFetcher fetcher : fetchers) {
Version version = fetcher.version(str);
if (version != null) return version;
}
return null;
}
}