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

public static < T extends Comparable < ? super T > > T median ( final T ... items ) { Validate . notEmpty ( items ) ; Validate . noNullElements ( items ) ; final TreeSet < T > sort = new TreeSet < T > ( ) ; 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 .
