List of usage examples for java.util Collection clear
void clear();
From source file:de.hybris.platform.acceleratorstorefrontcommons.breadcrumb.impl.ProductBreadcrumbBuilder.java
/** * Returns a list of breadcrumbs for the given product. * * @param productCode/*from w w w. j a v a2 s. c om*/ * @return breadcrumbs for the given product */ public List<Breadcrumb> getBreadcrumbs(final String productCode) { final ProductModel productModel = getProductService().getProductForCode(productCode); final List<Breadcrumb> breadcrumbs = new ArrayList<>(); final Collection<CategoryModel> categoryModels = new ArrayList<>(); final Breadcrumb last; final ProductModel baseProductModel = getBaseProduct(productModel); last = getProductBreadcrumb(baseProductModel); categoryModels.addAll(baseProductModel.getSupercategories()); last.setLinkClass(LAST_LINK_CLASS); breadcrumbs.add(last); while (!categoryModels.isEmpty()) { CategoryModel toDisplay = null; toDisplay = processCategoryModels(categoryModels, toDisplay); categoryModels.clear(); if (toDisplay != null) { breadcrumbs.add(getCategoryBreadcrumb(toDisplay)); categoryModels.addAll(toDisplay.getSupercategories()); } } Collections.reverse(breadcrumbs); return breadcrumbs; }
From source file:mitm.djigzo.web.pages.certificate.CertificateImport.java
public void onSuccess() throws NoSuchProviderException, IOException, WebServiceCheckedException, CertificateException { importCount = new Integer(0); /*// w w w . j a v a2s. c o m * It should already be checked that the file contains certificates. */ Collection<X509Certificate> certificates = CertificateUtils.readX509Certificates(file.getStream()); totalCount = certificates.size(); Collection<X509Certificate> batch = new LinkedList<X509Certificate>(); for (X509Certificate certificate : certificates) { if (accept(certificate)) { batch.add(certificate); if (batch.size() >= maxBatchSize) { addCertificates(batch); batch.clear(); } } } /* * Check if there are still some certificates left to add (happens when the number * of certificates is not a multiple of maxBatchSize) */ if (batch.size() > 0) { addCertificates(batch); } }
From source file:com.graphaware.module.es.ElasticSearchModule.java
private void reindexRelationships(GraphDatabaseService database) { final Collection<WriteOperation<?>> operations = new HashSet<>(); new IterableInputBatchTransactionExecutor<>(database, reindexBatchSize, new AllRelationships(database, reindexBatchSize), (db, rel, batchNumber, stepNumber) -> { if (shouldReindexRelationship(rel)) { }/* w w w . ja va2 s .c om*/ if (operations.size() >= reindexBatchSize) { writer.processOperations(Arrays.asList(operations)); operations.clear(); LOG.info("Done " + reindexBatchSize); } }).execute(); if (operations.size() > 0) { afterCommit(new HashSet<>(operations)); operations.clear(); } }
From source file:ubic.gemma.persistence.service.common.description.CharacteristicDaoImpl.java
@Override public Collection<Characteristic> findByUri(Collection<String> uris) { int batchSize = 1000; // to avoid HQL parser barfing Collection<String> batch = new HashSet<>(); Collection<Characteristic> results = new HashSet<>(); if (uris.isEmpty()) return results; //language=HQL final String queryString = "from Characteristic where valueUri in (:uris)"; for (String uri : uris) { batch.add(uri);//from w ww . j a v a 2 s . c om if (batch.size() >= batchSize) { results.addAll(this.getBatchList(batch, queryString)); batch.clear(); } } if (batch.size() > 0) { results.addAll(this.getBatchList(batch, queryString)); } return results; }
From source file:ubic.gemma.core.loader.association.NCBIGene2GOAssociationLoader.java
private void load(BlockingQueue<Gene2GOAssociation> queue) { NCBIGene2GOAssociationLoader.log.debug("Entering 'load' "); long millis = System.currentTimeMillis(); int cpt = 0;// w w w . ja v a2 s .co m double secspt = 0.0; Collection<Gene2GOAssociation> itemsToPersist = new ArrayList<>(); try { while (!(producerDone.get() && queue.isEmpty())) { Gene2GOAssociation associations = queue.poll(); if (associations == null) { continue; } itemsToPersist.add(associations); if (++count % NCBIGene2GOAssociationLoader.BATCH_SIZE == 0) { persisterHelper.persist(itemsToPersist); itemsToPersist.clear(); } // just some timing information. if (count % 10000 == 0) { cpt++; double secsperthousand = (System.currentTimeMillis() - millis) / 1000.0; secspt += secsperthousand; double meanspt = secspt / cpt; String progString = "Processed and loaded " + count + " (" + secsperthousand + " seconds elapsed, average per thousand=" + String.format("%.2f", meanspt) + ")"; NCBIGene2GOAssociationLoader.log.info(progString); millis = System.currentTimeMillis(); } } } catch (Exception e) { consumerDone.set(true); NCBIGene2GOAssociationLoader.log.fatal(e, e); throw new RuntimeException(e); } // finish up. persisterHelper.persist(itemsToPersist); NCBIGene2GOAssociationLoader.log.info("Finished, loaded total of " + count + " GO associations"); consumerDone.set(true); }
From source file:org.apache.fop.render.ps.PSDocumentHandler.java
private void writeExtensions(int which) throws IOException { Collection extensions = comments[which]; if (extensions != null) { PSRenderingUtil.writeEnclosedExtensionAttachments(gen, extensions); extensions.clear(); }//w w w.j av a 2 s.c om }
From source file:ubic.gemma.search.GeneSetSearchImpl.java
@Override public Collection<GeneSet> findGeneSetsByName(String query, Long taxonId) { if (StringUtils.isBlank(query)) { return new HashSet<GeneSet>(); }// www . jav a 2s . c om Collection<GeneSet> foundGeneSets = null; Taxon tax = null; tax = taxonService.load(taxonId); if (tax == null) { // throw new IllegalArgumentException( "Can't locate taxon with id=" + taxonId ); foundGeneSets = findByName(query); } else { foundGeneSets = findByName(query, tax); } foundGeneSets.clear(); // for testing general search /* * SEARCH GENE ONTOLOGY */ if (query.toUpperCase().startsWith("GO")) { GeneSet goSet = findByGoId(query, tax); if (goSet != null) foundGeneSets.add(goSet); } else { foundGeneSets.addAll(findByGoTermName(query, tax)); } return foundGeneSets; }
From source file:net.sf.keystore_explorer.crypto.signing.JarSigner.java
private static CMSSignedData addTimestamp(String tsaUrl, CMSSignedData signedData) throws IOException { Collection<SignerInformation> signerInfos = signedData.getSignerInfos().getSigners(); // get signature of first signer (should be the only one) SignerInformation si = signerInfos.iterator().next(); byte[] signature = si.getSignature(); // send request to TSA byte[] token = TimeStampingClient.getTimeStampToken(tsaUrl, signature, DigestType.SHA1); // create new SignerInformation with TS attribute Attribute tokenAttr = new Attribute(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken, new DERSet(ASN1Primitive.fromByteArray(token))); ASN1EncodableVector timestampVector = new ASN1EncodableVector(); timestampVector.add(tokenAttr);//from www .ja va2s . com AttributeTable at = new AttributeTable(timestampVector); si = SignerInformation.replaceUnsignedAttributes(si, at); signerInfos.clear(); signerInfos.add(si); SignerInformationStore newSignerStore = new SignerInformationStore(signerInfos); // create new signed data CMSSignedData newSignedData = CMSSignedData.replaceSigners(signedData, newSignerStore); return newSignedData; }
From source file:ubic.gemma.loader.association.NCBIGene2GOAssociationLoader.java
/** * @param queue/*from ww w .j a v a 2s . c o m*/ */ protected void load(BlockingQueue<Gene2GOAssociation> queue) { log.debug("Entering 'load' "); long millis = System.currentTimeMillis(); int cpt = 0; double secspt = 0.0; Collection<Gene2GOAssociation> itemsToPersist = new ArrayList<Gene2GOAssociation>(); try { while (!(producerDone.get() && queue.isEmpty())) { Gene2GOAssociation associations = queue.poll(); if (associations == null) { continue; } itemsToPersist.add(associations); if (++count % BATCH_SIZE == 0) { persisterHelper.persist(itemsToPersist); itemsToPersist.clear(); } // just some timing information. if (count % 1000 == 0) { cpt++; double secsperthousand = (System.currentTimeMillis() - millis) / 1000.0; secspt += secsperthousand; double meanspt = secspt / cpt; String progString = "Processed and loaded " + count + " (" + secsperthousand + " seconds elapsed, average per thousand=" + String.format("%.2f", meanspt) + ")"; log.info(progString); millis = System.currentTimeMillis(); } } } catch (Exception e) { consumerDone.set(true); log.fatal(e, e); throw new RuntimeException(e); } // finish up. persisterHelper.persist(itemsToPersist); log.info("Finished, loaded total of " + count + " GO associations"); consumerDone.set(true); }
From source file:org.apache.openjpa.kernel.AttachStrategy.java
/** * Replace the contents of <code>toc</code> with the contents of * <code>frmc</code>. Neither collection is null. *//* w w w . ja v a2 s. c o m*/ private void replaceCollection(AttachManager manager, Collection frmc, Collection toc, OpenJPAStateManager sm, FieldMetaData fmd) { // if frmc collection is empty, just clear toc if (frmc.isEmpty()) { if (!toc.isEmpty()) toc.clear(); return; } // if this is a pc collection, attach all instances boolean pc = fmd.getElement().isDeclaredTypePC(); if (pc) frmc = attachCollection(manager, frmc, sm, fmd); // remove all elements from the toc collection that aren't in frmc toc.retainAll(frmc); // now add all elements that are in frmc but not toc if (frmc.size() != toc.size()) { for (Iterator i = frmc.iterator(); i.hasNext();) { Object ob = i.next(); if (!toc.contains(ob)) toc.add(ob); } } }