import java.util.*;
/** An immutable List<Double> representing the sequence ax^2 + bx + c */
public class QuadraticSequence extends AbstractList<Double> {
final int size;
final double a, b, c;
QuadraticSequence(double a, double b, double c, int size) {
this.a = a; this.b = b; this.c = c; this.size = size;
}
@Override public int size() { return size; }
@Override public Double get(int index) {
if (index<0 || index>=size) throw new ArrayIndexOutOfBoundsException();
return a*index*index + b*index + c;
}
}
|