code: public static boolean shouldRetain(int i, int maxRetention, int length) {
      // Files with a zero-based index greater or equal than the retentionCutoff
      // should be retained.
      int retentionCutoff = length - maxRetention;
      boolean retain = (i >= retentionCutoff) ? true : false;
      return retain;
    }
docs: Method that can be used when iterating over an array and you want to retain
  only maxRetention items.
  
  @param i
  index of element in ordered array of length
  @param maxRetention
  total number of elements to retain.
  @param length
  of the ordered array
  @return whether this element should be retained or not.