paredToCaloriesMassToKeep = currentFoodMatter.mass
paredToCaloriesMassToKeep = paredToFlowrateFoodMatter.mass
    public FoodMatter[] takeFoodMatterCalories(float pCalories,            float limitingMass) {        List<FoodMatter> itemsToReturn = new Vector<FoodMatter>();        List<FoodMatter> itemsToRemove = new Vector<FoodMatter>();        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 or too big, need to pare down to flowrate            // or pare down to needed calories            if (((currentCalories > caloriesStillNeeded) || (collectedMass + currentFoodMatter.mass) > limitingMass)) {                float paredToFlowrateCalories = currentCalories;                FoodMatter paredToFlowrateFoodMatter = cloneMatter(currentFoodMatter);                //pare it to mass if necessary                if (currentFoodMatter.mass > limitingMass) {                    float flowRateMass = limitingMass - collectedMass;                    float flowrateFractionOfOriginal = flowRateMass                            / currentFoodMatter.mass;                    paredToFlowrateFoodMatter = new FoodMatter(limitingMass                            - collectedMass, currentFoodMatter.waterContent                            * flowrateFractionOfOriginal,                            currentFoodMatter.type);                    paredToFlowrateCalories = calculateCaloriesSingular(paredToFlowrateFoodMatter);                }                                float paredToCaloriesMassToKeep = paredToFlowrateFoodMatter.mass;                //pare it to calories if necessary                if (paredToFlowrateCalories > caloriesStillNeeded){                    float fractionOfMassToKeepForCalories = (paredToFlowrateCalories - caloriesStillNeeded)                        / paredToFlowrateCalories;                    paredToCaloriesMassToKeep = currentFoodMatter.mass                        * fractionOfMassToKeepForCalories;                }                                float massToReturn = paredToFlowrateFoodMatter.mass                        - paredToCaloriesMassToKeep;                float caloriesFractionOfOriginal = massToReturn                        / paredToFlowrateFoodMatter.mass;                float waterToReturn = caloriesFractionOfOriginal                        * paredToFlowrateFoodMatter.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 paredToFlowrateFoodMatter = new FoodMatter(                        limitingMass - collectedMass,                        currentFoodMatter.waterContent                                * flowrateFractionOfOriginal,                        currentFoodMatter.type);                currentFoodMatter.mass -= paredToFlowrateFoodMatter.mass;                itemsToReturn.add(paredToFlowrateFoodMatter);                if (currentFoodMatter.mass <= 0)                    itemsToRemove.add(currentFoodMatter);                collectedMass += paredToFlowrateFoodMatter.mass;                collectedCalories = calculateCaloriesSingular(paredToFlowrateFoodMatter);            }            //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 = (itemsToReturn.toArray(returnArray));        return returnArray;    }