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.joliciel.frenchTreebank.upload.TreebankXmlReader.java

void addFiles(File file, List<File> files) {
    if (file.isDirectory()) {
        File[] fileArray = file.listFiles();
        Arrays.sort(fileArray);
        for (File oneFile : fileArray) {
            this.addFiles(oneFile, files);
        }//from  w  w w .ja v a2 s  .  co m
    } else if (file.getName().endsWith(".xml")) {
        files.add(file);
    }
}

From source file:net.sf.taverna.t2.activities.wsdl.xmlsplitter.XMLSplitterConfigurationBeanBuilder.java

public static JsonNode buildBeanForInput(Element element) throws JDOMException, IOException {
    ObjectNode bean = JSON_NODE_FACTORY.objectNode();
    ArrayNode inputDefinitions = bean.arrayNode();
    bean.put("inputPorts", inputDefinitions);
    ArrayNode outputDefinitions = bean.arrayNode();
    bean.put("outputPorts", outputDefinitions);

    TypeDescriptor descriptor = XMLSplitterSerialisationHelper.extensionXMLToTypeDescriptor(element);
    ObjectNode outBean = outputDefinitions.addObject();
    outBean.put("name", "output");
    outBean.put("mimeType", "'text/xml'");
    outBean.put("depth", 0);
    outBean.put("granularDepth", 0);

    if (descriptor instanceof ComplexTypeDescriptor) {
        List<TypeDescriptor> elements = ((ComplexTypeDescriptor) descriptor).getElements();
        String[] names = new String[elements.size()];
        Class<?>[] types = new Class<?>[elements.size()];
        TypeDescriptor.retrieveSignature(elements, names, types);
        for (int i = 0; i < names.length; i++) {
            ObjectNode portBean = inputDefinitions.addObject();
            portBean.put("name", names[i]);
            portBean.put("mimeType", TypeDescriptor.translateJavaType(types[i]));
            portBean.put("depth", depthForDescriptor(elements.get(i)));
        }//from w ww  .j  av  a  2  s  .  co m

        List<TypeDescriptor> attributes = ((ComplexTypeDescriptor) descriptor).getAttributes();
        String[] elementNames = Arrays.copyOf(names, names.length);
        Arrays.sort(elementNames);
        String[] attributeNames = new String[attributes.size()];
        Class<?>[] attributeTypes = new Class<?>[attributes.size()];
        TypeDescriptor.retrieveSignature(attributes, attributeNames, attributeTypes);
        for (int i = 0; i < attributeNames.length; i++) {
            ObjectNode portBean = inputDefinitions.addObject();
            if (Arrays.binarySearch(elementNames, attributeNames[i]) < 0) {
                portBean.put("name", attributeNames[i]);
            } else {
                portBean.put("name", "1" + attributeNames[i]);
            }
            portBean.put("mimeType", TypeDescriptor.translateJavaType(attributeTypes[i]));
            portBean.put("depth", depthForDescriptor(attributes.get(i)));
        }

    } else if (descriptor instanceof ArrayTypeDescriptor) {
        ObjectNode portBean = inputDefinitions.addObject();
        portBean.put("name", descriptor.getName());

        if (((ArrayTypeDescriptor) descriptor).getElementType() instanceof BaseTypeDescriptor) {
            portBean.put("mimeType", "l('text/plain')");
        } else {
            portBean.put("mimeType", "l('text/xml')");
        }
        portBean.put("depth", 1);
    }

    String wrappedType = new XMLOutputter().outputString(element);
    bean.put("wrappedType", wrappedType);

    return bean;
}

From source file:com.microsoft.tfs.core.clients.build.internal.soapextensions.BuildInformation.java

/**
 * Creates a top-level build information node collection for a BuildDetail
 * object and initializes it from an array of BuildInformation objects.
 *
 *
 * @param build/* w  w w  .j av a2 s  .c o  m*/
 *        The owner of this collection.
 * @param informationNodes
 *        The BuildInformation objects from which the tree is initialized.
 */
