Example usage for java.util Arrays sort

List of usage examples for java.util Arrays sort

Introduction

In this page you can find the example usage for java.util Arrays sort.

Prototype

public static void sort(Object[] a) 

Source Link

Document

Sorts the specified array of objects into ascending order, according to the Comparable natural ordering of its elements.

Usage

From source file:com.l2jfree.gameserver.model.skills.conditions.ConditionTargetRaceId.java

public ConditionTargetRaceId(List<Integer> raceId) {
    _raceIds = ArrayUtils.toPrimitive(raceId.toArray(new Integer[raceId.size()]), 0);

    Arrays.sort(_raceIds);
}

From source file:com.wallellen.wechat.common.util.crypto.SHA1.java

/**
 * &arr??sha1 digest// w w  w  .  j  a v  a  2  s.  c  om
 *
 * @param arr
 * @return
 */
public static String genWithAmple(String... arr) throws NoSuchAlgorithmException {
    Arrays.sort(arr);
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < arr.length; i++) {
        String a = arr[i];
        sb.append(a);
        if (i != arr.length - 1) {
            sb.append('&');
        }
    }
    return DigestUtils.sha1Hex(sb.toString());
}

From source file:SampleCombo.java

public SampleCombo() {
    init();//from   www.  j a  v a 2  s.c  o  m

    shell.setLayout(new GridLayout(2, false));

    (new Label(shell, SWT.NULL)).setText("Select your favorite programming language: ");

    //final CCombo combo = new CCombo(shell, SWT.FLAT);
    final Combo combo = new Combo(shell, SWT.NULL);

    String[] languages = new String[] { "Java", "C", "C++", "SmallTalk" };

    Arrays.sort(languages);

    for (int i = 0; i < languages.length; i++)
        combo.add(languages[i]);

    //combo.add("Perl", 5);
    //combo.setItem(5, "Perl");

    combo.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            System.out.println("Selected index: " + combo.getSelectionIndex() + ", selected item: "
                    + combo.getItem(combo.getSelectionIndex()) + ", text content in the text field: "
                    + combo.getText());
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            System.out.println("Default selected index: " + combo.getSelectionIndex() + ", selected item: "
                    + (combo.getSelectionIndex() == -1 ? "<null>" : combo.getItem(combo.getSelectionIndex()))
                    + ", text content in the text field: " + combo.getText());
            String text = combo.getText();
            if (combo.indexOf(text) < 0) { // Not in the list yet. 
                combo.add(text);
                // Re-sort
                String[] items = combo.getItems();
                Arrays.sort(items);
                combo.setItems(items);
            }
        }
    });

    shell.pack();
    shell.open();
    //textUser.forceFocus();

    // Set up the event loop.
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            // If no more entries in event queue
            display.sleep();
        }
    }

    display.dispose();
}

From source file:com.opengamma.analytics.math.FunctionUtils.java

/**
 * Same behaviour as mathlab unique/*from   ww w .j  a v  a2 s . c  om*/
 * @param in input array
 * @return a sorted array with no duplicates values
 */
public static double[] unique(final double[] in) {
    Arrays.sort(in);
    final int n = in.length;
    final double[] temp = new double[n];
    temp[0] = in[0];
    int count = 1;
    for (int i = 1; i < n; i++) {
        if (Double.compare(in[i], in[i - 1]) != 0) {
            temp[count++] = in[i];
        }
    }
    if (count == n) {
        return temp;
    }
    return Arrays.copyOf(temp, count);
}

From source file:com.l2jfree.gameserver.model.skills.conditions.ConditionPlayerHasClanHall.java

public ConditionPlayerHasClanHall(List<Integer> clanHall) {
    _clanHall = ArrayUtils.toPrimitive(clanHall.toArray(new Integer[clanHall.size()]), 0);

    Arrays.sort(_clanHall);
}

From source file:com.xiantrimble.combinatorics.CombMathUtilsBenchmark.java

