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:Main.java

public static String[] getTagDataArray(String xmlStr, String xmlRoot) {
    List<String> data = new ArrayList<String>();
    Matcher m;// w w w . java2 s.c o m
    m = Pattern.compile("<" + xmlRoot + ">(.*?)</" + xmlRoot + ">", Pattern.MULTILINE | Pattern.DOTALL)
            .matcher(xmlStr);
    while (m.find()) {
        data.add(xmlToText(m.group(1)));
    }
    return data.toArray(new String[data.size()]);
}

From source file:com.tdclighthouse.prototype.utils.EmailUtils.java

public static String[] parseToAddress(String to) {
    List<String> emails = new ArrayList<String>();
    String[] split = to.split("(\\s*[;,]\\s*)+");
    for (String email : split) {
        if (StringUtils.isNotBlank(email)) {
            emails.add(email);//ww  w.j  a  va  2  s. co  m
        }
    }
    return emails.toArray(new String[emails.size()]);
}

From source file:ConsoleUtils.java

public static Process exec(String exePath, List files, boolean stop) throws InterruptedException, IOException {
    List filePaths = new ArrayList();
    filePaths.add(exePath);/*from   w  w  w.  j a  v  a  2  s  .c  o  m*/
    for (int i = 0; i < files.size(); i++) {
        File file = (File) files.get(i);
        filePaths.add(file.getPath());
    }
    String command[] = (String[]) filePaths.toArray(new String[filePaths.size()]);
    return exec(command, stop);
}

From source file:be.i8c.codequality.sonar.plugins.sag.webmethods.flow.FlowLanguage.java

private static String[] filterEmptyStrings(String[] stringArray) {
    List<String> nonEmptyStrings = new ArrayList<>();
    for (String string : stringArray) {
        if (StringUtils.isNotBlank(string.trim())) {
            nonEmptyStrings.add(string.trim());
        }//  w  w w  .j av a  2s  .  c  o m
    }
    return nonEmptyStrings.toArray(new String[nonEmptyStrings.size()]);
}

From source file:com.netflix.genie.core.jpa.specifications.JpaCommandSpecs.java

/**
 * Get all the clusters given the specified parameters.
 *
 * @param applicationId The id of the application that is registered with these commands
 * @param statuses      The status of the commands
 * @return The specification// w w w  .  j av a 2 s  .  co  m
 */
public static Specification<CommandEntity> findCommandsForApplication(final String applicationId,
        final Set<CommandStatus> statuses) {
    return (final Root<CommandEntity> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) -> {
        final List<Predicate> predicates = new ArrayList<>();
        final Join<CommandEntity, ApplicationEntity> application = root.join(CommandEntity_.applications);

        predicates.add(cb.equal(application.get(ApplicationEntity_.id), applicationId));

        if (statuses != null && !statuses.isEmpty()) {
            final List<Predicate> orPredicates = statuses.stream()
                    .map(status -> cb.equal(root.get(CommandEntity_.status), status))
                    .collect(Collectors.toList());
            predicates.add(cb.or(orPredicates.toArray(new Predicate[orPredicates.size()])));
        }

        return cb.and(predicates.toArray(new Predicate[predicates.size()]));
    };
}

From source file:com.schnobosoft.semeval.cortical.SemEvalTextSimilarity.java

/**
 * Read an input file of tab-separated texts. Ignoring empty lines.
 *
 * @param inputFile the input {@link File}
 * @return an array {@link CompareModels}, each holding two {@link Text}s which have been read from the file.
 * @throws IOException// www .  ja va  2 s  .c  o  m
 */
private static CompareModels[] readInput(File inputFile) throws IOException {
    LOG.info("Reading input file " + inputFile);
    assert inputFile.getName().startsWith(INPUT_FILE_PREFIX);
    List<CompareModels> lines = Files.lines(inputFile.toPath()).filter((s) -> !s.isEmpty())
            .map(line -> line.split("\t")).map(line -> new CompareModels(new Text(line[0]), new Text(line[1])))
            .collect(Collectors.toList());
    return lines.toArray(new CompareModels[lines.size()]);
}

From source file:de.unisb.cs.st.javalanche.mutation.runtime.testDriver.junit.Junit4Util.java

private static Class<?>[] getClasses(final Multimap<String, String> methods) throws ClassNotFoundException {
    Set<String> keySet = methods.keySet();
    List<Class<?>> classes = new ArrayList<Class<?>>();

    for (String className : keySet) {
        classes.add(Class.forName(className));
    }//from  w  w  w  .j  a  va2 s . c o  m
    return classes.toArray(new Class<?>[0]);
}

From source file:forestry.arboriculture.commands.CommandTreeSpawn.java

private static String[] getSpecies() {
    List<String> species = new ArrayList<String>();

    for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values())
        if (allele instanceof IAlleleTreeSpecies)
            species.add(allele.getName().replaceAll("\\s", ""));

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

From source file:com.stratio.deep.commons.utils.AnnotationUtils.java

/**
 * Utility method that filters out all the fields _not_ annotated
 * with the {@link com.stratio.deep.commons.annotations.DeepField} annotation.
 *
 * @param clazz the Class object for which we want to resolve deep fields.
 * @return an array of deep Field(s)./*from w w w. ja  va2  s .com*/
 */
public static Field[] filterDeepFields(Class clazz) {
    Field[] fields = Utils.getAllFields(clazz);
    List<Field> filtered = new ArrayList<>();
    for (Field f : fields) {
        if (f.isAnnotationPresent(DeepField.class)) {
            filtered.add(f);
        }
    }
    return filtered.toArray(new Field[filtered.size()]);
}

From source file:language_engine.bing.BingTranslationApi.java

private static String generateUrl(String accessToken, List<String> querys, SupportedLanguages from,
        SupportedLanguages to) {//  w  w  w .  j  a  v  a2s.c  o m
    String[] texts = new String[] {};
    texts = querys.toArray(texts);
    for (int i = 0; i < texts.length; i++) {
        texts[i] = StringEscapeUtils.escapeJava(texts[i]);
    }

    try {
        final String params = (accessToken != null
                ? PARAM_APP_ID + URLEncoder.encode("Bearer " + accessToken, ENCODING)
                : "") + PARAM_FROM_LANG + URLEncoder.encode(from.getLanguageCode(), ENCODING) + PARAM_TO_LANG
                + URLEncoder.encode(to.getLanguageCode(), ENCODING) + PARAM_TEXT_ARRAY
                + URLEncoder.encode(buildStringArrayParam(texts), ENCODING);

        return TRANSLATE_URL + params;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return null;
}