Source of Utils.java


  1: import java.util.*;

  3: public class Utils
  4: {
  5:    public static <E> void fill(ArrayList<E> a, E value, int count)
  6:    {
  7:       for (int i = 0; i < count; i++)
  8:          a.add(value);
  9:    }

 11:    public static <E, F extends E> void append(ArrayList<E> a, 
 12:          ArrayList<F> b, int count)
 13:    {
 14:       for (int i = 0; i < count && i < b.size(); i++)
 15:          a.add(b.get(i));
 16:    }

 18:    public static <E extends Comparable<? super E>> 
 19:          E getMax(ArrayList<E> a)
 20:    {
 21:       E max = a.get(0);
 22:       for (int i = 1; i < a.size(); i++)
 23:          if (a.get(i).compareTo(max) > 0) max = a.get(i);
 24:       return max;
 25:    }

 27:    public static <E> void fillWithDefaults(ArrayList<E> a, 
 28:          Class<? extends E> cl, int count) 
 29:          throws InstantiationException, IllegalAccessException
 30:    {
 31:       for (int i = 0; i < count; i++)
 32:          a.add(cl.newInstance());
 33:    }
 34: }