Example usage for java.util Collection toArray

List of usage examples for java.util Collection toArray

Introduction

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

Prototype

default <T> T[] toArray(IntFunction<T[]> generator) 

Source Link

Document

Returns an array containing all of the elements in this collection, using the provided generator function to allocate the returned array.

Usage

From source file:com.kylinolap.job.engine.JobEngine.java

public double getPercentileJobStepDuration(double percentile) {
    Collection<Double> values = JOB_DURATION.values();
    Double[] all = (Double[]) values.toArray(new Double[values.size()]);
    Percentile p = new Percentile(percentile);
    return p.evaluate(ArrayUtils.toPrimitive(all));
}

From source file:fr.fastconnect.factory.tibco.bw.codereview.BWProjectBuilder.java

private void addSources(ProjectDefinition project) {
    final File basedir = project.getBaseDir();

    logger.debug(basedir.getAbsolutePath());

    // TODO: ignore child modules folders more properly
    IOFileFilter custom = new IOFileFilter() {
        @Override//from  w  w  w  . j a v a  2  s  . c o m
        public boolean accept(File file) {
            return file.isDirectory() && !(new File(file, "pom.xml").exists())
                    || file.getAbsolutePath().equals(basedir.getAbsolutePath());
        }

        @Override
        public boolean accept(File dir, String name) {
            return false;
        }
    };

    Collection<File> files = FileUtils.listFiles(basedir, new SuffixFileFilter(".process"),
            new AndFileFilter(new NotFileFilter(new PrefixFileFilter("target")), custom));

    project.addSources(files.toArray(new File[0]));
}

From source file:com.salesmanager.core.util.www.ajax.UpdateZones.java

public Zone[] updateZones(String countryid, int languageid) {

    RefCache cache = RefCache.getInstance();

    HttpServletRequest req = WebContextFactory.get().getHttpServletRequest();

    int country = defaultcountryid;

    try {/*from www. j av  a 2s  .  c  o m*/
        country = Integer.parseInt(countryid);
    } catch (Exception e) {
        log.error(e);
    }

    req.getSession().setAttribute("COUNTRY", country);

    ReferenceService service = new ReferenceService();
    // Collection c = service.getZonesByCountry(country, req);
    Collection c = RefCache.getFilterdByCountryZones(country, languageid);

    if (c != null) {
        Zone[] z = new Zone[c.size()];
        Zone[] znarray = (Zone[]) c.toArray(z);
        return znarray;
    } else {
        Zone[] z = new Zone[1];
        Zone zone = new Zone();
        zone.setZoneCountryId(country);
        zone.setZoneName("N/A");
        zone.setZoneId(0);
        z[0] = zone;
        return z;
    }

}

From source file:libra.preprocess.common.kmerhistogram.KmerRangePartitioner.java

public KmerRangePartition[] getHistogramPartitions(Collection<KmerHistogramRecord> records, long samples) {
    return getHistogramPartitions(records.toArray(new KmerHistogramRecord[0]), samples);
}

From source file:br.com.caelum.vraptor.observer.upload.CommonsUploadMultipartObserver.java

public void upload(@Observes ControllerFound event, MutableRequest request, MultipartConfig config,
        Validator validator) {/*from   www.j  a  va  2 s.  com*/

    if (!ServletFileUpload.isMultipartContent(request)) {
        return;
    }

    logger.info("Request contains multipart data. Try to parse with commons-upload.");

    final Multiset<String> indexes = HashMultiset.create();
    final Multimap<String, String> params = LinkedListMultimap.create();

    ServletFileUpload uploader = createServletFileUpload(config);
    uploader.setSizeMax(config.getSizeLimit());
    uploader.setFileSizeMax(config.getFileSizeLimit());

    try {
        final List<FileItem> items = uploader.parseRequest(request);
        logger.debug("Found {} attributes in the multipart form submission. Parsing them.", items.size());

        for (FileItem item : items) {
            String name = item.getFieldName();
            name = fixIndexedParameters(name, indexes);

            if (item.isFormField()) {
                logger.debug("{} is a field", name);
                params.put(name, getValue(item, request));

            } else if (isNotEmpty(item)) {
                logger.debug("{} is a file", name);
                processFile(item, name, request);

            } else {
                logger.debug("A file field is empty: {}", item.getFieldName());
            }
        }

        for (String paramName : params.keySet()) {
            Collection<String> paramValues = params.get(paramName);
            request.setParameter(paramName, paramValues.toArray(new String[paramValues.size()]));
        }

    } catch (final SizeLimitExceededException e) {
        reportSizeLimitExceeded(e, validator);

    } catch (FileUploadException e) {
        reportFileUploadException(e, validator);
    }
}

From source file:org.apache.solr.client.solrj.impl.SolrPortAwareCookieSpecFactory.java

@Override
public CookieSpec newInstance(final HttpParams params) {
    if (params != null) {
        String[] patterns = null;
        final Collection<?> param = (Collection<?>) params.getParameter(CookieSpecPNames.DATE_PATTERNS);
        if (param != null) {
            patterns = new String[param.size()];
            patterns = param.toArray(patterns);
        }//ww w.jav  a2  s. co  m
        return new PortAwareCookieSpec(patterns);
    } else {
        return new PortAwareCookieSpec(null);
    }
}

From source file:com.freetmp.common.util.ClassUtils.java

public static Class<?>[] toClassArray(Collection<Class<?>> collection) {
    if (collection == null) {
        return null;
    }/*from w w  w .j a v a  2s  .  c om*/
    return collection.toArray(new Class<?>[collection.size()]);
}

From source file:com.octo.java.sql.exp.Exp.java

public Exp in(final Collection<Object> values) throws QueryGrammarException {
    if (values == null) {
        return this;
    } else {/*from   www  .  j  a  v  a2s.com*/
        return applyInOperation(values.toArray(new Object[values.size()]));
    }
}

From source file:com.octo.java.sql.exp.Exp.java

public Exp notIn(final Collection<Object> values) throws QueryGrammarException {
    if (values == null) {
        return this;
    } else {// w  w w  .j  av a  2s .  c  om
        return applyNotInOperation(values.toArray(new Object[values.size()]));
    }
}

From source file:net.dv8tion.jda.core.entities.impl.MemberImpl.java

@Override
public boolean hasPermission(Collection<Permission> permissions) {
    Args.notNull(permissions, "Permission Collection");

    return hasPermission(permissions.toArray(new Permission[permissions.size()]));
}