public BuildInformation(final BuildDetail build, final BuildInformationNode[] informationNodes) {
    this(build, (BuildInformationNode) null);

    // No information nodes - nothing to do.
    if (informationNodes.length > 0) {
        final Map<Integer, Map<Integer, BuildInformationNode>> nodeParentDict = new HashMap<Integer, Map<Integer, BuildInformationNode>>();
        Map<Integer, BuildInformationNode> children;

        for (final BuildInformationNode node : informationNodes) {
            // Add node to parent node dictionary.
            children = nodeParentDict.get(node.getParentID());
            if (children == null) {
                children = new HashMap<Integer, BuildInformationNode>();
                nodeParentDict.put(node.getParentID(), children);
            }

            node.setBuild(build);

            if (!children.containsKey(node.getID())) {
                children.put(node.getID(), node);
            } else {
                log.warn("Duplicate information nodes present in a build!"); //$NON-NLS-1$
            }
        }

        // Build up as much of the tree structure as we can manage.
        for (final BuildInformationNode node : informationNodes) {
            children = nodeParentDict.get(node.getID());
            if (children != null) {
                final BuildInformation theChildren = (BuildInformation) node.getChildren();

                final Collection<BuildInformationNode> values = children.values();
                final BuildInformationNode[] array = values.toArray(new BuildInformationNode[values.size()]);
                Arrays.sort(array);

                for (final BuildInformationNode child : array) {
                    child.setParent(node);
                    child.setOwner(theChildren);
                    theChildren.add(child);
                }
            }
        }

        // Add any unparented nodes as top level nodes.
        for (final BuildInformationNode node : informationNodes) {
            if (node.getParent() == null) {
                node.setOwner(this);
                add(node);
            }
        }
    }
}

From source file:ca.nines.ise.cmd.Command.java

/**
 * Get a list of file paths from the command line arguments.
 *
 * @param cmd//from   ww w. j  ava  2  s .c  om
 * @return File[]
 */
public File[] getFilePaths(CommandLine cmd) {
    Collection<File> fileList = new ArrayList<>();

    List<?> argList = cmd.getArgList();
    argList = argList.subList(1, argList.size());
    String[] args = argList.toArray(new String[argList.size()]);

    if (argList.isEmpty()) {
        File dir = new File("input");
        SuffixFileFilter sfx = new SuffixFileFilter(".txt");
        fileList = FileUtils.listFiles(dir, sfx, TrueFileFilter.INSTANCE);
    } else {
        for (String name : args) {
            fileList.add(new File(name));
        }
    }

    File[] files = fileList.toArray(new File[fileList.size()]);
    Arrays.sort(files);
    return files;
}

From source file:edu.rice.cs.bioinfo.programs.phylonet.algos.network.NetworkPseudoLikelihoodFromGTT.java

