import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.Shape;
import java.util.ArrayList;
import java.util.GregorianCalendar;
public class UtilsTester {
public static void main(String[] args) throws InstantiationException,
IllegalAccessException {
ArrayList ids = new ArrayList();
Utils.fill(ids, "default", 10);
System.out.println(ids);
ArrayList shapes = new ArrayList();
Utils.fill(shapes, new Rectangle(5, 10, 20, 30), 2);
System.out.println(shapes);
ArrayList polys = new ArrayList();
Utils.fillWithDefaults(polys, Polygon.class, 10);
Utils.append(shapes, polys, 2);
System.out.println(shapes);
ArrayList dates = new ArrayList();
Utils.fillWithDefaults(dates, GregorianCalendar.class, 5);
System.out.println(Utils.getMax(dates));
}
}
class Utils {
public static void fill(ArrayList a, E value, int count) {
for (int i = 0; i < count; i++)
a.add(value);
}
public static void append(ArrayList a, ArrayList b,
int count) {
for (int i = 0; i < count && i < b.size(); i++)
a.add(b.get(i));
}
public static > E getMax(ArrayList a) {
E max = a.get(0);
for (int i = 1; i < a.size(); i++)
if (a.get(i).compareTo(max) > 0)
max = a.get(i);
return max;
}
public static void fillWithDefaults(ArrayList a,
Class extends E> cl, int count) throws InstantiationException,
IllegalAccessException {
for (int i = 0; i < count; i++)
a.add(cl.newInstance());
}
}