List of usage examples for java.util Arrays sort
public static void sort(Object[] a)
From source file:fi.smaa.libror.RandomUtil.java
/** * Creates an array of random numbers that sum to a given amount. * //ww w. ja va 2 s . c o m * @param dest the array to create the numbers to. * @param sumTo The amount the numbers must sum to. Must be >= 0.0 * @throws NullPointerException if dest == null */ public static void createSumToRand(double[] dest, double sumTo) throws NullPointerException { if (sumTo < 0.0) { throw new IllegalArgumentException("sumTo negative"); } if (dest == null) { throw new NullPointerException("destination array null"); } int len = dest.length; for (int i = 0; i < len - 1; i++) { dest[i] = createUnif01() * sumTo; } dest[len - 1] = sumTo; Arrays.sort(dest); double last = 0.0; for (int i = 0; i < len; i++) { double t = dest[i]; dest[i] = t - last; last = t; } }
From source file:com.opengamma.analytics.math.statistics.descriptive.ModeCalculator.java
/** * @param x The array of data, not null or empty * @return The arithmetic mean/*from w w w . j ava 2 s .c o m*/ */ @Override public Double evaluate(final double[] x) { Validate.notNull(x, "x"); Validate.isTrue(x.length > 0, "x cannot be empty"); if (x.length == 1) { return x[0]; } final double[] x1 = Arrays.copyOf(x, x.length); Arrays.sort(x1); final TreeMap<Integer, Double> counts = new TreeMap<Integer, Double>(); int count = 1; for (int i = 1; i < x1.length; i++) { if (Math.abs(x1[i] - x1[i - 1]) < EPS) { count++; } else { counts.put(count, x1[i - 1]); count = 1; } } if (counts.lastKey() == 1) { throw new MathException("Could not find mode for array; no repeated values"); } return counts.lastEntry().getValue(); }
From source file:Statistics.java
public static int median(final int[] list) throws IllegalArgumentException { if (list.length < 1) { throw new IllegalArgumentException(); }/*from www .j a va 2 s. co m*/ Arrays.sort(list); if ((list.length % 2) == 0) { // is even final int idx = list.length / 2; return (list[idx] + list[idx - 1]) / 2; } else { // is odd final int idx = list.length / 2; return list[idx]; } }
From source file:com.opengamma.analytics.math.statistics.descriptive.robust.WinsorizedMeanCalculator.java
@Override public Double evaluate(final double[] x) { Validate.notNull(x, "x was null"); final int length = x.length; Validate.isTrue(length > 0, "x was empty"); final double[] winsorized = Arrays.copyOf(x, length); Arrays.sort(winsorized); final int value = (int) Math.round(length * _gamma); final double x1 = winsorized[value]; final double x2 = winsorized[length - value - 1]; for (int i = 0; i < value; i++) { winsorized[i] = x1;//from ww w .java 2 s . co m winsorized[length - 1 - i] = x2; } return MEAN_CALCULATOR.evaluate(winsorized); }
From source file:com.akjava.wiki.client.keyword.KeyWordUtils.java
public static Keyword[] loadCsvKeyWord(Reader reader) { List<Keyword> list = new ArrayList<Keyword>(); String text;/*from ww w .j a va2 s . co m*/ try { text = IOUtils.toString(reader); String line[] = text.split(SystemUtils.LINE_SEPARATOR); for (int i = 0; i < line.length; i++) { String word[] = line[i].split(","); if (word.length > 1) { Keyword key = new Keyword(word[0], word[1]); if (word.length > 2) { key.setIcon(word[2].trim()); } list.add(key); } else if (word.length == 1) { String w = word[0]; if (!w.startsWith("<") && !w.isEmpty()) {//ignore tag & empty Keyword key = new Keyword(w, ""); list.add(key); } } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Keyword[] keywords = (Keyword[]) list.toArray(new Keyword[list.size()]); Arrays.sort(keywords); return keywords; }
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/*from w w w.ja v a 2 s . c o m*/ */ public static float[] stateless(float[] v1) { Validate.notNull(v1); float[] tmp = Arrays.copyOf(v1, v1.length); Arrays.sort(tmp); return tmp; }
From source file:com.opengamma.analytics.math.statistics.descriptive.robust.TrimmedMeanCalculator.java
@Override public Double evaluate(final double[] x) { Validate.notNull(x, "x was null"); final int length = x.length; Validate.isTrue(length > 0, "x was empty"); final int value = (int) Math.round(length * _gamma); final double[] copy = Arrays.copyOf(x, length); Arrays.sort(copy); final double[] trimmed = new double[length - 2 * value]; for (int i = 0; i < trimmed.length; i++) { trimmed[i] = x[i + value];/*from w ww .ja va 2 s . c o m*/ } return MEAN_CALCULATOR.evaluate(trimmed); }
From source file:com.opengamma.analytics.math.statistics.descriptive.MedianCalculator.java
/** * @param x The array of data, not null or empty * @return The median/*from w w w . ja v a 2 s . c o m*/ */ @Override public Double evaluate(final double[] x) { Validate.notNull(x); Validate.isTrue(x.length > 0, "x cannot be empty"); if (x.length == 1) { return x[0]; } final double[] x1 = Arrays.copyOf(x, x.length); Arrays.sort(x1); final int mid = x1.length / 2; if (x1.length % 2 == 1) { return x1[mid]; } return (x1[mid] + x1[mid - 1]) / 2.; }
From source file:com.l2jfree.gameserver.model.skills.conditions.ConditionPlayerClassIdRestriction.java
public ConditionPlayerClassIdRestriction(List<Integer> classId) { _classIds = ArrayUtils.toPrimitive(classId.toArray(new Integer[classId.size()]), 0); Arrays.sort(_classIds); }
From source file:com.l2jfree.gameserver.model.skills.conditions.ConditionTargetClassIdRestriction.java
public ConditionTargetClassIdRestriction(List<Integer> classId) { _classIds = ArrayUtils.toPrimitive(classId.toArray(new Integer[classId.size()]), 0); Arrays.sort(_classIds); }