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 * TODO For 4.0, rename to ArraySort, since we cover the sort() method here, see also ArrayFill. 26 * @since 3.12.0 27 */ 28 public class ArraySorter { 29 30 /** 31 * Sorts and returns the given array. 32 * 33 * @param array the array to sort. 34 * @return the given array. 35 * @see Arrays#sort(byte[]) 36 */ 37 public static byte[] sort(final byte[] array) { 38 Arrays.sort(array); 39 return array; 40 } 41 42 /** 43 * Sorts and returns the given array. 44 * 45 * @param array the array to sort. 46 * @return the given array. 47 * @see Arrays#sort(char[]) 48 */ 49 public static char[] sort(final char[] array) { 50 Arrays.sort(array); 51 return array; 52 } 53 54 /** 55 * Sorts and returns the given array. 56 * 57 * @param array the array to sort. 58 * @return the given array. 59 * @see Arrays#sort(double[]) 60 */ 61 public static double[] sort(final double[] array) { 62 Arrays.sort(array); 63 return array; 64 } 65 66 /** 67 * Sorts and returns the given array. 68 * 69 * @param array the array to sort. 70 * @return the given array. 71 * @see Arrays#sort(float[]) 72 */ 73 public static float[] sort(final float[] array) { 74 Arrays.sort(array); 75 return array; 76 } 77 78 /** 79 * Sorts and returns the given array. 80 * 81 * @param array the array to sort. 82 * @return the given array. 83 * @see Arrays#sort(int[]) 84 */ 85 public static int[] sort(final int[] array) { 86 Arrays.sort(array); 87 return array; 88 } 89 90 /** 91 * Sorts and returns the given array. 92 * 93 * @param array the array to sort. 94 * @return the given array. 95 * @see Arrays#sort(long[]) 96 */ 97 public static long[] sort(final long[] array) { 98 Arrays.sort(array); 99 return array; 100 } 101 102 /** 103 * Sorts and returns the given array. 104 * 105 * @param array the array to sort. 106 * @return the given array. 107 * @see Arrays#sort(short[]) 108 */ 109 public static short[] sort(final short[] array) { 110 Arrays.sort(array); 111 return array; 112 } 113 114 /** 115 * Sorts and returns the given array. 116 * 117 * @param <T> the array type. 118 * @param array the array to sort. 119 * @return the given array. 120 * @see Arrays#sort(Object[]) 121 */ 122 public static <T> T[] sort(final T[] array) { 123 Arrays.sort(array); 124 return array; 125 } 126 127 /** 128 * Sorts and returns the given array. 129 * 130 * @param <T> the array type. 131 * @param array the array to sort. 132 * @param comparator the comparator to determine the order of the array. A {@code null} value uses the elements' 133 * {@link Comparable natural ordering}. 134 * @return the given array. 135 * @see Arrays#sort(Object[]) 136 */ 137 public static <T> T[] sort(final T[] array, final Comparator<? super T> comparator) { 138 Arrays.sort(array, comparator); 139 return array; 140 } 141 142 }