public static Map<String, double[]> computeTripleFrequenciesFromSingleGT(Tree gt) {
    List<String> taxaList = new ArrayList<>();
    Map<String, Integer> pairwiseDepths = new HashMap<>();
    Map<TNode, Integer> node2depth = new HashMap<>();
    Map<TNode, List<String>> node2leaves = new HashMap<>();
    for (TNode node : gt.postTraverse()) {
        int depth = 0;
        List<String> leaves = new ArrayList<>();
        if (node.isLeaf()) {
            //leaves.add(taxon2ID.get(node.getName()));
            leaves.add(node.getName());//from w w  w. j a v  a2  s  . c o  m
            taxaList.add(node.getName());
        } else {
            List<List<String>> childLeavesList = new ArrayList<>();
            for (TNode child : node.getChildren()) {
                depth = Math.max(depth, node2depth.get(child));
                List<String> childLeaves = new ArrayList<>();
                childLeaves.addAll(node2leaves.get(child));
                childLeavesList.add(childLeaves);
                leaves.addAll(childLeaves);
            }
            depth++;
            for (int i = 0; i < childLeavesList.size(); i++) {
                List<String> childLeaves1 = childLeavesList.get(i);
                for (int j = i + 1; j < childLeavesList.size(); j++) {
                    List<String> childLeaves2 = childLeavesList.get(j);
                    for (String leaf1 : childLeaves1) {
                        for (String leaf2 : childLeaves2) {
                            pairwiseDepths.put(leaf1 + "&" + leaf2, depth);
                            pairwiseDepths.put(leaf2 + "&" + leaf1, depth);
                        }
                    }
                }

            }

        }
        node2depth.put(node, depth);
        node2leaves.put(node, leaves);
    }

    String[] taxa = taxaList.toArray(new String[0]);
    Arrays.sort(taxa);
    int numTaxa = taxa.length;
    Map<String, double[]> triple2counts = new HashMap<>();

    for (int i = 0; i < numTaxa; i++) {
        String taxonI = taxa[i];
        for (int j = i + 1; j < numTaxa; j++) {
            String taxonJ = taxa[j];
            String pair = taxonI + "&" + taxonJ;
            int ij = pairwiseDepths.get(pair);
            for (int k = j + 1; k < numTaxa; k++) {
                String taxonK = taxa[k];
                String triplet = pair + "&" + taxonK;
                double[] freq = new double[3];
                triple2counts.put(triplet, freq);
                int minIndex = -1;
                int ik = pairwiseDepths.get(taxonI + "&" + taxonK);
                int jk = pairwiseDepths.get(taxonJ + "&" + taxonK);
                if (ij < ik && ij < jk) {
                    minIndex = 0;
                } else if (ik < ij && ik < jk) {
                    minIndex = 1;
                } else if (jk < ij && jk < ik) {
                    minIndex = 2;
                }
                if (minIndex != -1) {
                    freq[minIndex] = 1;
                } else {

                    for (int m = 0; m < 3; m++) {
                        freq[m] = 1 / 3.0;
                    }
                }
            }
        }
    }

    return triple2counts;
}

From source file:com.espertech.esper.event.vaevent.PropertyUtility.java

/**
 * From a list of property groups that include multiple group numbers for each property,
 * make a map of group numbers per property.
 * @param groups property groups//from   w  w  w.j ava 2  s  . c o m
 * @return map of property name and group number
 */
public static Map<String, int[]> getGroupsPerProperty(PropertyGroupDesc[] groups) {
    Map<String, int[]> groupsNumsPerProp = new HashMap<String, int[]>();
    for (PropertyGroupDesc group : groups) {
        for (String property : group.getProperties()) {
            int[] value = groupsNumsPerProp.get(property);
            if (value == null) {
                value = new int[1];
                groupsNumsPerProp.put(property, value);
                value[0] = group.getGroupNum();
            } else {
                int[] copy = new int[value.length + 1];
                System.arraycopy(value, 0, copy, 0, value.length);
                copy[value.length] = group.getGroupNum();
                Arrays.sort(copy);
                groupsNumsPerProp.put(property, copy);
            }
        }
    }
    return groupsNumsPerProp;
}

From source file:geva.Util.Statistics.IndividualCatcher.java

/**
 * Add the population to a StringBuffer. geva.Individuals are taken according to catchInterval
 * @param population Population/*from  www.  ja va2s .  c  o  m*/
 */

public void addPop(List<Individual> population) {
    Fitness[] fA = new Fitness[population.size()];
    for (int i = 0; i < fA.length; i++) {
        fA[i] = population.get(i).getFitness();
    }
    //Sort ascending
    Arrays.sort(fA);
    int cnt = 0;
    while (cnt < fA.length) {
        sb.append("Rank:").append(cnt).append(" Fit:").append(fA[cnt].getDouble());
        sb.append(" Phenotype:").append(fA[cnt].getIndividual().toString());
        sb.append(System.getProperty("line.separator"));
        cnt += this.catchInterval;
    }
}

