@Override
  public <E> List<E> sort(final List<E> elements) {
    int elementsSize = elements.size();

    if (elementsSize <= getSizeThreshold()) {
      return getSorter().sort(elements);
    }
    else {
      int beginIndex = 1;
      int endIndex = (elementsSize - 1);

      E pivotElement = elements.get(0);

      while (beginIndex < endIndex) {
        while (beginIndex < endIndex && getOrderBy().compare(elements.get(beginIndex), pivotElement) <= 0) {
          beginIndex++;
        }

        while (endIndex >= beginIndex && getOrderBy().compare(elements.get(endIndex), pivotElement) >= 0) {
          endIndex--;
        }

        if (beginIndex < endIndex) {
          swap(elements, beginIndex, endIndex);
        }
      }

      swap(elements, 0, endIndex);
      sort(elements.subList(0, endIndex));
      sort(elements.subList(endIndex + 1, elementsSize));

      return elements;
    }
  }
@ Override public < E > List < E > sort ( final List < E > elements ) { int elementsSize = elements . size ( ) ; if ( elementsSize <= getSizeThreshold ( ) ) { return getSorter ( ) . sort ( elements ) ; } else { int beginIndex = 1 ; int endIndex = ( elementsSize - 1 ) ; E pivotElement = elements . get ( 0 ) ; while ( beginIndex < endIndex ) { while ( beginIndex < endIndex && getOrderBy ( ) . compare ( elements . get ( beginIndex ) , pivotElement ) <= 0 ) { beginIndex ++ ; } while ( endIndex >= beginIndex && getOrderBy ( ) . compare ( elements . get ( endIndex ) , pivotElement ) >= 0 ) { endIndex -- ; } if ( beginIndex < endIndex ) { swap ( elements , beginIndex , endIndex ) ; } } swap ( elements , 0 , endIndex ) ; sort ( elements . subList ( 0 , endIndex ) ) ; sort ( elements . subList ( endIndex + 1 , elementsSize ) ) ; return elements ; } }
Uses the Quick Sort algorithm to sort a List of elements as defined by the Comparator, or as determined
by the elements in the collection if the elements are Comparable.

@param <E> the type of elements in the List.
@param elements the List of elements to sort.
@return the collection of elements sorted.
@see java.util.List