
jedi.functional.Range Maven / Gradle / Ivy
The newest version!
package jedi.functional;
import jedi.filters.AllPassFilter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Represents a range of ints, with a possible filter.
* Instances of this class are {@link Serializable} if the given filter is {@link Serializable}.
*/
public class Range implements Iterable, Serializable {
private static final long serialVersionUID = 1L;
private final int start;
private final int end;
private final Filter filter;
public static Range range(int start, int end) {
return new Range(start, end);
}
public Range(int start, int end) {
this(start, end, new AllPassFilter());
}
public Range(int start, int end, Filter filter) {
this.start = start;
this.end = end;
this.filter = filter;
}
public Iterator iterator() {
List items = new ArrayList();
for (int i = start; i < end; i++) {
if (filter.execute(i)) items.add(i);
}
return items.iterator();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy