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:chibi.gemmaanalysis.GeneExpressionWriterCLI.java

@Override
protected Exception doWork(String[] args) {

    StopWatch timer = new StopWatch();
    timer.start();//from   w  ww .  j  a va 2  s . co m

    String HEADER = "HEADER";

    processCommandLine(args);

    Collection<Gene> genes;
    try {
        genes = getQueryGenes();
    } catch (IOException e) {
        return e;
    }

    StringBuffer sb = new StringBuffer();
    for (Gene gene : genes) {
        sb.append(gene.toString());
        sb.append(", ");
    }
    log.info(genes.size() + " genes: " + sb.toString());

    sb = new StringBuffer();
    for (BioAssaySet bas : this.expressionExperiments) {
        sb.append(bas.toString());
        sb.append(", ");
    }
    log.info(this.expressionExperiments.size() + " experiments: " + sb.toString());

    Map<Object, StringBuffer> outBuffs = new HashMap<>();

    String fileName = outFilePrefix + ".txt";

    log.info("Output filename " + fileName);

    for (BioAssaySet bas : this.expressionExperiments) {
        ExpressionExperiment ee = (ExpressionExperiment) bas;
        Collection<ArrayDesign> ads = eeService.getArrayDesignsUsed(ee);
        Collection<CompositeSequence> css = new HashSet<CompositeSequence>();
        for (ArrayDesign ad : ads) {
            css.addAll(adService.getCompositeSequences(ad));
        }

        log.info("====================================");
        log.info("Experiment " + ee + "; Array Design " + ads + "; Composite sequences " + css.size());

        Map<Gene, Collection<CompositeSequence>> gene2css = getGene2CsMap(css);
        // ExpressionDataDoubleMatrix dataMatrix = expressionDataMatrixService.getFilteredMatrix( ee, filterConfig
        // );
        ExpressionDataDoubleMatrix dataMatrix = expressionDataMatrixService
                .getProcessedExpressionDataMatrix(ee);

        // store values inside a buffer
        if (!outBuffs.containsKey(HEADER)) {
            StringBuffer hb = new StringBuffer();
            hb.append("Gene\tProbe\tID");
            outBuffs.put(HEADER, hb);
        }
        for (BioMaterial bm : dataMatrix.getMatrix().getColNames()) {
            // bm.getFactorValues()
            // bm.getCharacteristics()
            // outBuffs.get( HEADER )
            // .append(
            // "\t" + bm.getName() + "."
            // + StringUtils.collectionToDelimitedString( bm.getFactorValues(), "," ) );
            outBuffs.get(HEADER)
                    .append("\t" + ee.getShortName() + "." + bm.getName() + "."
                            + StringUtils.collectionToDelimitedString(bm.getCharacteristics(), ",") + "."
                            + StringUtils.collectionToDelimitedString(bm.getFactorValues(), ","));
        }

        for (Gene gene : genes) {
            log.debug(" Getting component sequence for gene " + gene);
            Collection<CompositeSequence> c = gene2css.get(gene);

            if (c == null) {
                log.error("No composite sequences found for gene " + gene);
                continue;
            }

            for (CompositeSequence cs : c) {

                Double[] row = dataMatrix.getRow(cs);
                if (row == null) {
                    log.error("Cannot get data from data matrix for " + gene.getOfficialSymbol() + " ("
                            + cs.getName() + ")");
                    // continue;
                    row = new Double[dataMatrix.getMatrix().columns()];
                }

                if (!outBuffs.containsKey(cs)) {
                    StringBuffer gb = new StringBuffer();
                    gb.append(gene.getOfficialSymbol() + "\t" + cs.getName() + "\t" + cs.getId());
                    outBuffs.put(cs, gb);
                }

                StringBuffer buf = new StringBuffer();
                for (Double d : row) {
                    if (d == null)
                        buf.append("NA");
                    else
                        buf.append(d);
                    buf.append("\t");
                }
                buf.deleteCharAt(buf.length() - 1);
                outBuffs.get(cs).append("\t" + buf.toString());
            }
        }

    }

    // Output to file
    try (PrintWriter out = new PrintWriter(new FileWriter(fileName));) {
        out.println(outBuffs.get(HEADER));
        for (Object key : outBuffs.keySet()) {
            if (key.equals(HEADER)) {
                continue;
            }
            out.println(outBuffs.get(key));
        }
    } catch (IOException e) {
        return e;
    }

    log.info("Done. Wrote " + genes.size() + " genes and " + (outBuffs.keySet().size() - 1)
            + " composite sequences in " + this.expressionExperiments.size() + " experiments which took "
            + timer.getTime() + " ms. Output file " + fileName);

    return null;
}