From source file:com.ery.dimport.daemon.MasterStatusServlet.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    DaemonMaster master = (DaemonMaster) getServletContext().getAttribute(DaemonMaster.MASTER);
    assert master != null : "No Master in context!";
    doCheckMaster(request, response);//  w ww  .j a v  a 2  s .com
    Configuration conf = master.getConfiguration();
    Map<String, HostInfo> servers = master.getBackMasterTracker().getOnlineServers();// backMasters
    Map<String, HostInfo> deadServs = master.getServerManager().getDeadServers();
    PrintWriter out = response.getWriter();
    response.setContentType("text/html");

    TaskManager assign = master.getTaskManager();

    out.println("<html>");
    out.println("<head>");
    out.println("<meta HTTP-EQUIV='REFRESH' content='5;url=/master'/>");
    out.println("<script type='text/javascript'> ");
    out.println("function ensureInt(n) {\n var isInt = /^\\d+$/.test(n);"
            + "if (!isInt) {\n alert(\"'\" + n + \"' is not integer.\");}\n  return isInt;\n}");
    out.println("</script>");

    out.println("</head>");
    out.println("<body>");
    out.println("<center>Dimport Master Info</center><br/>");
    out.println("<hr/>");
    out.println("Active Master<br/>");
    out.println(master.getActiveMaster());
    out.println("<br/>");
    out.println("<a href='/order'>submit task</a>");
    out.println("<hr/>");
    out.println("Task Masters<br/>");
    List<String> server = new ArrayList<String>(servers.keySet());
    String servs[] = server.toArray(new String[0]);
    Arrays.sort(servs);
    for (String serv : servs) {
        out.println(servers.get(serv));
        out.println("=================servStatus=");
        out.println("<br/>");
    }

    out.println("<hr/>");
    out.println("dead Masters<br/>");
    if (deadServs.size() > 0) {
        for (String serv : deadServs.keySet()) {
            out.println(deadServs.get(serv));
            out.println("<br/>");
        }
    }

    out.println("<hr/>");
    // ?
    out.print("<B>ALL Running task</B>");
    out.print("<pre> TASK_ID");
    out.print(" TASK_NAME");
    out.print(" IS_ALL_SUCCESS");
    out.print(" FILE_PATH");
    out.print(" FILE_FILTER");
    out.print(" TASK_COMMAND");
    out.println("</pre> ");
    for (String taskId : assign.allTask.keySet()) {
        TaskInfo taskInfo = assign.allTask.get(taskId);
        out.print("<pre> " + taskInfo.toString().replaceAll("\n", "\\n"));
        out.println("</pre> <input type=button value='STOP' onclick='window.open( \"/order?order=stop&taskId="
                + taskInfo.TASK_ID + "\")' />");
    }
    // allTaskInfo ??????
    out.println("<hr/>");
    out.println("<B>TASK HSOT FILE RUNNING INFO</B><hr/>");
    for (String taskId : assign.allTaskInfo.keySet()) {
        Map<String, List<LogHostRunInfoPO>> map = assign.allTaskInfo.get(taskId);
        TaskInfo taskInfo = assign.allTask.get(taskId);
        if (taskInfo == null)
            continue;
        int runEndSize = 0;
        int runningSize = 0;
        HashMap<String, String> hostSum = new HashMap<String, String>();

        List<String> mapHost = new ArrayList<String>(map.keySet());
        String mhosts[] = mapHost.toArray(new String[0]);
        Arrays.sort(mhosts);
        for (String host : mhosts) {
            boolean isRunEnd = true;
            int failedFileSize = 0;
            int sucFileSize = 0;
            int waitingFileSize = 0;
            int runFileSize = 0;
            List<LogHostRunInfoPO> files = map.get(host);
            for (LogHostRunInfoPO logHostRunInfoPO : files) {
                if (logHostRunInfoPO.IS_RUN_SUCCESS != 1
                        || logHostRunInfoPO.END_TIME.getTime() < logHostRunInfoPO.START_TIME.getTime()) {
                    isRunEnd = false;
                }
                if (logHostRunInfoPO.START_TIME.getTime() > 100000) {
                    if (logHostRunInfoPO.RETURN_CODE == 0) {// runed suc
                        sucFileSize++;
                    } else if (logHostRunInfoPO.END_TIME.getTime() > logHostRunInfoPO.START_TIME.getTime()) {
                        failedFileSize++;
                    } else {// running
                        runFileSize++;
                    }
                } else if (logHostRunInfoPO.IS_RUN_SUCCESS != 1) {// wait
                    waitingFileSize++;
                }
            }
            hostSum.put(host, "suc[" + sucFileSize + "],fail[" + failedFileSize + "],run[" + runFileSize
                    + "],wait[" + waitingFileSize + "]");
            if (isRunEnd) {
                runEndSize++;
            }
            if (files.size() > sucFileSize + failedFileSize + waitingFileSize)
                runningSize++;
        }
        String waitHost = "";
        String thosts[] = taskInfo.hosts.toArray(new String[0]);
        Arrays.sort(thosts);
        for (String host : thosts) {
            if (!map.containsKey(host)) {
                waitHost += host + ",";
            }
        }
        out.println("<b>" + taskId + "(all[" + taskInfo.hosts.size() + "],rec[" + map.size() + "],end["
                + runEndSize + "],running[" + runningSize + "],wait[" + waitHost + "])</b><pre>");
        for (String host : mhosts) {
            out.println("<b>" + host + "(" + hostSum.get(host) + ")</b>");
            List<LogHostRunInfoPO> files = map.get(host);
            for (LogHostRunInfoPO logHostRunInfoPO : files) {
                out.println(logHostRunInfoPO);
            }
        }
        out.println("</pre><hr/>");
    }
    out.println("</body></html>");
    out.flush();
    out.close();
}

