    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.lang3;
    018
    019import java.util.Arrays;
    020import java.util.Comparator;
    021
    022/**
    023 * Sorts and returns arrays in the fluent style.
    024 *
    025 * @since 3.12.0
    026 */
    027public class ArraySorter {
    028
    029    /**
    030     * Sorts and returns the given array.
    031     *
    032     * @param array the array to sort.
    033     * @return the given array.
    034     * @see Arrays#sort(byte[])
    035     */
    036    public static byte[] sort(final byte[] array) {
    037        Arrays.sort(array);
    038        return array;
    039    }
    040
    041    /**
    042     * Sorts and returns the given array.
    043     *
    044     * @param array the array to sort.
    045     * @return the given array.
    046     * @see Arrays#sort(char[])
    047     */
    048    public static char[] sort(final char[] array) {
    049        Arrays.sort(array);
    050        return array;
    051    }
    052
    053    /**
    054     * Sorts and returns the given array.
    055     *
    056     * @param array the array to sort.
    057     * @return the given array.
    058     * @see Arrays#sort(double[])
    059     */
    060    public static double[] sort(final double[] array) {
    061        Arrays.sort(array);
    062        return array;
    063    }
    064
    065    /**
    066     * Sorts and returns the given array.
    067     *
    068     * @param array the array to sort.
    069     * @return the given array.
    070     * @see Arrays#sort(float[])
    071     */
    072    public static float[] sort(final float[] array) {
    073        Arrays.sort(array);
    074        return array;
    075    }
    076
    077    /**
    078     * Sorts and returns the given array.
    079     *
    080     * @param array the array to sort.
    081     * @return the given array.
    082     * @see Arrays#sort(int[])
    083     */
    084    public static int[] sort(final int[] array) {
    085        Arrays.sort(array);
    086        return array;
    087    }
    088
    089    /**
    090     * Sorts and returns the given array.
    091     *
    092     * @param array the array to sort.
    093     * @return the given array.
    094     * @see Arrays#sort(long[])
    095     */
    096    public static long[] sort(final long[] array) {
    097        Arrays.sort(array);
    098        return array;
    099    }
    100
    101    /**
    102     * Sorts and returns the given array.
    103     *
    104     * @param array the array to sort.
    105     * @return the given array.
    106     * @see Arrays#sort(short[])
    107     */
    108    public static short[] sort(final short[] array) {
    109        Arrays.sort(array);
    110        return array;
    111    }
    112
    113    /**
    114     * Sorts and returns the given array.
    115     *
    116     * @param <T> the array type.
    117     * @param array the array to sort.
    118     * @return the given array.
    119     * @see Arrays#sort(Object[])
    120     */
    121    public static <T> T[] sort(final T[] array) {
    122        Arrays.sort(array);
    123        return array;
    124    }
    125
    126    /**
    127     * Sorts and returns the given array.
    128     *
    129     * @param <T> the array type.
    130     * @param array the array to sort.
    131     * @param comparator the comparator to determine the order of the array. A {@code null} value uses the elements'
    132     *        {@link Comparable natural ordering}.
    133     * @return the given array.
    134     * @see Arrays#sort(Object[])
    135     */
    136    public static <T> T[] sort(final T[] array, final Comparator<? super T> comparator) {
    137        Arrays.sort(array, comparator);
    138        return array;
    139    }
    140
    141}