From source file:org.reusables.dbunit.DbUnitDatasetExecutionListener.java

/**
 * Load the dataset using the given annotation information.
 * /*ww  w  . j a v a  2  s.  co m*/
 * @param operation The operation to perform.
 * @param testContext The context for the current test.
 * @param classAnnotation Dataset resource information of the test class.
 * @param methodAnnotation Dataset resource information of the test method.
 * @throws Exception Any error.
 * @since 1.3.0
 */
protected void handleDataset(final DatabaseOperation operation, final TestContext testContext,
        final DbUnitDataset classAnnotation, final DbUnitDataset methodAnnotation) throws Exception {
    LOG.debug("Getting datasets for operation: {}", operation.getClass().getSimpleName());

    final Collection<IDataSet> datasets = new ArrayList<IDataSet>();
    datasets.addAll(createDataSets(testContext, classAnnotation, false));
    datasets.addAll(createDataSets(testContext, methodAnnotation, true));

    if (datasets.isEmpty()) {
        LOG.debug("No datasets found.");
        return;
    }

    final IDataSet dataset = createAutoCompletionDataSet(
            new CompositeDataSet(datasets.toArray(new IDataSet[0])), testContext);
    final ConnectionType connectionType = getConnectionType(testContext, classAnnotation);
    handleOperation(new DatasetTask(operation, dataset), testContext, connectionType);
}

From source file:com.google.api.server.spi.request.ServletRequestParamReader.java

private <T> Collection<T> deserializeCollection(Class<?> clazz, ParameterizedType collectionType,
        JsonNode nodeValue) throws IOException {
    @SuppressWarnings("unchecked")
    Class<? extends Collection<T>> collectionClass = (Class<? extends Collection<T>>) clazz;
    @SuppressWarnings("unchecked")
    Class<T> paramClass = (Class<T>) EndpointMethod
            .getClassFromType(collectionType.getActualTypeArguments()[0]);
    @SuppressWarnings("unchecked")
    Class<T[]> arrayClazz = (Class<T[]>) Array.newInstance(paramClass, 0).getClass();
    Collection<T> collection = objectReader.forType(collectionClass).readValue(objectReader.createArrayNode());
    if (nodeValue != null) {
        T[] array = objectReader.forType(arrayClazz).readValue(nodeValue);
        collection.addAll(Arrays.asList(array));
    }/*w  ww.  ja v a2  s. c om*/
    return collection;
}

From source file:com.reprezen.swagedit.assist.SwaggerProposalProvider.java

protected Collection<Proposal> getProposals(TypeDefinition type, AbstractNode node, String prefix) {
    if (type instanceof ReferenceTypeDefinition) {
        type = ((ReferenceTypeDefinition) type).resolve();
    }/*from w w w  .j a  va2  s. c om*/

    ContentAssistExt ext = findExtension(type);
    if (ext != null) {
        return ext.getProposals(type, node, prefix);
    }

    switch (type.getType()) {
    case STRING:
    case INTEGER:
    case NUMBER:
        return createPrimitiveProposals(type);
    case BOOLEAN:
        return createBooleanProposals(type);
    case ENUM:
        return createEnumProposals(type, node);
    case ARRAY:
        return createArrayProposals((ArrayTypeDefinition) type, node);
    case OBJECT:
        return createObjectProposals((ObjectTypeDefinition) type, node, prefix);
    case ALL_OF:
    case ANY_OF:
    case ONE_OF:
        return createComplextTypeProposals((ComplexTypeDefinition) type, node, prefix);
    case UNDEFINED:
        Collection<Proposal> proposals = new LinkedHashSet<>();
        if (type instanceof MultipleTypeDefinition) {
            for (TypeDefinition currentType : ((MultipleTypeDefinition) type).getMultipleTypes()) {
                proposals.addAll(getProposals(currentType, node, prefix));
            }
        }
        return proposals;
    }
    return Collections.emptyList();
}

From source file:chibi.gemmaanalysis.cli.deprecated.BioSequenceCleanupCli.java

