Example usage for java.util List toArray

List of usage examples for java.util List toArray

Introduction

In this page you can find the example usage for java.util List toArray.

Prototype

<T> T[] toArray(T[] a);

Source Link

Document

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.

Usage

From source file:lucee.commons.io.res.util.ResourceClassLoader.java

/**
 * translate resources to url Objects/*from w  ww  .  j a v a  2s.  c  o  m*/
 * @param reses
 * @return
 * @throws PageException
 */
public static URL[] doURLs(Resource[] reses) throws IOException {
    List<URL> list = new ArrayList<URL>();
    for (int i = 0; i < reses.length; i++) {
        if (reses[i].isDirectory() || "jar".equalsIgnoreCase(ResourceUtil.getExtension(reses[i], null)))
            list.add(doURL(reses[i]));
    }
    return list.toArray(new URL[list.size()]);

}

From source file:dias.DIAS.java

public static boolean configureSession() {
    boolean output = false; //be pessimistic. 
    Configurations configs = new Configurations();
    try {//from w ww. ja  va2 s  .  co  m
        XMLConfiguration config = configs.xml("config/configuration.xml"); //this is a really nice factory implementation we're eliding
        //use XPATH so we can query attributes. NB that this means we'll be using slash-style lookup as in 
        // "processing/paths/excelFilePath" 
        // instead of 
        // "processing.paths.excelFilePath"
        config.setExpressionEngine(new XPathExpressionEngine());
        configurationEnvironment = config.getString("environment/env");
        verboseMode = Boolean.valueOf(config.getString("environment/verbose"));
        if (verboseMode) {
            System.out.println("User directory is " + System.getProperty("user.dir"));
        }
        if (verboseMode) {
            System.out.println(configurationEnvironment);
        }
        excelFilePath = config
                .getString("processing[@env='" + configurationEnvironment + "']/paths/excelFilePath");
        bodymediaFileUrl = config
                .getString("processing[@env='" + configurationEnvironment + "']/paths/bodymediaFileUrl");
        //HierarchicalConfiguration node = (HierarchicalConfiguration) config.configurationAt("/nodes/node[@id='"+(str)+"']");
        List<String> emails = config.getList(String.class,
                "processing[@env='" + configurationEnvironment + "']/emails/email");
        privateMails = new String[emails.size()];
        privateMails = emails.toArray(privateMails);
        output = true;
    } catch (ConfigurationException cex) {
        //Something went wrong; we should probably check to see if the configuration file wasn't found, 
        // but otherwise just keep the output as false.
        System.out.println(cex.getMessage());
    }
    return output;
}

From source file:net.sf.jabref.model.DuplicateCheck.java

/**
 * Checks if the two entries represent the same publication.
 *
 * @param one BibEntry//w  w  w .  ja va  2  s .  c  o  m
 * @param two BibEntry
 * @return boolean
 */
public static boolean isDuplicate(BibEntry one, BibEntry two, BibDatabaseMode bibDatabaseMode) {

    // First check if they are of the same type - a necessary condition:
    if (!one.getType().equals(two.getType())) {
        return false;
    }
    EntryType type = EntryTypes.getTypeOrDefault(one.getType(), bibDatabaseMode);

    // The check if they have the same required fields:
    java.util.List<String> var = type.getRequiredFieldsFlat();
    String[] fields = var.toArray(new String[var.size()]);
    double[] req;
    if (fields == null) {
        req = new double[] { 0., 0. };
    } else {
        req = DuplicateCheck.compareFieldSet(fields, one, two);
    }

    if (Math.abs(req[0] - DuplicateCheck.duplicateThreshold) > DuplicateCheck.DOUBT_RANGE) {
        // Far from the threshold value, so we base our decision on the req. fields only
        return req[0] >= DuplicateCheck.duplicateThreshold;
    }
    // Close to the threshold value, so we take a look at the optional fields, if any:
    java.util.List<String> optionalFields = type.getOptionalFields();
    fields = optionalFields.toArray(new String[optionalFields.size()]);
    if (fields != null) {
        double[] opt = DuplicateCheck.compareFieldSet(fields, one, two);
        double totValue = ((DuplicateCheck.REQUIRED_WEIGHT * req[0] * req[1]) + (opt[0] * opt[1]))
                / ((req[1] * DuplicateCheck.REQUIRED_WEIGHT) + opt[1]);
        return totValue >= DuplicateCheck.duplicateThreshold;
    }
    return req[0] >= DuplicateCheck.duplicateThreshold;
}

From source file:com.htmlhifive.tools.jslint.util.ConfigBeanUtil.java

/**
 * ???????????.//w w  w . j av  a  2  s  .co  m
 * 
 * @param options ?
 * @param clazz .
 * @return ?.
 */
private static CheckOption[] pickUpOption(CheckOption[] options, Class<?> clazz) {

    List<CheckOption> optionList = new ArrayList<CheckOption>();
    for (CheckOption option : options) {
        if (option.getClazz() == clazz) {
            optionList.add(option);
        }
    }
    return (CheckOption[]) optionList.toArray(new CheckOption[optionList.size()]);
}

From source file:hsyndicate.hadoop.utils.DFSNodeInfoUtils.java

public static String[] getDataNodes(Configuration conf) throws IOException {
    List<String> datanodes = new ArrayList<String>();
    DFSClient client = new DFSClient(NameNode.getAddress(conf), conf);
    DatanodeInfo[] datanodeReport = client.datanodeReport(HdfsConstants.DatanodeReportType.LIVE);
    for (DatanodeInfo nodeinfo : datanodeReport) {
        datanodes.add(nodeinfo.getHostName().trim());
    }/*from w w  w.j av a 2s  .  c  o m*/

    return datanodes.toArray(new String[0]);
}

