class CollectionUtil {

  public static <R> Collection<R> maxValues(Collection<R> values, Comparator<R> comparator) {
    List<R> maxValues = new ArrayList<>();
    for (R value : values) {
      if (maxValues.isEmpty()) {
        maxValues.add(value);
        continue;
      }
      int cmp = comparator.compare(value, maxValues.get(0));
      if (cmp == 0) {
        maxValues.add(value);
      } else if (cmp > 0) {
        maxValues.clear();
        maxValues.add(value);
      }
    }
    return maxValues;
  }

  private  CollectionUtil();

}