Example usage for java.util Collection addAll

List of usage examples for java.util Collection addAll

Introduction

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

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Adds all of the elements in the specified collection to this collection (optional operation).

Usage

From source file:net.roboconf.dm.templating.internal.templates.TemplateWatcher.java

/**
 * Finds the templates that can apply to a given application.
 * <p>The templates contained in the returned set may have been removed at the time they are accessed.</p>
 *
 * @param appName the name of the application, or {@code null} to only get the global templates
 * @return a non-null list//ww w  . j ava  2 s .c o m
 */
public Collection<TemplateEntry> findTemplatesForApplication(final String appName) {

    final Collection<TemplateEntry> result = new ArrayList<>();
    this.lock.readLock().lock();
    try {
        result.addAll(TemplateUtils.findTemplatesForApplication(appName, this.fileToTemplate.values()));

    } finally {
        this.lock.readLock().unlock();
    }

    return result;
}

From source file:org.obiba.mica.web.model.StudySummaryDtos.java

@NotNull
public Mica.StudySummaryDto.Builder asCollectionStudyDtoBuilder(@NotNull Study study, boolean isPublished,
        long variablesCount) {
    Mica.StudySummaryDto.Builder builder = Mica.StudySummaryDto.newBuilder();
    builder.setPublished(isPublished);//  w w  w.  ja  v a 2 s  . co  m

    builder.setId(study.getId()) //
            .setTimestamps(TimestampsDtos.asDto(study)) //
            .addAllName(localizedStringDtos.asDto(study.getName())) //
            .addAllAcronym(localizedStringDtos.asDto(study.getAcronym())) //
            .addAllObjectives(localizedStringDtos.asDto(study.getObjectives()))
            .setVariables(isPublished ? variablesCount : 0);

    if (study.getLogo() != null)
        builder.setLogo(attachmentDtos.asDto(study.getLogo()));

    addDesignInBuilderIfPossible(study.getModel(), builder);
    addTargetNumberInBuilderIfPossible(study.getModel(), builder);

    Collection<String> countries = new HashSet<>();
    SortedSet<Population> populations = study.getPopulations();

    if (populations != null) {
        countries.addAll(extractCountries(populations));
        populations.forEach(population -> builder.addPopulationSummaries(asDto(population)));
        addDataSources(builder, populations);
    }

    builder.setPermissions(permissionsDtos.asDto(study));

    builder.addAllCountries(countries);

    return builder;
}

From source file:com.github.dozermapper.core.util.MappingUtils.java

