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:io.fabric8.maven.core.util.ClassUtil.java

public static URLClassLoader createProjectClassLoader(final MavenProject project, Logger log) {

    try {/*from  ww  w  . j a va2  s  .c  om*/

        List<URL> compileJars = new ArrayList<>();

        for (String element : project.getCompileClasspathElements()) {
            compileJars.add(new File(element).toURI().toURL());
        }

        return new URLClassLoader(compileJars.toArray(new URL[compileJars.size()]),
                PluginServiceFactory.class.getClassLoader());

    } catch (Exception e) {
        log.warn("Instructed to use project classpath, but cannot. Continuing build if we can: ", e);
    }

    // return an empty CL .. don't want to have to deal with NULL later
    // if somehow we incorrectly call this method
    return new URLClassLoader(new URL[] {});
}

From source file:com.netflix.genie.server.repository.jpa.JobSpecs.java

/**
 * Find jobs based on the parameters.//w w  w .  java2  s . c  o  m
 *
 * @param id          The job id
 * @param jobName     The job name
 * @param userName    The user who created the job
 * @param statuses    The job statuses
 * @param tags        The tags for the jobs to find
 * @param clusterName The cluster name
 * @param clusterId   The cluster id
 * @param commandName The command name
 * @param commandId   The command id
 * @return The specification
 */
public static Specification<Job> find(final String id, final String jobName, final String userName,
        final Set<JobStatus> statuses, final Set<String> tags, final String clusterName, final String clusterId,
        final String commandName, final String commandId) {
    return new Specification<Job>() {
        @Override
        public Predicate toPredicate(final Root<Job> root, final CriteriaQuery<?> cq,
                final CriteriaBuilder cb) {
            final List<Predicate> predicates = new ArrayList<>();
            if (StringUtils.isNotBlank(id)) {
                predicates.add(cb.like(root.get(Job_.id), id));
            }
            if (StringUtils.isNotBlank(jobName)) {
                predicates.add(cb.like(root.get(Job_.name), jobName));
            }
            if (StringUtils.isNotBlank(userName)) {
                predicates.add(cb.equal(root.get(Job_.user), userName));
            }
            if (statuses != null && !statuses.isEmpty()) {
                //Could optimize this as we know size could use native array
                final List<Predicate> orPredicates = new ArrayList<>();
                for (final JobStatus status : statuses) {
                    orPredicates.add(cb.equal(root.get(Job_.status), status));
                }
                predicates.add(cb.or(orPredicates.toArray(new Predicate[orPredicates.size()])));
            }
            if (tags != null) {
                for (final String tag : tags) {
                    if (StringUtils.isNotBlank(tag)) {
                        predicates.add(cb.isMember(tag, root.get(Job_.tags)));
                    }
                }
            }
            if (StringUtils.isNotBlank(clusterName)) {
                predicates.add(cb.equal(root.get(Job_.executionClusterName), clusterName));
            }
            if (StringUtils.isNotBlank(clusterId)) {
                predicates.add(cb.equal(root.get(Job_.executionClusterId), clusterId));
            }
            if (StringUtils.isNotBlank(commandName)) {
                predicates.add(cb.equal(root.get(Job_.commandName), commandName));
            }
            if (StringUtils.isNotBlank(commandId)) {
                predicates.add(cb.equal(root.get(Job_.commandId), commandId));
            }
            return cb.and(predicates.toArray(new Predicate[predicates.size()]));
        }
    };
}

From source file:gov.nih.nci.caarray.util.EmailUtil.java

private static MimeMessage constructMessage(List<String> mailRecipients, String from, String mailSubject)
        throws MessagingException {
    Validate.notEmpty(mailRecipients, "No email recipients are specified");
    if (StringUtils.isEmpty(mailSubject)) {
        LOG.info("No email subject specified");
    }//from   w  w w.java  2  s  .  co m

    List<Address> addresses = new ArrayList<Address>();
    for (String recipient : mailRecipients) {
        addresses.add(new InternetAddress(recipient));
    }

    MimeMessage message = new MimeMessage(MAILSESSION);
    message.setRecipients(Message.RecipientType.TO, addresses.toArray(new Address[addresses.size()]));
    message.setFrom(new InternetAddress(from));
    message.setSubject(mailSubject);

    return message;
}

From source file:com.wiyun.engine.network.Network.java

static void setMultipartEntity(HttpEntityEnclosingRequestBase request, List<Part> parts) {
    request.setEntity(new MultipartEntity(parts.toArray(new Part[parts.size()])));
}

From source file:com.eatnumber1.util.cglib.EnhancerUtils.java

