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.shlaunch.weixin.local.web.AbstractController.java

protected boolean checkSignature(String signature, String timestamp, String nonce) {
    String token = TOKEN;/*  w  w w.  j  a v a2s. co m*/
    String[] str = { token, timestamp, nonce };
    Arrays.sort(str); // ??
    String bigStr = str[0] + str[1] + str[2];
    String sha = DigestUtils.shaHex(bigStr);
    logger.debug("bigStr:" + bigStr + ",sha:" + sha);
    if (signature.equals(sha)) {
        return true;
    } else {
        return false;
    }
}

From source file:com.chiorichan.site.SiteManager.java

public static void cleanupBackups(final String siteId, final String suffix, int limit) {
    File dir = new File(AppConfig.get().getDirectory("archive", "archive"), siteId);
    if (!dir.exists())
        return;//  w w w  .  j  ava  2 s . c o m
    File[] files = dir.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(suffix);
        }
    });

    if (files == null || files.length < 1)
        return;

    // Delete all logs, no archiving!
    if (limit < 1) {
        for (File f : files)
            f.delete();
        return;
    }

    FileFunc.SortableFile[] sfiles = new FileFunc.SortableFile[files.length];

    for (int i = 0; i < files.length; i++)
        sfiles[i] = new FileFunc.SortableFile(files[i]);

    Arrays.sort(sfiles);

    if (sfiles.length > limit)
        for (int i = 0; i < sfiles.length - limit; i++)
            sfiles[i].f.delete();
}

From source file:net.ageto.gyrex.persistence.jdbc.pool.internal.commands.ListPools.java

@Override
protected void doExecute() throws Exception {

    // check for exact filter match
    if ((null != poolIdFilter) && IdHelper.isValidId(poolIdFilter)) {
        final PoolDefinition pool = new PoolDefinition(poolIdFilter);
        if (pool.exists()) {
            printPool(pool);//from  w  w  w  . ja  v a 2 s . c om
            return;
        }
    }

    // list all known ids
    printf("Known Pools:");
    final String[] knownPoolIds = PoolDefinition.getKnownPoolIds();
    Arrays.sort(knownPoolIds);
    for (final String poolId : knownPoolIds) {
        if ((null == poolIdFilter) || StringUtils.containsIgnoreCase(poolId, poolIdFilter)) {
            if (PoolActivator.getInstance().getRegistry().isActive(poolId)) {
                printf("  %s (open)", poolId);
            } else {
                printf("  %s", poolId);
            }
        }
    }

    // list all known drivers
    printf("Known drivers:");
    final Collection<ServiceReference<DataSourceFactory>> services = PoolActivator.getInstance()
            .findDriverDataSourceFactoryServices(null);
    if (!services.isEmpty()) {
        for (final ServiceReference<DataSourceFactory> serviceReference : services) {
            printf("  %s", serviceReference.toString());
        }
    } else {
        printf("  None");
    }

}

From source file:net.itransformers.topologyviewer.menu.handlers.graphTools.shortherstPathMenuHandlers.DijkstraWeightedShortestPathMenuHandler.java

@Override
public void actionPerformed(ActionEvent e) {
    final GraphViewerPanel viewerPanel = (GraphViewerPanel) frame.getTabbedPane().getSelectedComponent();
    final MyVisualizationViewer vv = (MyVisualizationViewer) viewerPanel.getVisualizationViewer();

    Collection<String> vertices = viewerPanel.getCurrentGraph().getVertices();
    String[] test = vertices.toArray(new String[0]);
    Arrays.sort(test);

    final String mFrom = (String) JOptionPane.showInputDialog(frame, "Choose A Node", "A Node",
            JOptionPane.PLAIN_MESSAGE, null, test, test[0]);
    final String mTo = (String) JOptionPane.showInputDialog(frame, "Choose B Node", "B Node",
            JOptionPane.PLAIN_MESSAGE, null, test, test[0]);
    String weightedKey = JOptionPane.showInputDialog(frame, "Enter Weighted Key", "Weighted Key",
            JOptionPane.QUESTION_MESSAGE);

    Transformer<String, Double> wtTransformer = new Transformer<String, Double>() {
        public Double transform(String edgeId) {

            return null;
        }//w ww  .j  a v a  2s .co  m
    };

    final Graph<String, String> mGraph = viewerPanel.getCurrentGraph();
    DijkstraShortestPath<String, String> alg = new DijkstraShortestPath(mGraph, wtTransformer);

    final List<String> mPred = alg.getPath(mFrom, mTo);
    //        System.out.println("The shortest unweighted path from" + mFrom +" to " + mTo + " is:");
    //        System.out.println(mPred.toString());

    if (mPred == null) {
        JOptionPane.showMessageDialog(frame,
                String.format("Shortest path between %s,%s is not found", mFrom, mTo), "Message",
                JOptionPane.INFORMATION_MESSAGE);
        return;
    }

    final Layout<String, String> layout = vv.getGraphLayout();
    for (final String edge : layout.getGraph().getEdges()) {
        if (mPred.contains(edge)) {
            vv.setEdgeStroke(edge, new BasicStroke(4f));

        }

    }
}