@Override
public long c(int k, int... m) {
    // sort m//from   w ww.j a  v a 2s  .  c o m
    int[] mSorted = Arrays.copyOf(m, m.length);
    Arrays.sort(mSorted);

    // group the distinct values.
    ArrayList<DistinctM> distinctMs = new ArrayList<DistinctM>();
    for (int i = mSorted.length - 1; i >= 0;) {
        int count = 1;
        for (; i - count >= 0 && mSorted[i] == mSorted[i - count]; count++)
            ;
        distinctMs.add(new DistinctM(mSorted[i], count));
        i -= count;
    }

    return c(k, distinctMs.toArray(new DistinctM[distinctMs.size()]));
}

From source file:Main.java

public SortedComboBoxModel(Object[] items) {
    Arrays.sort(items);
    int size = items.length;
    for (int i = 0; i < size; i++) {
        super.addElement(items[i]);
    }//www . j  av  a 2  s .  c o  m
    setSelectedItem(items[0]);
}

From source file:au.org.ala.spatial.util.BatchConsumer.java

synchronized public static void start(LayerIntersectDAO layerIntersectDao, String batchDir) {
    if (threads.size() == 0) {
        waitingBatchDirs = new LinkedBlockingQueue<String>();

        int size = Integer.parseInt(
                (new UserProperties()).getProperties().getProperty("batch_sampling_parallel_requests", "1"));
        for (int i = 0; i < size; i++) {
            Thread t = new BatchConsumerThread(waitingBatchDirs, layerIntersectDao, batchDir);
            t.start();//w  ww  .j  a  v  a 2 s. com
            threads.add(t);
        }

        //get jobs that may have been interrupted but a shutdown
        File f = new File(batchDir);
        File[] files = f.listFiles();
        Arrays.sort(files);
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()
                    && !(new File(files[i].getPath() + File.separator + "error.txt")).exists()
                    && !(new File(files[i].getPath() + File.separator + "finished.txt")).exists()) {
                System.out.println("found incomplete batch_sampling: " + files[i].getPath());
                try {
                    addBatch(files[i].getPath() + File.separator);
                } catch (InterruptedException e) {

                }
            }
        }
    }
}

From source file:com.gson.oauth.Pay.java

/**
 * ??//from w ww .j  a va  2 s  .  c  o  m
 * @param params
 * @param encode
 * @return
 * @throws UnsupportedEncodingException 
 */
public static String createSign(Map<String, String> params, boolean encode)
        throws UnsupportedEncodingException {
    Set<String> keysSet = params.keySet();
    Object[] keys = keysSet.toArray();
    Arrays.sort(keys);
    StringBuffer temp = new StringBuffer();
    boolean first = true;
    for (Object key : keys) {
        if (first) {
            first = false;
        } else {
            temp.append("&");
        }
        temp.append(key).append("=");
        Object value = params.get(key);
        String valueString = "";
        if (null != value) {
            valueString = value.toString();
        }
        if (encode) {
            temp.append(URLEncoder.encode(valueString, "UTF-8"));
        } else {
            temp.append(valueString);
        }
    }
    return temp.toString();
}

From source file:com.opengamma.analytics.math.statistics.descriptive.QuartileSkewnessCalculator.java

/**
 * @param x The array of data, not null. Must contain at least three points.
 * @return The quartile skewness./*from   w  w  w  . j  a  v a2 s.c  om*/
 */
@Override
public Double evaluate(final double[] x) {
    Validate.notNull(x, "x");
    final int n = x.length;
    Validate.isTrue(n >= 3, "Need at least three points to calculate interquartile range");
    if (n == 3) {
        return (x[2] - 2 * x[1] + x[0]) / 2.;
    }
    final double[] copy = Arrays.copyOf(x, n);
    Arrays.sort(copy);
    double[] lower, upper;
    if (n % 2 == 0) {
        lower = Arrays.copyOfRange(copy, 0, n / 2);
        upper = Arrays.copyOfRange(copy, n / 2, n);
    } else {
        lower = Arrays.copyOfRange(copy, 0, n / 2 + 1);
        upper = Arrays.copyOfRange(copy, n / 2, n);
    }
    final double q1 = MEDIAN.evaluate(lower);
    final double q2 = MEDIAN.evaluate(x);
    final double q3 = MEDIAN.evaluate(upper);
    return (q1 - 2 * q2 + q3) / (q3 - q1);
}