org.rx.util.UrlGenerator Maven / Gradle / Ivy
package org.rx.util;
import lombok.NonNull;
import org.rx.core.Strings;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class UrlGenerator implements Iterable {
private final List urls = new ArrayList<>();
@Override
public Iterator iterator() {
return urls.iterator();
}
public UrlGenerator(@NonNull String urlExpression) {
int s = urlExpression.indexOf("["), e;
if (s == -1 || (e = urlExpression.indexOf("]", s)) == -1) {
urls.add(urlExpression);
return;
}
String rangeString = urlExpression.substring(s, e + 1);
String[] ranges = Strings.split(rangeString.substring(1, rangeString.length() - 1), "-", 2);
int f = Integer.parseInt(ranges[0]), t = Integer.parseInt(ranges[1]);
for (; f <= t; f++) {
urls.add(urlExpression.replace(rangeString, String.valueOf(f)));
}
}
}