• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 package org.apache.commons.lang3;
18 
19 import java.util.Arrays;
20 import java.util.Comparator;
21 
22 /**
23  * Sorts and returns arrays in the fluent style.
24  *
25  * @since 3.12.0
26  */
27 public class ArraySorter {
28 
29     /**
30      * Sorts and returns the given array.
31      *
32      * @param array the array to sort.
33      * @return the given array.
34      * @see Arrays#sort(byte[])
35      */
sort(final byte[] array)36     public static byte[] sort(final byte[] array) {
37         Arrays.sort(array);
38         return array;
39     }
40 
41     /**
42      * Sorts and returns the given array.
43      *
44      * @param array the array to sort.
45      * @return the given array.
46      * @see Arrays#sort(char[])
47      */
sort(final char[] array)48     public static char[] sort(final char[] array) {
49         Arrays.sort(array);
50         return array;
51     }
52 
53     /**
54      * Sorts and returns the given array.
55      *
56      * @param array the array to sort.
57      * @return the given array.
58      * @see Arrays#sort(double[])
59      */
sort(final double[] array)60     public static double[] sort(final double[] array) {
61         Arrays.sort(array);
62         return array;
63     }
64 
65     /**
66      * Sorts and returns the given array.
67      *
68      * @param array the array to sort.
69      * @return the given array.
70      * @see Arrays#sort(float[])
71      */
sort(final float[] array)72     public static float[] sort(final float[] array) {
73         Arrays.sort(array);
74         return array;
75     }
76 
77     /**
78      * Sorts and returns the given array.
79      *
80      * @param array the array to sort.
81      * @return the given array.
82      * @see Arrays#sort(int[])
83      */
sort(final int[] array)84     public static int[] sort(final int[] array) {
85         Arrays.sort(array);
86         return array;
87     }
88 
89     /**
90      * Sorts and returns the given array.
91      *
92      * @param array the array to sort.
93      * @return the given array.
94      * @see Arrays#sort(long[])
95      */
sort(final long[] array)96     public static long[] sort(final long[] array) {
97         Arrays.sort(array);
98         return array;
99     }
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      */
sort(final short[] array)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      */
sort(final T[] array)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      */
sort(final T[] array, final Comparator<? super T> comparator)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 }
142