public static <T>T median(final Comparator<T> comparator,final T... items){
  Validate.notEmpty(items,"null/empty items");
  Validate.noNullElements(items);
  Validate.notNull(comparator,"null comparator");
  final TreeSet<T> sort=new TreeSet<T>(comparator);
  Collections.addAll(sort,items);
  @SuppressWarnings("unchecked") final T result=(T)sort.toArray()[(sort.size() - 1) / 2];
  return result;
}

public static < T > T median ( final Comparator < T > comparator , final T ... items ) { Validate . notEmpty ( items , "null/empty items" ) ; Validate . noNullElements ( items ) ; Validate . notNull ( comparator , "null comparator" ) ; final TreeSet < T > sort = new TreeSet < T > ( comparator ) ; Collections . addAll ( sort , items ) ; @ SuppressWarnings ( "unchecked" ) final T result = ( T ) sort . toArray ( ) [ ( sort . size ( ) - 1 ) / 2 ] ; return result ; }
find the " best guess " middle value among comparables . if there is an even number of total values , the lower of the two middle values will be returned .
