Example usage for java.util ArrayList toArray

List of usage examples for java.util ArrayList toArray

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public <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:adalid.commons.properties.PropertiesHandler.java

private static File[] velocityFolders() {
    File file;//w  w  w  .ja v a2s. c om
    ArrayList<File> files = new ArrayList<>();
    file = new File(USER_VELOCITY_RESOURCES_DIR);
    if (FilUtils.isVisibleDirectory(file)) {
        files.add(file);
    }
    String pathnames[] = getPathArray(VELOCITY_FOLDER_KEY);
    if (pathnames != null && pathnames.length > 0) {
        for (String pathname : pathnames) {
            file = new File(pathname);
            if (FilUtils.isVisibleDirectory(file)) {
                files.add(file);
            } else {
                logInvalidDirectory(VELOCITY_FOLDER_KEY, pathname);
            }
        }
    }
    if (files.isEmpty()) {
        logMissingProperty(VELOCITY_FOLDER_KEY);
        return null;
    }
    return files.toArray(new File[0]);
}

From source file:jp.ambrosoli.quickrestclient.apache.headers.ApacheHeaderBuilder.java

public Header[] createConformedHeaders(final List<NameValueObject> headers) {
    if (headers == null || headers.isEmpty()) {
        return null;
    }//from  w  w w .ja va  2  s. co  m

    ArrayList<Header> headerList = new ArrayList<Header>();
    for (NameValueObject nvo : headers) {
        if (nvo != null) {
            BasicHeader header = new BasicHeader(nvo.getName(), nvo.getValue());
            headerList.add(header);
        }
    }

    return headerList.toArray(new Header[headerList.size()]);
}

From source file:classif.kmedoid.KMedoidsSymbolicSequence.java

public Sequence[] getCenters() {
    ArrayList<Sequence> centers = new ArrayList<>();

    for (int i = 0; i < indexMedoids.length; i++) {
        if (indexMedoids[i] != -1) {
            centers.add(data.get(indexMedoids[i]));
        }//w  ww  .  ja v  a 2s  .  c o m
    }

    return centers.toArray(new Sequence[] {});
}

From source file:org.apache.lucene.replicator.http.ReplicationService.java

/**
 * Returns the path elements that were given in the servlet request, excluding
 * the servlet's action context./*from  ww  w  .j a va2 s  .  co m*/
 */
private String[] getPathElements(HttpServletRequest req) {
    String path = req.getServletPath();
    String pathInfo = req.getPathInfo();
    if (pathInfo != null) {
        path += pathInfo;
    }
    int actionLen = REPLICATION_CONTEXT.length();
    int startIdx = actionLen;
    if (path.length() > actionLen && path.charAt(actionLen) == '/') {
        ++startIdx;
    }

    // split the string on '/' and remove any empty elements. This is better
    // than using String.split() since the latter may return empty elements in
    // the array
    StringTokenizer stok = new StringTokenizer(path.substring(startIdx), "/");
    ArrayList<String> elements = new ArrayList<>();
    while (stok.hasMoreTokens()) {
        elements.add(stok.nextToken());
    }
    return elements.toArray(new String[0]);
}

From source file:com.digitalpebble.stormcrawler.Metadata.java

public void addValues(String key, Collection<String> values) {
    if (values == null || values.size() == 0)
        return;/*from  w ww .ja  v a2  s  .c  o  m*/
    String[] existingvals = md.get(key);
    if (existingvals == null) {
        md.put(key, values.toArray(new String[values.size()]));
        return;
    }

    ArrayList<String> existing = new ArrayList<>(existingvals.length + values.size());
    for (String v : existingvals)
        existing.add(v);

    existing.addAll(values);
    md.put(key, existing.toArray(new String[existing.size()]));
}

From source file:com.dsh105.commodus.config.Option.java

public Option(FileConfiguration configuration, String path, String... comments) {
    this.config = configuration;
    this.path = path;

    ArrayList<String> commentsList = new ArrayList<>();
    for (String comment : comments) {
        Collections.addAll(commentsList, WordUtils.wrap(comment, 30, "\n", false).split("\n"));
    }/*from   w w  w  .  jav  a  2  s .  c  o  m*/
    this.comments = commentsList.toArray(new String[commentsList.size()]);
}

From source file:configuration.Cluster.java

/**
 * Test if the output is here path is a Unix path
 * Added by JG 2017/* w  ww. j  a v a 2s.  c o  m*/
 * @param 
 * @return true or false
 */
