currentFoodMatter.mass -= pairedToFlowrateFoodMatter.mass; itemsToReturn.add(pairedToFlowrateFoodMatter);
currentFoodMatter.mass -= paredToFlowrateFoodMatter.mass; itemsToReturn.add(paredToFlowrateFoodMatter);
    public FoodMatter[] takeFoodMatterCalories(float pCalories,            float limitingMass) {        List itemsToReturn = new Vector();        List itemsToRemove = new Vector();        float collectedCalories = 0f;        float collectedMass = 0f;        for (Iterator iter = currentFoodItems.iterator(); iter.hasNext()                && (collectedCalories < pCalories)                && (collectedMass < limitingMass);) {            FoodMatter currentFoodMatter = (FoodMatter) (iter.next());            float currentCalories = calculateCaloriesSingular(currentFoodMatter);            float caloriesStillNeeded = pCalories - collectedCalories;            //Too many calories and too big, need to pair down to flowrate,            // then pair down to needed calories            if (((currentCalories > caloriesStillNeeded) || (collectedMass + currentFoodMatter.mass) > limitingMass)) {                //pair it to mass                float flowRateMass = limitingMass - collectedMass;                float flowrateFractionOfOriginal = flowRateMass                        / currentFoodMatter.mass;                FoodMatter pairedToFlowrateFoodMatter = new FoodMatter(                        limitingMass - collectedMass,                        currentFoodMatter.waterContent                                * flowrateFractionOfOriginal,                        currentFoodMatter.type);                float pairedToFlowrateCalories = calculateCaloriesSingular(pairedToFlowrateFoodMatter);                //pair it to calories                float fractionOfMassToKeep = (pairedToFlowrateCalories - caloriesStillNeeded)                        / pairedToFlowrateCalories;                float pairedToCaloriesMassToKeep = pairedToFlowrateFoodMatter.mass                        * fractionOfMassToKeep;                float massToReturn = pairedToFlowrateFoodMatter.mass                        - pairedToCaloriesMassToKeep;                float caloriesFractionOfOriginal = massToReturn                        / pairedToFlowrateFoodMatter.mass;                float waterToReturn = caloriesFractionOfOriginal                        * pairedToFlowrateFoodMatter.waterContent;                currentFoodMatter.mass = currentFoodMatter.mass - massToReturn;                currentFoodMatter.waterContent = currentFoodMatter.waterContent                        - waterToReturn;                FoodMatter partialReturnedFoodMatter = new FoodMatter(                        massToReturn, waterToReturn, currentFoodMatter.type);                itemsToReturn.add(partialReturnedFoodMatter);                if (currentFoodMatter.mass <= 0)                    itemsToRemove.add(currentFoodMatter);                collectedMass += partialReturnedFoodMatter.mass;                collectedCalories = pCalories;            }            //Not enough calories and too big. Pair down to flowrate            else if (((collectedMass + currentFoodMatter.mass) > limitingMass)                    && (currentCalories <= caloriesStillNeeded)) {                float flowRateMass = limitingMass - collectedMass;                float flowrateFractionOfOriginal = flowRateMass                        / currentFoodMatter.mass;                FoodMatter pairedToFlowrateFoodMatter = new FoodMatter(                        limitingMass - collectedMass,                        currentFoodMatter.waterContent                                * flowrateFractionOfOriginal,                        currentFoodMatter.type);                currentFoodMatter.mass -= pairedToFlowrateFoodMatter.mass;                itemsToReturn.add(pairedToFlowrateFoodMatter);                if (currentFoodMatter.mass <= 0)                    itemsToRemove.add(currentFoodMatter);                collectedMass += pairedToFlowrateFoodMatter.mass;                collectedCalories = calculateCaloriesSingular(pairedToFlowrateFoodMatter);            }            //Too many calories and small. Pair down to calories            else if (((collectedMass + currentFoodMatter.mass) <= limitingMass)                    && (currentCalories > caloriesStillNeeded)) {                float fractionOfMassToKeep = (currentCalories - caloriesStillNeeded)                        / currentCalories;                float massToKeep = currentFoodMatter.mass                        * fractionOfMassToKeep;                float massToReturn = currentFoodMatter.mass - massToKeep;                currentFoodMatter.mass = massToKeep;                FoodMatter partialReturnedFoodMatter = new FoodMatter(                        massToReturn, currentFoodMatter.waterContent                                * fractionOfMassToKeep, currentFoodMatter.type);                itemsToReturn.add(partialReturnedFoodMatter);                if (currentFoodMatter.mass <= 0)                    itemsToRemove.add(currentFoodMatter);                collectedMass += partialReturnedFoodMatter.mass;                collectedCalories = pCalories;            }            //Too little calories and small. Just add            else {                itemsToReturn.add(currentFoodMatter);                itemsToRemove.add(currentFoodMatter);                collectedCalories += currentCalories;                collectedMass += currentFoodMatter.mass;            }        }        //Remove items from List        for (Iterator iter = itemsToRemove.iterator(); iter.hasNext();) {            currentFoodItems.remove(iter.next());        }        currentLevel -= collectedMass;        //return the array        FoodMatter[] returnArray = new FoodMatter[0];        returnArray = (FoodMatter[]) (itemsToReturn.toArray(returnArray));        return returnArray;    }