private void padMetric(String metric, Bucket toPresent, int currentDataPoints) {
        LinkedHashMap<Point, TimeStampedMetric> cachedPoints = getCachedMetric(metric);
        int toAdd = pointsToKeep - currentDataPoints;
        @SuppressWarnings({"unchecked","rawtypes"})
            Entry<Point, TimeStampedMetric>[] cachedEntries = cachedPoints.entrySet().toArray(new Entry[0]);
        long nowMillis = System.currentTimeMillis();
        for (int i = cachedEntries.length - 1; i >= 0 && toAdd > 0; --i) {
            Entry<Point, TimeStampedMetric> leastOld = cachedEntries[i];
            if (leastOld.getValue().millis + MAX_AGE_MILLIS  < nowMillis) {
                continue;
            }
            Identifier id = new Identifier(metric, leastOld.getKey());
            if ( ! toPresent.hasIdentifier(id)) {
                toPresent.put(id, leastOld.getValue().metric.pruneData());
                --toAdd;
            }
        }
    }
The persistence layer for metrics. Both CPU and memory hungry, but
it runs in its own little world.

@author Steinar Knutsen
container-core/src/main/java/com/yahoo/metrics/simple/DimensionCache.java