From source file:ca.nines.ise.util.TextReplacementTable.java

public String[] getSources() {
    String sources[] = table.keySet().toArray(new String[table.size()]);
    Arrays.sort(sources);
    return sources;
}

From source file:com.liferay.ci.http.JSONBuildUtil.java

public static ContinuousIntegrationJob[] getLastBuilds(AuthConnectionParams connectionParams,
        ContinuousIntegrationJob... jobs) throws IOException, JSONException {

    ContinuousIntegrationJob[] result = new ContinuousIntegrationJob[jobs.length];

    System.arraycopy(jobs, 0, result, 0, jobs.length);

    for (int i = 0; i < result.length; i++) {
        String jobAccount = result[i].getAccount();
        String jobName = result[i].getRealJobName();
        String jobAlias = result[i].getJobAlias();

        ContinuousIntegrationBuild lastBuild = getLastBuild(connectionParams, jobAccount, jobName);

        if (lastBuild.getStatus() == TravisIntegrationConstants.TRAVIS_BUILD_STATUS_FAILED) {

            result[i] = new ContinuousIntegrationUnstableJob(jobAccount, jobName, jobAlias,
                    lastBuild.getStatus());
        } else {//from ww w .j a  va  2  s . c om
            result[i] = new ContinuousIntegrationJob(jobAccount, jobName, jobAlias, lastBuild.getStatus());
        }
    }

    // sort jobs by status

    Arrays.sort(result);

    return result;
}

From source file:com.hydroLibCreator.action.Creator.java

private void setSortedAudioFileslist() {

    this.audioFileslist = sourceDir.list();

    FilenameFilter filter = new FilenameFilter() {
        @Override/* w w  w .  jav  a  2  s.  co  m*/
        public boolean accept(File dir, String name) {
            return false;
        }
    };

    if (audioFileslist == null || audioFileslist.length == -1)
        throw new ApplicationException("Missing Audio Files Exception",
                "Please make sure your directory has audio files");

    Arrays.sort(audioFileslist);

}

From source file:de.uni.bremen.monty.moco.util.MontyFile.java

@Override
public MontyResource[] listSubPackages() {
    File[] files = listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);
    MontyResource[] montyResources = convertAllFiles(files);
    Arrays.sort(montyResources);
    return montyResources;
}

From source file:edu.umn.cs.spatialHadoop.operations.ConvexHull.java

/**
 * Computes the convex hull of a set of points using a divide and conquer
 * in-memory algorithm. This function implements Andrew's modification to
 * the Graham scan algorithm.//from   www  .  j ava2  s  .  c  o m
 * 
 * @param points
 * @return
 */
public static <P extends Point> P[] convexHullInMemory(P[] points) {
    Stack<P> s1 = new Stack<P>();
    Stack<P> s2 = new Stack<P>();

    Arrays.sort(points);

    // Lower chain
    for (int i = 0; i < points.length; i++) {
        while (s1.size() > 1) {
            P p1 = s1.get(s1.size() - 2);
            P p2 = s1.get(s1.size() - 1);
            P p3 = points[i];
            double crossProduct = (p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x);
            if (crossProduct <= 0)
                s1.pop();
            else
                break;
        }
        s1.push(points[i]);
    }

    // Upper chain
    for (int i = points.length - 1; i >= 0; i--) {
        while (s2.size() > 1) {
            P p1 = s2.get(s2.size() - 2);
            P p2 = s2.get(s2.size() - 1);
            P p3 = points[i];
            double crossProduct = (p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x);
            if (crossProduct <= 0)
                s2.pop();
            else
                break;
        }
        s2.push(points[i]);
    }

    s1.pop();
    s2.pop();
    s1.addAll(s2);
    return s1.toArray((P[]) Array.newInstance(s1.firstElement().getClass(), s1.size()));
}

From source file:com.mrfeinberg.translation.AbstractTranslationService.java

public Language[] getSupportedLanguages() {
    final Language[] langs = supportedLanguages.toArray(new Language[0]);
    Arrays.sort(langs);
    return langs;
}