code: private void trim() {
  
          // Trim
          while (values.size() > limit.getMaxEntries()) {
              values.removeLast();
          }
  
          // Trim according to duration
          if (limit.getMaxDuration() > 0 && !values.isEmpty()) {
              long duration = limit.getMaxDuration();
              long start = values.getFirst().getTimestamp();
              while (start - values.getLast().getTimestamp() > duration) {
                  values.removeLast();
              }
          }
      }
docs: Truncate list so that no more than max entries are stored in the list