@SuppressWarnings("unchecked")
private static Collection<?> prepareIndexedCollectionType(Class<?> collectionType, Object existingCollection,
        Object collectionEntry, int index) {
    Collection result = null;
    //Instantiation of the new Collection: can be interface or implementation class
    if (collectionType.isInterface()) {
        if (collectionType.equals(Set.class)) {
            result = new HashSet();
        } else if (collectionType.equals(List.class)) {
            result = new ArrayList();
        } else {/*  w ww  . j  a va2  s.c om*/
            throwMappingException(
                    "Only interface types java.util.Set and java.util.List are supported for java.util.Collection type indexed properties.");
        }
    } else {
        //It is an implementation class of Collection
        try {
            result = (Collection) collectionType.newInstance();
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }

    //Fill in old values in new Collection
    if (existingCollection != null) {
        result.addAll((Collection) existingCollection);
    }

    //Add the new value:
    //For an ordered Collection
    if (result instanceof List) {
        while (result.size() < index + 1) {
            result.add(null);
        }
        ((List) result).set(index, collectionEntry);
    } else {
        //for an unordered Collection (index has no use here)
        result.add(collectionEntry);
    }
    return result;
}

From source file:croche.maven.plugin.dbupgrade.CreateUpgradeScriptMojo.java

/**
 * Gets the comma separated list of effective exclude patterns.
 * @return The comma separated list of effective exclude patterns, never <code>null</code>.
 *//*ww  w  .j  av  a  2  s.c  o m*/
@SuppressWarnings({ "rawtypes", "unchecked" })
String getExcludesCSV() {
    Collection patterns = new LinkedHashSet(FileUtils.getDefaultExcludesAsList());
    // add on the target files as excludes
    patterns.addAll(Arrays.asList(this.allInOneFileName, this.coreFileName, this.wwwFileName));
    if (this.excludes != null) {
        patterns.addAll(Arrays.asList(this.excludes));
    }
    return StringUtils.join(patterns.iterator(), ",");
}

From source file:net.ontopia.topicmaps.nav2.portlets.pojos.TMRAP.java

public Collection getAllPages(Collection model) {
    Collection pages = new ArrayList();
    Iterator it = model.iterator();
    while (it.hasNext()) {
        Server server = (Server) it.next();
        pages.addAll(server.getPages());
    }//  w  w w. j a v  a  2  s .  c  om
    return pages;
}

From source file:com.hurence.logisland.processor.excel.ExcelExtract.java

@Override
public Collection<Record> process(ProcessContext context, Collection<Record> records) {
    final Collection<Record> ret = new ArrayList<>();
    for (Record record : records) {
        //Extract source input stream
        InputStream is = extractRawContent(record);
        //process
        ret.addAll(handleExcelStream(is)
                //enrich
                .map(current -> enrichWithMetadata(current, record))
                //collect and add to global results
                .collect(Collectors.toList()));
    }/*from  w  ww. jav  a 2s.c  o m*/
    return ret;
}

From source file:be.wimsymons.intellij.polopolyimport.PPImporter.java

private byte[] makeJar(VirtualFile[] files) throws IOException {
    JarOutputStream jarOS = null;
    ByteArrayOutputStream byteOS = null;
    try {//from  w  w  w  .  ja  va  2  s  . c o m
        progressIndicator.setIndeterminate(true);

        // build list of files to process
        Collection<VirtualFile> filesToProcess = new LinkedHashSet<VirtualFile>();
        for (VirtualFile virtualFile : files) {
            filesToProcess.addAll(getFileList(virtualFile));
        }

        progressIndicator.setIndeterminate(false);
        progressIndicator.setFraction(0.0D);

        totalCount = filesToProcess.size();

        byteOS = new ByteArrayOutputStream();
        jarOS = new JarOutputStream(byteOS);
        int counter = 0;
        for (VirtualFile file : filesToProcess) {
            if (progressIndicator.isCanceled()) {
                break;
            }

            counter++;
            progressIndicator.setFraction((double) counter / (double) totalCount * 0.5D);
            progressIndicator.setText("Adding " + file.getName() + " ...");

            if (canImport(file)) {
                LOGGER.info("Adding file " + (counter + 1) + "/" + totalCount);
                addToJar(jarOS, file);
            } else {
                skippedCount++;
            }
        }
        jarOS.flush();
        return progressIndicator.isCanceled() ? null : byteOS.toByteArray();
    } finally {
        Closeables.close(jarOS, true);
        Closeables.close(byteOS, true);
    }
}

From source file:de.hybris.platform.category.impl.DefaultCategoryService.java

@Override
public List<CategoryModel> getCategoryPathForProduct(final ProductModel product,
        final Class... includeOnlyCategories) {
    final List<CategoryModel> result = new ArrayList<CategoryModel>();
    final Collection<CategoryModel> currentLevel = new ArrayList<CategoryModel>();
    currentLevel.addAll(product.getSupercategories());

    while (!CollectionUtils.isEmpty(currentLevel)) {
        CategoryModel categoryModel = null;
        for (final CategoryModel category : currentLevel) {
            if (categoryModel == null && shouldAddPathElement(category.getClass(), includeOnlyCategories)) {
                categoryModel = category;
            }/*from  w w  w .j a  v  a 2 s . co  m*/
        }
        currentLevel.clear();
        if (categoryModel != null) {
            currentLevel.addAll(categoryModel.getSupercategories());
            result.add(categoryModel);
        }
    }

    Collections.reverse(result);
    return result;
}

From source file:com.ebay.cloud.cms.metadata.mongo.MetadataOptionValidator.java

private Collection<IndexInfo> getEmbededIndexes(MetaClass metaClass, MetaClassGraph graph) {
    Collection<IndexInfo> embedIndexes = new ArrayList<IndexInfo>();
    Collection<MetaField> fields = metaClass.getClassFields();
    for (MetaField field : fields) {
        if (field.getDataType() == DataTypeEnum.RELATIONSHIP
                && ((MetaRelationship) field).getRelationType() == RelationTypeEnum.Embedded) {
            MetaRelationship relationship = (MetaRelationship) field;
            String refDataType = relationship.getRefDataType();
            MetaClass targetMeta = graph.getMetaClass(refDataType);
            if (targetMeta != null) {
                // add reference indexes
                targetMeta.addReferenceIndexes();
                // add self indexes
                Collection<IndexInfo> targetIndexes = new ArrayList<IndexInfo>(
                        targetMeta.getOptions().getIndexes());
                // add nested embed indexes
                targetIndexes.addAll(getEmbededIndexes(targetMeta, graph));
                for (IndexInfo targetIndex : targetIndexes) {
                    embedIndexes.add(new IndexInfo(targetIndex, relationship));
                }//from w w  w.  ja v a 2s.  c o  m
            }
        }
    }
    return embedIndexes;
}

From source file:biz.wolschon.fileformats.gnucash.jwsdpimpl.GnucashTransactionWritingImpl.java

/**
 *
 * @throws JAXBException if we have issues with the XML-backend
 * @see biz.wolschon.fileformats.gnucash.GnucashWritableTransaction#remove()
 *///from  ww  w . jav  a 2s  .c o m
public void remove() throws JAXBException {
    getWritingFile().removeTransaction(this);
    Collection<GnucashWritableTransactionSplit> c = new LinkedList<GnucashWritableTransactionSplit>();
    c.addAll(getWritingSplits());
    for (GnucashWritableTransactionSplit element : c) {
        element.remove();
    }

}