From source file:ca.nines.ise.document.Corpus.java

/**
 * Return a list of Works, sorted by play code.
 *
 * @return Work[]//  w w w .  j a  v  a  2  s  . c om
 * @throws IOException
 */
public Work[] getWorks() throws IOException {
    File[] dirs = ArrayUtils.addAll(new File(root.getCanonicalFile() + "/noTitlePage").listFiles(),
            new File(root.getCanonicalFile() + "/withTitlePage").listFiles());
    for (File d : dirs) {
        File editions[] = d.listFiles(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                return Document.validName(name);
            }
        });
        if (editions.length == 0) {
            continue;
        }
        Work w = new Work(d);
        for (File edition : editions) {
            w.addEdition(edition);
        }
        works.put(d.getName(), w);
    }
    Work[] list = works.values().toArray(new Work[works.size()]);
    Arrays.sort(list);
    return list;
}

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

public static JenkinsJob[] getLastBuilds(AuthConnectionParams connectionParams, String... jobNames)
        throws IOException, JSONException {

    JenkinsJob[] result = new JenkinsJob[jobNames.length];

    for (int i = 0; i < jobNames.length; i++) {
        String fullJobName = jobNames[i];

        String[] jobNameArray = fullJobName.split("\\|");

        String jobName;/*from  w  w w  .  j  a  v a2s.c o  m*/
        String jobAlias;

        if (jobNameArray.length > 2) {
            _log.warn("Job name uses invalidad format: " + fullJobName);

            continue;
        } else if (jobNameArray.length == 2) {
            jobName = jobNameArray[0];
            jobAlias = jobNameArray[1];
        } else {
            jobName = fullJobName;
            jobAlias = fullJobName;
        }

        JenkinsBuild lastBuild = getLastBuild(connectionParams, jobName);

        if (lastBuild.getStatus().equals(JenkinsIntegrationConstants.JENKINS_BUILD_STATUS_UNSTABLE)) {

            result[i] = new JenkinsUnstableJob(jobName, jobAlias, lastBuild.getStatus(),
                    lastBuild.getFailedTests());
        } else {
            result[i] = new JenkinsJob(jobName, jobAlias, lastBuild.getStatus());
        }
    }

    // sort jobs by status

    Arrays.sort(result);

    return result;
}