From source file:Main.java

public static Node[] getChildNodesByName(Element parent, String name) {
    List<Node> nodeList = new ArrayList<Node>();

    NodeList childNodes = parent.getChildNodes();
    int length = childNodes.getLength();
    for (int i = 0; i < length; i++) {
        Node current = childNodes.item(i);
        if (current.getNodeName().equals(name))
            nodeList.add(current);// w w  w . j  a v a 2  s  . c  o  m
    }

    Node[] nodes = new Node[nodeList.size()];
    nodeList.toArray(nodes);
    return nodes;
}

From source file:Main.java

public static Node[] findChildren(Node node, String name) {
    List<Node> list = new ArrayList<Node>();
    NodeList childNodes = node.getChildNodes();
    int count = childNodes.getLength();
    for (int i = 0; i < count; i++) {
        Node child = childNodes.item(i);
        if (child instanceof Element && (name == null || child.getNodeName().equals(name))) {
            list.add(child);/*from w ww. j  a va  2s  . c  om*/
        }
    }
    return list.toArray(new Node[list.size()]);
}

From source file:de.laeubisoft.tools.ant.validation.Tools.java

/**
 * Creates a {@link RequestEntity} that can be used for submitting a file
 * //www  .j a  va  2s  . c  o  m
 * @param params
 *            the params to use
 * @param methodParams
 *            the {@link HttpMethodParams} of the requesting method
 * @return {@link RequestEntity} that can be used for submitting the given
 *         file via Multipart
 * @throws IOException
 *             if something is wrong with the file...
 */
public static RequestEntity createFileUpload(File file, String filePartName, String charset,
        List<NameValuePair> params, HttpMethodParams methodParams) throws IOException {
    if (file == null) {
        throw new FileNotFoundException("file not present!");
    }
    List<Part> parts = nvToParts(params);
    FilePart fp = new FilePart(filePartName, file);
    fp.setContentType(URLConnection.guessContentTypeFromName(file.getName()));
    if (charset != null) {
        fp.setCharSet(charset);
    }
    parts.add(fp);
    return new MultipartRequestEntity(parts.toArray(new Part[0]), methodParams);
}

From source file:edu.msu.cme.rdp.kmer.KmerFilter.java

private static void processSeq(Sequence querySeq, List<String> refLabels, KmerTrie kmerTrie,
        KmerStartsWriter out, int wordSize, boolean translQuery, int translTable, boolean reverse)
        throws IOException {

    String seqString = querySeq.getSeqString();

    if (reverse) {
        seqString = IUBUtilities.reverseComplement(seqString);
    }/*from   w  w w. j  av a2  s . c  o m*/

    List<char[]> tmpKmerList = KmerGenerator.getKmers(seqString, wordSize);
    char[][] kmers = tmpKmerList.toArray(new char[tmpKmerList.size()][]);
    char[][][] protKmers = null;

    if (translQuery) {
        protKmers = new char[3][][];
        for (int i = 0; i < 3; i++) {
            String frameSeq = seqString.substring(i);
            //System.out.println(frameSeq);
            frameSeq = ProteinUtils.getInstance().translateToProtein(frameSeq, true, translTable);
            //System.out.println(frameSeq);

            tmpKmerList = KmerGenerator.getKmers(frameSeq, wordSize / 3);
            protKmers[i] = tmpKmerList.toArray(new char[tmpKmerList.size()][]);
        }
    }

    int frame = 0;
    char[] kmer = null;
    char[] protKmer = null;
    TrieLeaf leaf = null;

    for (int kmerIndex = 0; kmerIndex < kmers.length; kmerIndex++) {
        kmer = kmers[kmerIndex];

        if (translQuery) {
            protKmer = null;
            if (protKmers[frame].length > kmerIndex / 3) {
                protKmer = protKmers[frame][kmerIndex / 3];
            }
            if (protKmer == null) {
                System.err.println("Skipping null prot kmer " + kmerIndex + " " + querySeq.getSeqName()
                        + ((kmer != null) ? " " + new String(kmer) : ""));
                continue;
            }
            leaf = kmerTrie.contains(protKmer);
        } else {
            leaf = kmerTrie.contains(kmer);
        }

        if (leaf != null) {
            outputLock.lock();
            try {
                for (Integer refId : leaf.getRefSets()) {
                    for (RefPos refPos : leaf.getModelStarts(refId)) {

                        out.write(new KmerStart(refLabels.get(refId), querySeq.getSeqName(), refPos.seqid,
                                new String(kmer), (reverse ? -(frame + 1) : (frame + 1)), refPos.modelPos,
                                translQuery, (translQuery ? new String(protKmer) : null)));
                    }
                }
            } finally {
                outputLock.unlock();
            }
        }

        frame = ((frame + 1) >= 3) ? 0 : frame + 1;
    }
}

From source file:com.puppetlabs.geppetto.forge.util.TarUtils.java

private static void chmod(Map<File, Map<Integer, List<String>>> chmodMap) throws IOException {
    for (Map.Entry<File, Map<Integer, List<String>>> entry : chmodMap.entrySet())
        for (Map.Entry<Integer, List<String>> dirEntry : entry.getValue().entrySet())
            for (List<String> files : splitList(dirEntry.getValue(), MAX_FILES_PER_COMMAND))
                OsUtil.chmod(entry.getKey(), dirEntry.getKey().intValue(),
                        files.toArray(new String[files.size()]));
}