static <T extends Comparable<T>> void binaryInsert(List<T> list, T value, boolean ascending) {
    
    int position = Collections.binarySearch(list, value, getComparator(ascending, (T)null));
    if (position < 0) {
      position = (-position) - 1; 
    }
    list.add(position, value);
  }
Insert an element into an ascending/descending array, and keep the order. 
@param ascending
           if true, the array is sorted in ascending order,
           otherwise it is in descending order.
contrib/src/java/org/apache/hadoop/hive/contrib/udaf/example/UDAFExampleMaxMinNUtil.java