List of usage examples for java.util Arrays sort
public static void sort(Object[] a)
From source file:Main.java
/** * Returns the 'percentile' value in array * @param array A {@code double} array * @param percentile The percentile value to obtain between 0-1 * @return returns value at {@code percentile} in {@code array} * *///from ww w .j a v a 2s. c om public static double percentile(double[] array, double percentile) { Arrays.sort(array); if (array.length == 0 || percentile < 0 || percentile > 1) throw new IllegalArgumentException(); double k = (array.length - 1) * percentile; double f = Math.floor(k); double c = Math.ceil(k); if (f == c) return array[(int) k]; return array[(int) f] * (c - k) + array[(int) c] * (k - f); }
From source file:Main.java
/** * Get all threads/*w w w .j a va2 s . c o m*/ * * @return */ public static String[] getThreadNames() { ThreadGroup group = Thread.currentThread().getThreadGroup(); ThreadGroup parent = null; while ((parent = group.getParent()) != null) { group = parent; } Thread[] threads = new Thread[group.activeCount()]; group.enumerate(threads); HashSet<String> set = new HashSet<String>(); for (int i = 0; i < threads.length; ++i) { if (threads[i] != null && threads[i].isAlive()) { try { set.add(threads[i].getThreadGroup().getName() + ", " + threads[i].getName() + ", " + threads[i].getPriority() + ", " + threads[i].getState()); } catch (Throwable e) { e.printStackTrace(); } } } String[] result = (String[]) set.toArray(new String[0]); Arrays.sort(result); for (int i = 0; i < result.length; i++) { // logger.debug(result[i]); } return result; }
From source file:Main.java
/** * Sort the CopyOnWriteArrayList./*from w ww.j a v a 2 s.co m*/ * * @param list The list to sort. * @param <E> The type of data. */ public static <E extends Comparable<E>> void sort(CopyOnWriteArrayList<E> list) { Object[] content = list.toArray(); Arrays.sort(content); for (int i = 0; i < content.length; i++) { list.set(i, (E) content[i]); } }
From source file:Main.java
public static String[] list(String path, AssetManager assetManager) throws IOException { String[] files = assetManager.list(path); Arrays.sort(files); return files; }
From source file:Main.java
/** * Greatest Common Divisor according to Euclid's algorithm * //from w ww . j a v a 2 s . co m * @param array * @return */ public static long gcd(long[] array) { // local vars int listSize = array.length; long a, b, gcd1; long ONE = (long) 1; long[] arrayTmp = array.clone(); Arrays.sort(arrayTmp); if (listSize == 0 || arrayTmp[listSize - 1] == 0) { return (ONE); } a = arrayTmp[0]; gcd1 = a; for (int i = 1; i < listSize; i++) { if (gcd1 == 1) { break; } gcd1 = a; a = arrayTmp[i]; b = gcd1; while (b != 0) { gcd1 = b; b = a % gcd1; a = gcd1; } // System.out.println(gcd1); } return (gcd1); }
From source file:Main.java
/** * Obtains a list of files that live in the specified directory and match the glob pattern. *//*from ww w .j ava 2s.com*/ public static String[] getFiles(File dir, String glob) { String regex = globToRegex(glob); final Pattern pattern = Pattern.compile(regex); String[] result = dir.list(new FilenameFilter() { @Override public boolean accept(File dir, String name) { Matcher matcher = pattern.matcher(name); return matcher.matches(); } }); Arrays.sort(result); return result; }
From source file:Main.java
public static void top_k_competition(float[][][] response_array, int k) { int depth = response_array.length; int height = response_array[0].length; int width = response_array[0][0].length; int find_min_flag = 0; float[] copy_of_array = new float[depth * height * width]; for (int depth_index = 0; depth_index < depth; depth_index++) { for (int height_index = 0; height_index < height; height_index++) { System.arraycopy(response_array[depth_index][height_index], 0, copy_of_array, (depth_index * height + height_index) * width, width); }/*from w ww . j av a 2 s . c o m*/ } Arrays.sort(copy_of_array); for (int depth_index = 0; depth_index < depth; depth_index++) { for (int height_index = 0; height_index < height; height_index++) { for (int width_index = 0; width_index < width; width_index++) { if (response_array[depth_index][height_index][width_index] < copy_of_array[depth * height * width - k]) { response_array[depth_index][height_index][width_index] = 0; } else if ((response_array[depth_index][height_index][width_index] == copy_of_array[depth * height * width - k]) && find_min_flag == 1) { response_array[depth_index][height_index][width_index] = 0; } else if ((response_array[depth_index][height_index][width_index] == copy_of_array[depth * height * width - k]) && find_min_flag == 0) { response_array[depth_index][height_index][width_index] = 1; find_min_flag = 1; } else { response_array[depth_index][height_index][width_index] = 1; } } } } }
From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Sort.java
/** * Sorts values statelessly in ascending order * @param v1 the values to sort (a native backed array) * @return tmp the sorted values// ww w. j a va2 s .c om */ public static int[] stateless(int[] v1) { Validate.notNull(v1); int[] tmp = Arrays.copyOf(v1, v1.length); Arrays.sort(tmp); return tmp; }
From source file:Main.java
/** * Removes the given elements from the given list. This method tries to use * {@link DefaultListModel#removeRange} when possible in order to group events * together.//www. j a v a2s . c o m * <p> * <strong>Warning:</strong> This method override the given {@code indices} array. * * @param list The list from which to remove elements. * @param indices The index of elements to remove. */ public static void remove(final DefaultListModel<?> list, final int[] indices) { // We must iterate in reverse order, because the // index after the removed elements will change. int i = indices.length; if (i != 0) { Arrays.sort(indices); int upper = indices[--i]; int lower = upper; while (i != 0) { int previous = indices[--i]; if (previous != lower - 1) { if (lower == upper) { list.remove(lower); } else { list.removeRange(lower, upper); } upper = previous; } lower = previous; } if (lower == upper) { list.remove(lower); } else { list.removeRange(lower, upper); } } }
From source file:SignatureTest.java
private String findSignature(String str) { String[] els = StringUtils.split(str, ":"); Arrays.sort(els); return StringUtils.join(els, ":"); }