package js.tools; import java.io.*; import java.util.*; /** * A comparable ArrayList. */ class Packing implements Comparable { Size array[]; int thisSize; // Construct a fully functioning object Packing() { array = new Size[CodePacker.list.size()]; thisSize = 0; } // Add an element if there is room. boolean add(int i) { Size size = (Size)CodePacker.list.get(i); if (size.size + thisSize <= CodePacker.maxSize) { array[i] = size; thisSize += size.size; return true; } return false; } void remove(int i) { if (array[i] != null) { thisSize -= array[i].size; array[i] = null; } } int getSize() { return thisSize; } /** * Pick a cross-over point within the index range. length/2 points before it come * from one array, the other come from the other array until the capacity gets busted. */ Packing breed(Packing other) { int crossOver = (int)(Math.random() * array.length); Packing offspring = new Packing(); for (int i = 0; i