class ArraySort {

  @Udf
  public <T extends Comparable<? super T>> List<T> arraySortWithDirection(@UdfParameter(
      description = "The array to sort") final List<T> input,
      @UdfParameter(
          description = "Marks the end of the series (inclusive)") final String direction) {
    if (input == null) {
      return null;
    }
    if (SORT_DIRECTION_ASC.contains(direction.toUpperCase())) {
      input.sort(nullsLast(naturalOrder()));
    } else if (SORT_DIRECTION_DESC.contains(direction.toUpperCase())) {
      input.sort(nullsLast(Collections.reverseOrder()));
    } else {
      return null;
    }
    return input;
  }

}