CargoBatch cb = (CargoBatch)batches.next();
CargoBatch cb = (CargoBatch)((Entry) batches.next()).getKey();
    private static void transferCargo(int cargoTypeToTransfer,        int amountToTransfer, CargoBundle from, CargoBundle to) {        if (0 == amountToTransfer) {            return;        } else {            Iterator batches = from.cargoBatchIterator();            int amountTransferedSoFar = 0;            while (batches.hasNext() &&                    amountTransferedSoFar < amountToTransfer) {                CargoBatch cb = (CargoBatch)batches.next();                if (cb.getCargoType() == cargoTypeToTransfer) {                    int amount = from.getAmount(cb);                    int amountOfThisBatchToTransfer;                    if (amount < amountToTransfer - amountTransferedSoFar) {                        amountOfThisBatchToTransfer = amount;                        batches.remove();                    } else {                        amountOfThisBatchToTransfer = amountToTransfer -                            amountTransferedSoFar;                        from.addCargo(cb, -amountOfThisBatchToTransfer);                    }                    to.addCargo(cb, amountOfThisBatchToTransfer);                    amountTransferedSoFar += amountOfThisBatchToTransfer;                }            }        }    }