package com.bbn.bue.common;

import com.google.common.base.Function;
import com.google.common.collect.Ordering;

public final class OrderingUtils {

  private OrderingUtils() {
    throw new UnsupportedOperationException();
  }

  /**
   * Gets a function which maps any iterable to its minimum according to the supplied {@link
   * com.google.common.collect.Ordering}.  If no such minimum exists for an input, it will throw an
   * exception as specified in {@link Ordering#min(Iterable)}.
   */
  public static <T> Function<Iterable<T>, T> minFunction(final Ordering<T> ordering) {
    return new Function<Iterable<T>, T>() {
      @Override
      public T apply(Iterable<T> input) {
        return ordering.min(input);
      }
    };
  }

  /**
   * Gets a function which maps any iterable to its maximum according to the supplied {@link
   * com.google.common.collect.Ordering}.  If no such maximum exists for an input, it will throw an
   * exception as specified in {@link Ordering#max(Iterable)}.
   */
  public static <T> Function<Iterable<T>, T> maxFunction(final Ordering<T> ordering) {
    return new Function<Iterable<T>, T>() {
      @Override
      public T apply(Iterable<T> input) {
        return ordering.max(input);
      }
    };
  }

  /**
   * Orders Ts in some domain by their image under F using the onFunctionResultOrdering
   */
  public static <T,V> Ordering<T> onResultOf(final Function<T, V> F, final Ordering<V> onFunctionResult) {
    return new Ordering<T>() {
      @Override
      public int compare(final T t, final T t1) {
        return onFunctionResult.compare(F.apply(t), F.apply(t1));
      }
    };
  }
}

@@ -1250,397 +1250,7 @@
 %0A  %7D
-%0A%0A  /**%0A   * Orders Ts in some domain by their image under F using the onFunctionResultOrdering%0A   */%0A  public static %3CT,V%3E Ordering%3CT%3E onResultOf(final Function%3CT, V%3E F, final Ordering%3CV%3E onFunctionResult) %7B%0A    return new Ordering%3CT%3E() %7B%0A      @Override%0A      public int compare(final T t, final T t1) %7B%0A        return onFunctionResult.compare(F.apply(t), F.apply(t1));%0A      %7D%0A    %7D;%0A  %7D
 %0A%7D%0A

Revert "add ability to order a domain D by the result of a function F and an Ordering O on the image of F"