public static boolean downloadResults(workflow_properties properties) {
    if (isP2RsaHere()) {
        Enumeration<Object> e = properties.keys();
        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();
            if (key.contains("ClusterLocalOutput_")) {
                String fLoc = "";
                if (isDocker(properties)) {
                    fLoc = restoreLocalDocker(properties.get(key))[0];
                } else {
                    fLoc = properties.get(key);
                }
                String fDir = fLoc;
                if (Util.testIfFile(fLoc))
                    fDir = Util.getParentOfFile(fLoc);
                String clusterDir = properties.get("ClusterDirPath");
                String fClus = clusterDir + "/outputs/";
                ArrayList<String> tab = runSshCommand(properties, "ls " + fClus);
                if (tab.size() >= 2 && !tab.get(0).contains("ls")) {
                    tab.remove(tab.size() - 1);
                    for (int i = 0; i < tab.size(); i++) {
                        tab.set(i, fClus + tab.get(i));
                    }
                    String[] tabTmp = tab.toArray(new String[tab.size()]);
                    boolean b2 = runDownloadDir(properties, fDir, tabTmp);
                    if (!b2) {
                        return false;
                    }
                } else {
                    return false;
                }
            }
        }
        return true;
    }
    return false;
}

From source file:com.verigreen.common.spring.SpringContextLoader.java

private String[] generateConfigLocations(List<String> additionalLocations) {

    String[] ecLocations = getLocationsToLoad();

    int size = ecLocations.length + additionalLocations.size();
    ArrayList<String> newLocations = new ArrayList<>(size);
    Collections.addAll(newLocations, ecLocations);

    // this line needs to be at the end so that any mock contexts will override normal contexts
    newLocations.addAll(additionalLocations);

    return newLocations.toArray(new String[size]);
}

From source file:de.mpg.escidoc.services.reporting.ReportFHI.java

/**
 * Generate month report files (formats are specified in properties)
 * @throws JRException//from w  w w. j  a v a  2 s .c om
 * @return list of paths to the generated reports 
 */
public static String[] generateReport() throws JRException {

    String[] formats = rprops.getProperty("FHI.report.formats").split(",");

    //GET REPORT FROM JRXMLs
    //compile subreports
    //       JasperCompileManager.compileReportToFile("src/main/resources/subreport_creators.jrxml");

    //get main report
    JasperReport jr = null;
    JasperDesign jd;
    jd = JRXmlLoader.load(JRLoader.getLocationInputStream("FHI_Bibilothek_report.jrxml"));
    jr = JasperCompileManager.compileReport(jd);
    if (jr == null) {
        throw new RuntimeException("Compiled report is null: " + "FHI_Bibilothek_report.jrxml");
    }

    Document doc = getXmlDataSource();

    Map<String, Object> params = new HashMap<String, Object>();
    params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, doc);

    //fill report in memory
    JasperPrint jasperPrint;
    jasperPrint = JasperFillManager.fillReport(jr, params, new JRXmlDataSource(doc, jr.getQuery().getText()));

    ArrayList<String> atts = new ArrayList<String>();
    String fn;
    //save in files in formats
    for (String f : formats) {
        if ("pdf".equalsIgnoreCase(f)) {
            JRPdfExporter pdfExp = new JRPdfExporter();
            pdfExp.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
            fn = "FHI_Bibilothek_report.pdf";
            pdfExp.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, fn);
            pdfExp.exportReport();
            atts.add(fn);
        } else if ("rtf".equalsIgnoreCase(f)) {
            JRRtfExporter rtfExp = new JRRtfExporter();
            rtfExp.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
            fn = "FHI_Bibilothek_report.rtf";
            rtfExp.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, fn);
            rtfExp.exportReport();
            atts.add(fn);
        }
    }

    return atts.toArray(new String[atts.size()]);

}

From source file:sample.portlet.MyBooksEditController.java

private void storeMyBooks(PortletRequest request, SortedSet<Book> myBooks) {

    ArrayList<String> keys = new ArrayList<String>();
    for (Iterator<Book> i = myBooks.iterator(); i.hasNext();) {
        Book book = i.next();/*from  ww w  .  java 2 s. c  om*/
        keys.add(book.getKey().toString());
    }

    String[] keysArr = keys.toArray(new String[] {});

    try {
        PortletPreferences prefs = request.getPreferences();
        prefs.setValues("myBooks", keysArr);
        prefs.store();
    } catch (Exception e) {
        logger.warn("unable to set portlet preference", e);
    }
}