@Override
protected Exception doWork(String[] args) {

    Exception err = processCommandLine(args);
    if (err != null)
        return err;

    Collection<ArrayDesign> ads = new HashSet<ArrayDesign>();
    if (!this.arrayDesignsToProcess.isEmpty()) {
        ads.addAll(this.arrayDesignsToProcess);
    } else if (file != null) {
        try (InputStream is = new FileInputStream(file);
                BufferedReader br = new BufferedReader(new InputStreamReader(is));) {

            String id = null;//from  w  w  w .  j a  v  a  2s .c o m
            Collection<Long> ids = new HashSet<Long>();
            while ((id = br.readLine()) != null) {
                if (StringUtils.isBlank(id)) {
                    continue;
                }
                ids.add(Long.parseLong(id));
            }

            Collection<BioSequence> bioSequences = bss.loadMultiple(ids);
            bioSequences = bss.thaw(bioSequences);
            processSequences(bioSequences);
            return null;
        } catch (Exception e) {
            return e;
        }
    } else {
        ads = this.arrayDesignService.loadAll();
    }

    for (ArrayDesign design : ads) {
        log.info(design);
        design = unlazifyArrayDesign(design);

        Collection<BioSequence> bioSequences = new HashSet<BioSequence>();

        for (CompositeSequence cs : design.getCompositeSequences()) {
            if (cs == null)
                continue;
            if (cs.getBiologicalCharacteristic() == null)
                continue;
            bioSequences.add(cs.getBiologicalCharacteristic());
        }

        processSequences(bioSequences); // fast.

        log.info("Phase II starting");

        // ///////////////////////////////
        // Second phase: make sure composite sequences don't refer to sequences that have duplicates based on name,
        // using stricter equality criteria.
        int i = 0;
        for (CompositeSequence cs : design.getCompositeSequences()) {

            if (++i % 500 == 0) {
                log.info("Processing: " + i + "/" + bioSequences.size() + " sequences");
            }

            BioSequence anchorSeq = cs.getBiologicalCharacteristic();
            if (anchorSeq == null) {
                continue;
            }
            Collection<BioSequence> seqs = bss.findByName(anchorSeq.getName());

            // no evidence of duplicates?
            if (seqs.size() == 1) {
                continue;
            }

            seqs.remove(anchorSeq);

            seqs = this.bss.thaw(seqs);

            // ensure this group really does contain all duplicates.
            if (log.isDebugEnabled())
                log.debug("Examining set of " + seqs.size() + " possible duplicates of " + anchorSeq);

            Collection<BioSequence> notDuplicate = new HashSet<BioSequence>();
            for (BioSequence candidateForRemoval : seqs) {
                if (log.isDebugEnabled())
                    log.debug("   Examining: " + candidateForRemoval);
                assert !candidateForRemoval.equals(anchorSeq) : candidateForRemoval + " equals " + anchorSeq;
                if (!this.equals(anchorSeq, candidateForRemoval)) {
                    notDuplicate.add(candidateForRemoval);
                } else {
                    if (log.isDebugEnabled())
                        log.debug("    Duplicate: " + anchorSeq + " " + candidateForRemoval);
                }
            }

            seqs.removeAll(notDuplicate);

            for (BioSequence toChange : seqs) {
                if (log.isDebugEnabled())
                    log.debug("Processing " + toChange);
                if (!this.equals(anchorSeq, toChange)) {
                    throw new IllegalStateException(
                            "Sequences weren't equal " + anchorSeq + " and " + toChange);
                }
                switchAndDeleteExtra(anchorSeq, toChange);

            }
        }
    }

    return null;

}

From source file:net.sf.jasperreports.engine.JRPropertiesMap.java

protected void collectPropertyNames(Collection<String> names) {
    if (base != null) {
        base.collectPropertyNames(names);
    }//from  www. j a  va  2  s  .  c  o  m

    if (propertiesList != null) {
        names.addAll(propertiesList);
    }
}

From source file:net.sourceforge.metware.binche.graph.ChebiGraph.java

/**
 * Removes a vertex and its connected edges.
 * @param chebiVertex/*from  ww  w  .java  2 s.co  m*/
 */
public void removeVertex(ChebiVertex chebiVertex) {
    Collection<ChebiEdge> toRemove = new LinkedList<ChebiEdge>(getInEdges(chebiVertex));
    toRemove.addAll(getOutEdges(chebiVertex));

    for (ChebiEdge chebiEdge : toRemove) {
        graph.removeEdge(chebiEdge);
    }

    graph.removeVertex(chebiVertex);
}

From source file:eu.europa.ec.markt.dss.signature.pades.PAdESProfileEPES.java