private static Enhancer getEnhancer(@NotNull Class<?> type, @Nullable Class<?>... interfaces) {
    Enhancer enhancer = new Enhancer();
    List<Class<?>> interfaceList = interfaces == null ? new ArrayList<Class<?>>()
            : new ArrayList<Class<?>>(Arrays.asList(interfaces));
    if (type.isInterface()) {
        interfaceList.add(type);/*from w w w.j  a v a2  s .c  o  m*/
    } else {
        enhancer.setSuperclass(type);
    }
    enhancer.setInterfaces(interfaceList.toArray(new Class<?>[interfaceList.size()]));
    return enhancer;
}

From source file:com.netradius.hibernate.support.HibernateUtil.java

private static List<String[]> getColumns(final String table) {
    final List<String[]> rows = new ArrayList<String[]>();
    rows.add(new String[] { "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME", "DATA_TYPE", "TYPE_NAME",
            "COLUMN_SIZE", "BUFFER_LENGTH", "DECIMAL_DIGITS", "NUM_PREC_RADIX", "NULLABLE", "REMARKS",
            "COLUMN_DEF", "SQL_DATA_TYPE", "SQL_DATETIME_SUB", "CHAR_OCTET_LENGTH", "ORDINAL_POSITION",
            "IS_NULLABLE", "SCOPE_CATLOG", "SCOPE_SCHEMA", "SCOPE_TABLE", "SOURCE_DATA_TYPE",
            "IS_AUTOINCREMENT" });
    Connection con = null;/*from w w  w.j  av a2  s .  co m*/
    ResultSet rs = null;
    try {
        con = getConnection();
        final DatabaseMetaData md = con.getMetaData();
        rs = md.getColumns(null, null, table, "%");
        while (rs.next()) {
            List<String> s = new ArrayList<String>(23);
            for (int i = 23; i > 0; i--)
                s.add(rs.getString(i));
            rows.add(s.toArray(new String[23]));
        }
    } catch (SQLException x) {
        log.error("Error describing table: " + x.getMessage(), x);
    } finally {
        close(con, null, rs);
    }
    return rows;
}

From source file:io.undertow.servlet.test.request.RedirectTestCase.java

/**
 * because String.split() is retarded//from  w ww.j av  a  2s.  com
 */
private static String[] split(String s) {
    List<String> strings = new ArrayList<>();
    int pos = 0;
    for (int i = 0; i < s.length(); ++i) {
        char c = s.charAt(i);
        if (c == ',') {
            strings.add(s.substring(pos, i));
            pos = i + 1;
        }
    }
    strings.add(s.substring(pos));
    return strings.toArray(new String[strings.size()]);
}

From source file:Main.java

public static String[][] tsvToArray(File f, int columns, boolean useFirstLine) throws FileNotFoundException {
    List<String[]> rows = new LinkedList<String[]>();
    Scanner in = new Scanner(f);
    if (!useFirstLine && in.hasNextLine())
        in.nextLine();//from w w  w.  j  a va 2s . c o  m

    while (in.hasNextLine()) {
        String[] tokens = in.nextLine().split("\t");
        if (columns > 0 && tokens.length < columns)
            continue;
        rows.add(tokens);
    }
    in.close();
    return rows.toArray(new String[0][]);
}

From source file:Main.java

private static List<Object[]> parseEntityData(final Iterator<Object[]> dataIterator, final Class<?>[] classes)
        throws Exception {
    List<Object[]> list = new ArrayList<Object[]>();

    while (dataIterator.hasNext()) {

        Object[] rowDataArray = dataIterator.next();

        List<Object> rowData = new ArrayList<Object>();

        if (classes != null) {
            for (Object data : rowDataArray) {
                for (Class<?> clazz : classes) {
                    if (data.getClass() == clazz) {
                        rowData.add(data);
                    }/*from w  w w .j a  va 2 s  .  co  m*/
                }

            }
        }

        list.add(rowData.toArray(new Object[] { rowData.size() }));
    }

    return list;
}

From source file:org.drools.karaf.itest.KieSpringIntegrationTestSupport.java

public static Option loadDroolsKieFeatures(String... features) {
    List<String> result = new ArrayList<String>();
    result.add("drools-module");
    for (String feature : features) {
        result.add(feature);//from  w  w w  .jav  a  2s. c o  m
    }

    MavenArtifactProvisionOption featuresUrl = getFeaturesUrl("org.jboss.integration.fuse", "karaf-features",
            DroolsVersion);
    return features(featuresUrl, result.toArray(new String[1 + features.length]));
}