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:de.nec.nle.siafu.graphics.controlpanel.OverlaysPanel.java

/**
 * Add the overlays to the combo box of the panel.
 *///w w w.j a v a 2 s .co  m
@Override
protected void addSelectableElements() {
    String[] items = new String[gui.getOverlays().size()];

    int i = 0;
    for (Overlay ov : gui.getOverlays()) {
        items[i] = ov.getName();
        i++;
    }

    Arrays.sort(items);
    selectionCombo.setItems(items);
}

From source file:eu.irreality.age.SwingAetheriaGameLoaderInterface.java

public static void loadFont() {

    //cargar configuracin del ini

    String fontName = "Courier New";
    int fontSize = 12;
    try {/*from www  .  jav  a  2 s .  c  om*/
        BufferedReader iniReader = new BufferedReader(
                Utility.getBestInputStreamReader(new FileInputStream("age.cfg")));
        String linea;
        for (int line = 1; line < 100; line++) {
            linea = iniReader.readLine();
            if (linea != null) {
                //System.out.println("Linea " + linea );
                String codigo = StringMethods.getTok(linea, 1, '=').trim().toLowerCase();
                if (codigo.equals("font name")) {
                    //System.out.println("Nombre: " + StringMethods.getTok(linea,2,'=').trim() );
                    fontName = StringMethods.getTok(linea, 2, '=').trim();
                } else if (codigo.equals("font size")) {
                    fontSize = Integer.parseInt(StringMethods.getTok(linea, 2, '=').trim());
                }
            }
        }
    }
    //las excepciones nos la sudan porque hay valores por defecto
    catch (FileNotFoundException fnfe) {
        ;
    } catch (NumberFormatException nfe) {
        ;
    } catch (IOException ioe) {
        ;
    } catch (SecurityException se) //applet mode
    {
        ;
    }
    Font[] fuentes = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
    Font fuenteElegida;
    for (int f = 0; f < fuentes.length; f++) {
        if (fuentes[f].getFontName().equalsIgnoreCase(fontName)) {
            SwingAetheriaGameLoaderInterface.font = fuentes[f].deriveFont((float) fontSize);
            break;
        }
        //System.out.println("Fuente: " + fuentes[f]);
    }

    //System.err.println("He seleccionado mi fuente, y es: " + SwingAetheriaGameLoaderInterface.font  );

    //font not selected? be less picky
    if (SwingAetheriaGameLoaderInterface.font == null) {
        String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
        Arrays.sort(fonts);
        if (Arrays.binarySearch(fonts, "Courier New") >= 0) {
            SwingAetheriaGameLoaderInterface.font = new Font("Courier New", Font.PLAIN, 12);
        } else if (Arrays.binarySearch(fonts, "Courier") >= 0) {
            SwingAetheriaGameLoaderInterface.font = new Font("Courier", Font.PLAIN, 12);
        } else if (Arrays.binarySearch(fonts, "Monospaced") >= 0) {
            SwingAetheriaGameLoaderInterface.font = new Font("Monospaced", Font.PLAIN, 13);
        }
    }

    //still not selected? well, in that case just default to font 0
    if (SwingAetheriaGameLoaderInterface.font == null)
        SwingAetheriaGameLoaderInterface.font = fuentes[0].deriveFont((float) fontSize);
}

From source file:adams.gui.visualization.stats.paintlet.Exponential.java

/**
 * For calculating the dimensions of the plot area.
 *///from  w  w  w .j  ava2  s. com
@Override
public void calculateDimensions() {
    double median;
    m_Sorted = SpreadSheetUtils.getNumericColumn(m_Data, m_Index);
    m_TransformedY = new double[m_Sorted.length];
    Arrays.sort(m_Sorted);
    for (int i = 0; i < m_Sorted.length; i++) {
        median = ((i + 1) - 0.3) / (m_Sorted.length + 0.4);
        //calculate the transformed y values using inverse exponential
        m_TransformedY[i] = -1 * (Math.log10(1 - median));
    }
    //If the axis can handle the data
    if (m_AxisBottom.getType().canHandle(m_Sorted[0], m_Sorted[m_Sorted.length - 1])) {
        m_AxisBottom.setMinimum(m_Sorted[0]);
        m_AxisBottom.setMaximum(m_Sorted[m_Sorted.length - 1]);
    } else {
        getLogger().severe("errors in plotting");
    }
    if (m_AxisLeft.getType().canHandle(m_TransformedY[0], m_TransformedY[m_TransformedY.length - 1])) {
        m_AxisLeft.setMinimum(m_TransformedY[0]);
        m_AxisLeft.setMaximum(m_TransformedY[m_TransformedY.length - 1]);
    } else {
        getLogger().severe("errors in plotting");
    }
    m_AxisBottom.setAxisName(m_Data.getColumnName(m_Index) + ")");
    m_AxisLeft.setAxisName("Inverse Exponential");
}

From source file:de.dhke.projects.cutil.collections.cow.CopyOnWriteMultiMapValueCollectionTest.java