CMSSignedDataGenerator createCMSSignedDataGenerator(ContentSigner contentSigner,
        DigestCalculatorProvider digestCalculatorProvider, final SignatureParameters parameters,
        final byte[] messageDigest) throws IOException {
    try {/*from w w  w  . jav  a 2 s  . com*/

        CMSSignedDataGenerator generator = new CMSSignedDataGenerator();

        X509Certificate signerCertificate = parameters.getSigningCertificate();

        X509CertificateHolder certHolder = new X509CertificateHolder(signerCertificate.getEncoded());

        SignerInfoGeneratorBuilder sigenb = new SignerInfoGeneratorBuilder(digestCalculatorProvider);

        final CAdESProfileEPES profile = new CAdESProfileEPES(true);

        sigenb = sigenb.setSignedAttributeGenerator(new CMSAttributeTableGenerator() {
            @Override
            public AttributeTable getAttributes(Map params) throws CMSAttributeTableGenerationException {
                Hashtable clone = (Hashtable) profile.getSignedAttributes(parameters).clone();

                if (!clone.containsKey(CMSAttributes.contentType)) {
                    DERObjectIdentifier contentType = (DERObjectIdentifier) params
                            .get(CMSAttributeTableGenerator.CONTENT_TYPE);

                    // contentType will be null if we're trying to generate a counter signature.
                    if (contentType != null) {
                        Attribute attr = new Attribute(CMSAttributes.contentType, new DERSet(contentType));
                        clone.put(attr.getAttrType(), attr);
                    }
                }

                if (!clone.containsKey(CMSAttributes.messageDigest)) {
                    System.out.println("Digest propos : "
                            + org.apache.commons.codec.binary.Hex.encodeHexString(messageDigest));
                    // byte[] messageDigest = (byte[]) params.get(CMSAttributeTableGenerator.DIGEST);
                    Attribute attr = new Attribute(CMSAttributes.messageDigest,
                            new DERSet(new DEROctetString(messageDigest)));
                    clone.put(attr.getAttrType(), attr);
                }

                if (parameters.getCommitmentTypeIndication() != null
                        && !parameters.getCommitmentTypeIndication().isEmpty()) {
                    ASN1EncodableVector vector = new ASN1EncodableVector();
                    for (String id : parameters.getCommitmentTypeIndication()) {
                        vector.add(new DERObjectIdentifier(id));
                    }
                    DERSet set = new DERSet(new DERSequence(vector));
                    Attribute attr = new Attribute(new DERObjectIdentifier("1.2.840.113549.1.9.16.2.16"), set);
                    clone.put(attr.getAttrType(), attr);
                }

                return new AttributeTable(clone);
            }
        });

        // sigenb.setUnsignedAttributeGenerator(new SimpleAttributeTableGenerator(new AttributeTable(
        // new Hashtable<ASN1ObjectIdentifier, ASN1Encodable>())));

        /*
         * We don't include a unsigned attribute table if not needed : a unsignedAttrs of signerInfo includes no
         * Attribute, UnsignedAttributes ::= SET SIZE (1..MAX) OF Attribute(defined in RFC3852).
         */
        SignerInfoGenerator sigen = sigenb.build(contentSigner, certHolder);

        generator.addSignerInfoGenerator(sigen);

        Collection<X509Certificate> certs = new ArrayList<X509Certificate>();
        if (parameters.getCertificateChain() == null
                || !parameters.getCertificateChain().contains(parameters.getSigningCertificate())) {
            certs.add(parameters.getSigningCertificate());
        }
        certs.addAll(parameters.getCertificateChain());
        JcaCertStore certStore = new JcaCertStore(certs);
        generator.addCertificates(certStore);

        System.out.println("Gnrator cr");
        return generator;

    } catch (CertificateException e) {
        throw new IOException(e);
    } catch (OperatorCreationException e) {
        throw new IOException(e);
    } catch (CMSException e) {
        throw new IOException(e);
    }

}

From source file:com.xchanging.support.batch.admin.service.SimpleJobService.java

public int countJobs() {
    Collection<String> names = new HashSet<String>(jobLocator.getJobNames());
    names.addAll(jobInstanceDao.getJobNames());
    return names.size();
}

From source file:edu.northwestern.bioinformatics.studycalendar.service.presenter.StudyWorkflowStatus.java

public Collection<WorkflowMessage> getStructureRelatedMessages() {
    Collection<WorkflowMessage> messages = new ArrayList<WorkflowMessage>();
    if (study.getHasTemporaryAssignedIdentifier()) {
        messages.add(workflowMessageFactory.createMessage(WorkflowStep.SET_ASSIGNED_IDENTIFIER, utr));
    } else if (getRevisionWorkflowStatus() != null && isNotEmpty(revisionWorkflowStatus.getMessages())) {
        messages.addAll(revisionWorkflowStatus.getStructureMessages());
    }//from   w  ww  .  j  a  va2 s  .  co m
    return messages;
}