List of usage examples for java.util Collection clear
void clear();
From source file:org.jactr.core.buffer.AbstractActivationBuffer.java
/** * spread activation to all the chunks that are connected to the source chunk * /* ww w.j ava 2 s .c o m*/ * @return a collection of all the chunks that have had their source * activation incremented */ final protected Collection<IChunk> spreadActivation() { /* * we use an array list which WILL permit duplicates. Why? shouldn't * something appearing N times in a source chunk get N times the source * activation? */ Collection<IChunk> rtn = new ArrayList<IChunk>(); Collection<Link> iLinks = new ArrayList<Link>(); /* * we need to get each chunk that the source contains */ for (IChunk sourceChunk : getSourceChunks()) { ISubsymbolicChunk sourceChunkSub = sourceChunk.getSubsymbolicChunk(); if (sourceChunkSub instanceof ISubsymbolicChunk4) { iLinks.clear(); ((ISubsymbolicChunk4) sourceChunkSub).getIAssociations(iLinks); /* * this chunk is J, so we need I */ for (Link iLink : iLinks) rtn.add(iLink.getIChunk()); } if (rtn.size() != 0) { // now we have them all, let's apply the activation double sourceActivation = getActivation() / rtn.size(); for (IChunk chunk : rtn) { // unlikely, but possible.. if (chunk.hasBeenDisposed()) continue; ISubsymbolicChunk ssc = chunk.getSubsymbolicChunk(); double activation = ssc.getSourceActivation() + sourceActivation; ssc.setSourceActivation(activation); } } } return rtn; }
From source file:com.pedra.storefront.breadcrumb.impl.SearchBreadcrumbBuilder.java
public List<Breadcrumb> getBreadcrumbs(final String categoryCode, final String searchText, final boolean emptyBreadcrumbs) throws IllegalArgumentException { final List<Breadcrumb> breadcrumbs = new ArrayList<Breadcrumb>(); if (categoryCode == null) { final Breadcrumb breadcrumb = new Breadcrumb("/search?text=" + getEncodedUrl(searchText), StringEscapeUtils.escapeHtml(searchText), (emptyBreadcrumbs ? LAST_LINK_CLASS : "")); breadcrumbs.add(breadcrumb);/*from w ww . j a v a 2 s . co m*/ } else { // Create category hierarchy path for breadcrumb final List<Breadcrumb> categoryBreadcrumbs = new ArrayList<Breadcrumb>(); final Collection<CategoryModel> categoryModels = new ArrayList<CategoryModel>(); final CategoryModel lastCategoryModel = getCommerceCategoryService().getCategoryForCode(categoryCode); categoryModels.addAll(lastCategoryModel.getSupercategories()); categoryBreadcrumbs .add(getCategoryBreadcrumb(lastCategoryModel, (!emptyBreadcrumbs ? LAST_LINK_CLASS : ""))); while (!categoryModels.isEmpty()) { final CategoryModel categoryModel = categoryModels.iterator().next(); if (!(categoryModel instanceof ClassificationClassModel)) { if (categoryModel != null) { categoryBreadcrumbs.add(getCategoryBreadcrumb(categoryModel)); categoryModels.clear(); categoryModels.addAll(categoryModel.getSupercategories()); } } else { categoryModels.remove(categoryModel); } } Collections.reverse(categoryBreadcrumbs); breadcrumbs.addAll(categoryBreadcrumbs); } return breadcrumbs; }
From source file:org.castor.cpa.test.test88.TestLazyLoading.java
public void testCollection() throws PersistenceException { LOG.info("Running testCollection..."); Identity fullname = new Identity("First", "Person"); LazyPerson loadPerson;/*from w ww .j a va 2 s . c om*/ // test java.util.Collection.clear() for lazy loading (bug 801) _db.begin(); loadPerson = _db.load(LazyEmployee.class, fullname); Collection<LazyAddress> addresses = loadPerson.getAddress(); addresses.clear(); _db.commit(); _db.begin(); loadPerson = _db.load(LazyEmployee.class, fullname); addresses = loadPerson.getAddress(); // check if clear() work if (!addresses.isEmpty()) { LOG.error("Error: Collection.clear() is not working!"); fail("Error: Collection.clear() is not working!"); } // modify the collection to test java.util.Collection.addAll() // for lazy loading (bug 801) Collection<LazyAddress> c = new ArrayList<LazyAddress>(); LazyAddress address = new LazyAddress(); address.setId(101); address.setStreet("Mattrew Street"); address.setCity("Rome City"); address.setState("RM"); address.setZip("10000"); address.setPerson(loadPerson); c.add(address); address = new LazyAddress(); address.setId(102); address.setStreet("Luke Street"); address.setCity("Rome City"); address.setState("RM"); address.setZip("10000"); address.setPerson(loadPerson); c.add(address); address = new LazyAddress(); address.setId(103); address.setStreet("John Street"); address.setCity("Rome City"); address.setState("RM"); address.setZip("10000"); address.setPerson(loadPerson); c.add(address); addresses.addAll(c); _db.commit(); // check if add all work _db.begin(); loadPerson = _db.load(LazyEmployee.class, fullname); addresses = loadPerson.getAddress(); Iterator<LazyAddress> itor = addresses.iterator(); boolean hasAddr1, hasAddr2, hasAddr3; hasAddr1 = false; hasAddr2 = false; hasAddr3 = false; while (itor.hasNext()) { address = itor.next(); if (address.getId() == 101) { hasAddr1 = true; } else if (address.getId() == 102) { hasAddr2 = true; } else if (address.getId() == 103) { hasAddr3 = true; } else { LOG.error("Error: Address with unexpected id is found! " + address); fail("Erorr: Address with unexpected id is found! " + address); } } if (!hasAddr1 || !hasAddr2 || !hasAddr3) { LOG.error("Error: Collection.addAll( Collection ) fail"); fail("Error: Collection.addAll( Collection ) fail"); } _db.commit(); }
From source file:ubic.gemma.persistence.service.genome.GeneDaoImpl.java
@Override public Collection<Gene> thawLite(final Collection<Gene> genes) { if (genes.isEmpty()) return new HashSet<>(); Collection<Gene> result = new HashSet<>(); Collection<Gene> batch = new HashSet<>(); for (Gene g : genes) { batch.add(g);/*from ww w .j a v a2s . co m*/ if (batch.size() == GeneDaoImpl.BATCH_SIZE) { result.addAll(this.loadThawed(EntityUtils.getIds(batch))); batch.clear(); } } if (!batch.isEmpty()) { result.addAll(this.loadThawed(EntityUtils.getIds(batch))); } return result; }
From source file:com.mitre.storefront.breadcrumb.impl.ProductBreadcrumbBuilder.java
protected void addCategoryBreadCrumbs(final List<Breadcrumb> breadcrumbs, final String baseProductCode) { final Collection<CategoryModel> categoryModels = new ArrayList<CategoryModel>(); final ProductModel baseProductModel = productService.getProductForCode(baseProductCode); categoryModels.addAll(baseProductModel.getSupercategories()); while (!categoryModels.isEmpty()) { CategoryModel toDisplay = null;//w w w .ja v a2 s. c om for (final CategoryModel categoryModel : categoryModels) { if (!(categoryModel instanceof ClassificationClassModel)) { if (toDisplay == null) { toDisplay = categoryModel; } if (getBrowseHistory().findUrlInHistory(categoryModel.getCode()) != null) { break; } } } categoryModels.clear(); if (toDisplay != null) { breadcrumbs.add(getCategoryBreadcrumb(toDisplay)); categoryModels.addAll(toDisplay.getSupercategories()); } } }
From source file:org.jbpm.kie.services.test.store.DeploymentStoreTest.java
@Test public void testEnableAndGetByDateActiveDeployments() { Collection<DeploymentUnit> enabled = store.getEnabledDeploymentUnits(); assertNotNull(enabled);//from w ww. j a v a 2 s.co m assertEquals(0, enabled.size()); Date date = new Date(); KModuleDeploymentUnit unit = new KModuleDeploymentUnit("org.jbpm", "test", "1.0"); store.enableDeploymentUnit(unit); unit = new KModuleDeploymentUnit("org.jbpm", "prod", "1.0"); store.enableDeploymentUnit(unit); Collection<DeploymentUnit> unitsEnabled = new HashSet<DeploymentUnit>(); Collection<DeploymentUnit> unitsDisabled = new HashSet<DeploymentUnit>(); Collection<DeploymentUnit> unitsActivated = new HashSet<DeploymentUnit>(); Collection<DeploymentUnit> unitsDeactivated = new HashSet<DeploymentUnit>(); store.getDeploymentUnitsByDate(date, unitsEnabled, unitsDisabled, unitsActivated, unitsDeactivated); assertNotNull(unitsEnabled); assertEquals(2, unitsEnabled.size()); assertNotNull(unitsDisabled); assertEquals(0, unitsDisabled.size()); date = new Date(); store.disableDeploymentUnit(unit); // verify unitsEnabled.clear(); unitsDisabled.clear(); unitsActivated.clear(); unitsDeactivated.clear(); store.getDeploymentUnitsByDate(date, unitsEnabled, unitsDisabled, unitsActivated, unitsDeactivated); assertNotNull(unitsEnabled); assertEquals(0, unitsEnabled.size()); assertNotNull(unitsDisabled); assertEquals(1, unitsDisabled.size()); }
From source file:org.extremecomponents.tree.ProcessTreeRowsCallback.java
public Collection sortRows(TableModel model, Collection rows) throws Exception { boolean sorted = model.getLimit().isSorted(); if (!sorted) { return rows; }//from w w w. j ava 2 s.co m List parents = new ArrayList(); for (Iterator iter = rows.iterator(); iter.hasNext();) { TreeNode node = (TreeNode) iter.next(); if (node.getParent() == null) parents.add(node); } List output = new ArrayList(); Sort sort = model.getLimit().getSort(); String property = sort.getProperty(); String sortOrder = sort.getSortOrder(); subSort(parents, property, sortOrder); // First sort the parents recursiveSort(output, parents, property, sortOrder); output.retainAll(rows); // Only keep the original nodes rows.clear(); rows.addAll(output); return rows; }
From source file:nl.tue.gale.um.UMServiceImpl.java
private void addUserInfo(Collection<URI> uriList, String userInfo) { List<URI> resultList = new LinkedList<URI>(); for (URI uri : uriList) resultList.add(addUserInfo(uri, userInfo)); uriList.clear(); uriList.addAll(resultList);//from w w w.jav a 2 s .c o m }
From source file:org.wso2.carbon.bpel.bam.publisher.Axis2ConfigurationContextObserverImpl.java
public void terminatingConfigurationContext(ConfigurationContext configurationContext) { Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); log.info("Removing data publishers for this tenant " + tenantId + "."); TenantProcessStore tenantsProcessStore = bpelServer.getMultiTenantProcessStore() .getTenantsProcessStore(tenantId); if (tenantsProcessStore != null) { Map dataPublisherMap = tenantsProcessStore.getDataPublisherMap(); if (dataPublisherMap != null) { Collection<EventPublisherConfig> eventPublisherConfig = dataPublisherMap.values(); Iterator<EventPublisherConfig> iterator = eventPublisherConfig.iterator(); while (iterator.hasNext()) { EventPublisherConfig publisherConfig = iterator.next(); if (publisherConfig.getDataPublisher() != null) { AsyncDataPublisher publisher = publisherConfig.getDataPublisher(); publisher.stop();//from w ww . j a va2s . co m } else if (publisherConfig.getLoadBalancingDataPublisher() != null) { LoadBalancingDataPublisher loadBalancingDataPublisher = publisherConfig .getLoadBalancingDataPublisher(); loadBalancingDataPublisher.stop(); } } eventPublisherConfig.clear(); } } }
From source file:edu.ksu.cis.indus.staticanalyses.concurrency.escape.MethodContext.java
/** * Retrieves the alias set in the given method context that corresponds to the given alias set in this method context. * // w ww . java2 s . c o m * @param ref the reference alias set that occurs in this context. * @param context the context in which <code>ref</code> occurs. * @return the alias set in this context and that corresponds to <code>ref</code>. This will be <code>null</code> if * there is no such alias set. * @pre ref != null and context != null */ AliasSet getImageOfRefInGivenContext(final AliasSet ref, final MethodContext context) { AliasSet _result = null; final Collection<Pair<AliasSet, AliasSet>> _temp = new HashSet<Pair<AliasSet, AliasSet>>(); final AliasSet _thisAS = getThisAS(); final AliasSet _thisAS2 = context.getThisAS(); if (_thisAS != null && _thisAS2 != null) { _temp.clear(); _result = _thisAS.getImageOfRefUnderRoot(_thisAS2, ref, _temp); } for (int _i = argAliasSets.size() - 1; _i >= 0 && _result == null; _i--) { final AliasSet _paramAS = getParamAS(_i); final AliasSet _paramAS2 = context.getParamAS(_i); if (_paramAS != null && _paramAS2 != null) { _temp.clear(); _result = _paramAS.getImageOfRefUnderRoot(_paramAS2, ref, _temp); } } if (_result == null) { final AliasSet _thrownAS = getThrownAS(); final AliasSet _thrownAS2 = context.getThrownAS(); if (_thrownAS != null && _thrownAS2 != null) { _temp.clear(); _result = _thrownAS.getImageOfRefUnderRoot(_thrownAS2, ref, _temp); } if (_result == null) { final AliasSet _returnAS = getReturnAS(); final AliasSet _returnAS2 = context.getReturnAS(); if (_returnAS != null && _returnAS2 != null) { _temp.clear(); _result = _returnAS.getImageOfRefUnderRoot(_returnAS2, ref, _temp); } } } return _result; }