/**
 * Test of iterator method, of class CopyOnWriteMultiMapValueCollection.
 *///from   w w  w .jav  a 2s  . c o  m
@Test
public void testIterator() {
    Iterator<String> iter = _valueCollection.iterator();
    String[] referenceArray = { "a", "A", "b", "B", "c", "C" };
    Arrays.sort(referenceArray);
    for (int i = 0; i < _valueCollection.size(); ++i) {
        assertTrue(iter.hasNext());
        assertTrue(Arrays.binarySearch(referenceArray, iter.next()) >= 0);
    }
    assertFalse(iter.hasNext());

    _cowMap.copy();
    iter = _valueCollection.iterator();
    String first = iter.next();
    iter.remove();
    assertFalse(_cowMap.containsValue(first));
}

From source file:org.eclipse.virgo.qa.performance.virgo.VirgoServerPickupDeploymentAndUndeploymentPerformanceTests.java

@Test
public void testPickupDeploymentOfStandardWarPerformance() throws Exception {
    long[] duration = new long[NO_OF_ITERATIONS];

    for (int i = 0; i < NO_OF_ITERATIONS; i++) {
        long starttime = 0l;
        long endtime = 0l;
        long testDuration = 0l;
        copyApplicationsToPickup(getPickupDir(), APPS_DIR, APPLICATION_NAME_WAR);
        starttime = System.currentTimeMillis();

        waitForTextPresent("/formtags-war-2.0.0.RELEASE", "applications_modules_formtags-war.war");
        endtime = System.currentTimeMillis();
        testDuration = endtime - starttime;
        duration[i] = testDuration;/*w  w w . j  ava2  s  . c o m*/

        deleteApplicationsFromPickup(getPickupDir(), APPLICATION_NAME_WAR);
        waitForTextNotPresent("/formtags-war-2.0.0.RELEASE", "applications_modules_formtags-war.war");
        Thread.sleep(2000);
    }

    Arrays.sort(duration);
    long high = duration[duration.length - 1];
    long low = duration[NO_OF_ITERATIONS / 2];
    long average = (high + low) / 2;
    try {
        record("testPickupDeploymentOfStandardWarPerformance", average, high, low, 5000);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:algorithms.MedianDivergenceComputer.java

private void deriveMedianColormapToJNDRatio() {
    int len = points.size() / 2;
    ratios = new double[len];
    Iterator<Point2D> ptIt = points.iterator();

    int i = 0;/*from   w ww . j a  v a 2  s  .  co  m*/
    while (i < len && ptIt.hasNext()) {
        Point2D p1 = ptIt.next();
        Point2D p2 = ptIt.next();

        double dist = p1.distance(p2);

        Color colorA = colormap.getColor(p1.getX(), p1.getY());
        Color colorB = colormap.getColor(p2.getX(), p2.getY());

        // color distance
        double cdist = colorDiff(colorA, colorB);

        // filter zero divisions, as long as the value distance is small
        // DON'T protect colormaps that contain duplicate colors
        if (cdist == 0 && dist < 0.05)
            continue;
        double ratio = cdist / dist;
        ratios[i] = ratio;
        i++;
    }
    Arrays.sort(ratios);
}

From source file:eionet.cr.web.action.admin.staging.AvailableFilesActionBean.java

/**
 * List all available files./*ww w  .  j  a  v a 2s  .com*/
 *
 * @return the resolution
 */
@DefaultHandler
public Resolution list() {

    File[] files = FileDownloader.FILES_DIR.listFiles();
    Arrays.sort(files);
    for (int i = 0; i < files.length; i++) {
        availableFiles.add(AvailableFile.create(files[i]));
    }

    return new ForwardResolution(LIST_JSP);
}

From source file:de.dhke.projects.cutil.collections.cow.CopyOnWriteMultiMapKeySetTest.java

/**
 * Test of iterator method, of class CopyOnWriteMultiMapKeySet.
 *///  w w  w.j a  va  2 s.  c  om
@Test
public void testIteratorCopyBefore() {
    Iterator<String> iter = _keySet.iterator();
    String[] referenceArray = { "1", "2", "3" };
    Arrays.sort(referenceArray);
    for (int i = 0; i < _keySet.size(); ++i) {
        assertTrue(iter.hasNext());
        assertTrue(Arrays.binarySearch(referenceArray, iter.next()) >= 0);
    }
    assertFalse(iter.hasNext());

    _cowMap.copy();
    iter = _keySet.iterator();
    String first = iter.next();
    iter.remove();
    assertFalse(_cowMap.containsKey(first));
}

From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Sort.java

/**
 * Sorts values statelessly in order given by enumeration
 * @param v1 the values to sort (a native backed array)
 * @param d the direction in which the sorted array should be returned (based on {@link direction})
 * @return tmp the sorted values/*from w ww  .ja v a 2s.c o m*/
 */
public static double[] stateless(double[] v1, direction d) {
    Validate.notNull(v1);
    double[] tmp = Arrays.copyOf(v1, v1.length);
    Arrays.sort(tmp);
    switch (d) {
    case ascend:
        break;
    case descend:
        Reverse.inPlace(tmp);
    }
    return tmp;
}

From source file:com.indeed.lsmtree.core.TestStore.java

public void testStore(StorageType storageType, CompressionCodec codec) throws Exception {
    File indexDir = new File(tmpDir, "index");
    indexDir.mkdirs();/*  w  ww.jav  a  2  s.c  om*/
    File indexLink = new File(tmpDir, "indexlink");
    PosixFileOperations.link(indexDir, indexLink);
    File storeDir = new File(indexLink, "store");
    Store<Integer, Long> store = new StoreBuilder<Integer, Long>(storeDir, new IntSerializer(),
            new LongSerializer()).setMaxVolatileGenerationSize(8 * 1024 * 1024).setStorageType(storageType)
                    .setCodec(codec).build();
    final Random r = new Random(0);
    final int[] ints = new int[treeSize];
    for (int i = 0; i < ints.length; i++) {
        ints[i] = r.nextInt();
    }
    for (final int i : ints) {
        store.put(i, (long) i);
        assertTrue(store.get(i) == i);
    }
    for (final int i : ints) {
        assertTrue(store.get(i) == i);
    }
    store.close();
    store.waitForCompactions();
    store = new StoreBuilder<Integer, Long>(storeDir, new IntSerializer(), new LongSerializer())
            .setMaxVolatileGenerationSize(8 * 1024 * 1024).setStorageType(storageType).setCodec(codec).build();
    Arrays.sort(ints);
    Iterator<Store.Entry<Integer, Long>> iterator = store.iterator();
    int index = 0;
    while (iterator.hasNext()) {
        Store.Entry<Integer, Long> next = iterator.next();
        int current = ints[index];
        assertTrue(next.getKey() == ints[index]);
        assertTrue(next.getValue() == ints[index]);
        while (index < ints.length && ints[index] == current) {
            index++;
        }
    }
    assertTrue(index == ints.length);
    final BitSet deleted = new BitSet();
    for (int i = 0; i < ints.length / 10; i++) {
        int deletionIndex = r.nextInt(ints.length);
        deleted.set(deletionIndex, true);
        for (int j = deletionIndex - 1; j >= 0; j--) {
            if (ints[j] == ints[deletionIndex]) {
                deleted.set(j, true);
            } else {
                break;
            }
        }
        for (int j = deletionIndex + 1; j < ints.length; j++) {
            if (ints[j] == ints[deletionIndex]) {
                deleted.set(j, true);
            } else {
                break;
            }
        }
        store.delete(ints[deletionIndex]);
        assertNull(store.get(ints[deletionIndex]));
    }
    iterator = store.iterator();
    index = 0;
    while (iterator.hasNext()) {
        Store.Entry<Integer, Long> next = iterator.next();
        while (deleted.get(index))
            index++;
        int current = ints[index];
        assertTrue(next.getKey() == ints[index]);
        assertTrue(next.getValue() == ints[index]);
        while (index < ints.length && ints[index] == current) {
            index++;
        }
    }
    while (deleted.get(index))
        index++;
    assertTrue(index == ints.length);
    final int max = ints[ints.length - 1];
    final AtomicInteger done = new AtomicInteger(8);
    for (int i = 0; i < done.get(); i++) {
        final int thread = i;
        final Store<Integer, Long> finalStore = store;
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Random r = new Random(thread);
                    for (int i = 0; i < treeSize; i++) {
                        int rand = r.nextInt();
                        int insertionindex = Arrays.binarySearch(ints, rand);

                        Store.Entry<Integer, Long> next = finalStore.ceil(rand);
                        boolean found = next != null;
                        if (insertionindex >= 0 && deleted.get(insertionindex)) {
                            assertNull(finalStore.get(ints[insertionindex]));
                        } else {
                            assertTrue(found == (rand <= max));
                            if (found) {
                                assertTrue(next.getKey() >= rand);
                                assertTrue(next.getKey().longValue() == next.getValue());
                                if (insertionindex >= 0) {
                                    assertTrue(rand == ints[insertionindex]);
                                    assertTrue(next.getKey() == rand);
                                    Long result = finalStore.get(rand);
                                    assertTrue(result == rand);
                                } else {
                                    int nextIndex = ~insertionindex;
                                    while (deleted.get(nextIndex) && nextIndex < ints.length)
                                        nextIndex++;
                                    if (nextIndex < ints.length) {
                                        if (insertionindex != -1)
                                            assertTrue(ints[(~insertionindex) - 1] < rand);
                                        assertTrue(ints[nextIndex] + " != " + next.getKey(),
                                                ints[nextIndex] == next.getKey());

                                    }
                                    Long result = finalStore.get(rand);
                                    assertTrue(result == null);
                                }
                            }
                        }
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } finally {
                    done.decrementAndGet();
                }
            }
        }).start();
    }
    while (done.get() > 0) {
        Thread.yield();
    }
    store.close();
}