/** * Flush all of the profiles maintained in a cache. * * @param cache The cache to flush. * @return The measurements captured when flushing the profiles. */ private List<ProfileMeasurement> flushCache(Cache<Integer, ProfileBuilder> cache) { List<ProfileMeasurement> measurements = new ArrayList<>(); for(ProfileBuilder profileBuilder: cache.asMap().values()) { // only need to flush, if the profile has been initialized if(profileBuilder.isInitialized()) { // flush the profiler and save the measurement, if one exists Optional<ProfileMeasurement> measurement = profileBuilder.flush(); measurement.ifPresent(m -> measurements.add(m)); } } return measurements; }