Simplify and prettify function looking for max value in a list and modifying some underlying values within that list This function is used to modify values in list List&lt;GoogleUsageMapping&gt; and prepare them for entering into billing system.

I'm hoping this function can be more simplified and prettified, logic works.
Function needs to keep track of maxValue and if the maxValue is of type LOGICAL_SIZE. Would love to eliminate one of the for-loop if possible for instance. 

private void checkForOverage(List&lt;GoogleUsageMapping&gt; records) {
    BigDecimal highestQuantity = new BigDecimal(0);
    GoogleUsageMapping recordHighestQuantity = null;
    for (GoogleUsageMapping record : records) {
        if (record.getUsage().getQuantity().compareTo(highestQuantity) &gt; 0) {
            highestQuantity = record.getUsage().getQuantity();
            recordHighestQuantity = record;
        }
    }

    if (recordHighestQuantity.getUsage().getMeasuredType() == MeasuredType.LOGICAL_SIZE) {
        s_logger.info("Overage scenario accord LOGICAL_SIZE: " + recordHighestQuantity.getUsage().getQuantity() + " greater than ALLOCATED_SIZE");
        for (GoogleUsageMapping record : records) {
            if (record.getUsage().getMeasuredType() == MeasuredType.LOGICAL_SIZE) {
                continue;
            }
            record.setState(GoogleTrackingState.IGNORED_OVERAGE);
        }
    }
}


modified version:

private void checkForOverage(List&lt;GoogleUsageMapping&gt; records) {
    GoogleUsageMapping recordUsageHighestQuantity = Collections.max(records, Comparator.comparing(c -&gt; c.getUsage().getQuantity()));

    if (recordUsageHighestQuantity.getUsage().getMeasuredType() == MeasuredType.LOGICAL_SIZE) {
        s_logger.info("Overage scenario accord LOGICAL_SIZE: " + recordUsageHighestQuantity.getUsage().getQuantity() + " greater than ALLOCATED_SIZE");
        for (GoogleUsageMapping record : records) {
            if (record.getUsage().getMeasuredType() == MeasuredType.LOGICAL_SIZE) {
                continue;
            }
            record.setState(GoogleTrackingState.IGNORED_OVERAGE);
        }
    }
}
If you want to get rid of a for-loop just for code clarity, you could use a Stream and the max() function. (Assuming you're using Java 8+). You could also use Streams for the second for-loop.

Note however, it's not logically possible to avoid iterating through the list twice. You have to check every element to get the largest value, and again to set values on every item in the list.

I don't see you using highestQuantity, it's not really necessary since you have a pointer to recordHighestQuantity already.