List of usage examples for java.util Collection remove
boolean remove(Object o);
From source file:org.kuali.kpme.core.service.role.KPMERoleServiceImpl.java
protected <T> List<T> intersect(Collection<? extends T> a, Collection<? extends T> b) { List<T> result = new ArrayList<T>(); for (T t : a) { if (b.remove(t)) result.add(t);//from w ww . j a va 2s. c o m } return result; }
From source file:com.googlecode.concurrentlinkedhashmap.ConcurrentMapTest.java
@Test(dataProvider = "warmedMap") public void values_whenPopulated(Map<Integer, Integer> map) { Collection<Integer> values = map.values(); assertThat(values.contains(new Object()), is(false)); assertThat(values.remove(new Object()), is(false)); assertThat(values, hasSize((int) capacity())); for (int i = 0; i < capacity(); i++) { assertThat(values.contains(-i), is(true)); assertThat(values.remove(-i), is(true)); assertThat(values.remove(-i), is(false)); assertThat(values.contains(-i), is(false)); }/*from w w w.j a v a2s . co m*/ assertThat(map, is(emptyMap())); }
From source file:com.aw.core.dao.bean.sql.BeanSqlBuilderUpdateImpl.java
/** * Ejecuta un SQL Update /*from w ww .j a va 2s. c om*/ * @param propertyNamesToUpdate Lista de columnas a actualizar. Si es NULO se actualizan todas * @return el bean con los atributos modificados */ public Object updateFields(Collection propertyNamesToUpdate) { List propertyNamesUpdatedXIntercetor = new ArrayList(); if (interceptor != null) bean = interceptor.onUpdate(bean, propertyNamesUpdatedXIntercetor); ArrayList<Object> params = new ArrayList<Object>(); // UPDATE StringBuffer sqlUpdate = new StringBuffer().append("UPDATE ").append(metaInfo.getMainTable()); StringBuffer sqlSet = new StringBuffer(); // SET // SET Armar subset de columnas si se indica Collection<BeanMetaInfo.ColumnInfo> nonIdColumnInfoList = new ArrayList<BeanMetaInfo.ColumnInfo>( metaInfo.getNonIdColumns()); if (propertyNamesToUpdate != null) { for (BeanMetaInfo.ColumnInfo columnInfo : metaInfo.getNonIdColumns()) { if (propertyNamesToUpdate.contains(columnInfo.getBeanField()) || propertyNamesUpdatedXIntercetor.contains(columnInfo.getBeanField())) { // skip, columna debe ser actualizada } else { // remover de colleccion nonIdColumnInfoList.remove(columnInfo); } } } // SET armar sentencia SET for (BeanMetaInfo.ColumnInfo columnInfo : nonIdColumnInfoList) { if (interceptor != null && interceptor.skipColUpdate(columnInfo.getTable(), columnInfo.getColumn())) continue; if (sqlSet.length() > 0) sqlSet.append(", "); buildColEqValue(columnInfo, sqlSet, params); } // WHERE StringBuffer sqlWhere = new StringBuffer(); for (BeanMetaInfo.ColumnInfo columnInfo : metaInfo.getIdColumns()) { if (sqlWhere.length() > 0) sqlWhere.append(" AND "); buildColEqValue(columnInfo, sqlWhere, params); } // Unir String fullSql = sqlUpdate + " SET " + sqlSet + " WHERE " + sqlWhere; int rows = execSqlUpdate(fullSql, params.toArray()); if (rows != 1) throw new AWBusinessException("Se esperaba actualizar un registro. Registros actualizados:" + rows); return bean; }
From source file:eu.annocultor.converters.geonames.GeonamesCsvToRdf.java
void features() throws Exception { System.out.println("Parsing features"); // load country-continent match countryToContinent.load(//from www . j a v a2 s .c om (new GeonamesCsvToRdf("EU")).getClass().getResourceAsStream("/country-to-continent.properties")); createDirsForContinents(); long counter = 0; LineIterator it = FileUtils.lineIterator(new File(root, "allCountries.txt"), "UTF-8"); try { while (it.hasNext()) { String text = it.nextLine(); String[] fields = text.split("\t"); if (fields.length != 19) { throw new Exception("Field names mismatch on " + text); } // progress counter++; if (counter % 100000 == 0) { System.out.print("*"); } String country = fields[countryCode]; String continent = countryToContinent.getProperty(country); if (continent != null && continent.startsWith(continentToConvert)) { String id = fields[geonameid]; String uri = NS_GEONAMES_INSTANCES + id + "/"; String featureCodeField = fields[featureClass] + "." + fields[featureCode]; String populationValue = fields[population]; if (includeRecordInConversion(featureCodeField, populationValue)) { boolean isDescriptionOfCountry = featureCodeField.startsWith("A.PCLI"); if (!fields[name].isEmpty()) { write(country, new Triple(uri, SKOS.LABEL_PREFERRED, new LiteralValue(fields[name]), null), isDescriptionOfCountry); } // String altLabels[] = fields[alternatenames].split(","); // for (String altLabel : altLabels) { // write(country, new Triple(uri, SKOS.LABEL_ALT, new LiteralValue(altLabel), null)); // } Collection<LiteralValue> altLabelCollection = altLabels.getCollection(id); if (altLabelCollection != null) { for (LiteralValue xmlValue : altLabelCollection) { write(country, new Triple(uri, SKOS.LABEL_ALT, xmlValue, null), isDescriptionOfCountry); } altLabels.remove(id); } Collection<String> linkCollection = links.getCollection(id); if (linkCollection != null) { for (String link : linkCollection) { // write(country, new Triple(uri, new Property(NS_EUROPEANA_SCHEMA + "link"), new LiteralValue(link), null)); } linkCollection.remove(fields[geonameid]); } if (fields[population].length() > 1) { write(country, new Triple(uri, new Property(NS_EUROPEANA_SCHEMA + "population"), new LiteralValue(fields[population]), null), isDescriptionOfCountry); } if (!fields[longitude].isEmpty()) { write(country, new Triple(uri, new Property(NS_WGS_SCHEMA + "long"), new LiteralValue(fields[longitude]), null), isDescriptionOfCountry); } if (!fields[latitude].isEmpty()) { write(country, new Triple(uri, new Property(NS_WGS_SCHEMA + "lat"), new LiteralValue(fields[latitude]), null), isDescriptionOfCountry); } if (!featureCodeField.isEmpty()) { write(country, new Triple(uri, new Property(NS_EUROPEANA_SCHEMA + "division"), new ResourceValue(NS_GEONAMES_ONTOLOGY + featureCodeField), null), isDescriptionOfCountry); } if (!country.isEmpty()) { write(country, new Triple(uri, new Property(NS_EUROPEANA_SCHEMA + "country"), new LiteralValue(country), null), isDescriptionOfCountry); } // alt label as country code if (featureCodeField.startsWith("A.PCL")) { write(country, new Triple(uri, SKOS.LABEL_ALT, new LiteralValue(country), null), isDescriptionOfCountry); } for (String broaderUri : allParents(uri, country)) { write(country, new Triple(uri, Concepts.DCTEMRS.IS_PART_OF, new ResourceValue(broaderUri), null), isDescriptionOfCountry); } // if (!fields[admin1code].isEmpty()) { // write(country, new Triple(uri, new Property(NS_EUROPEANA_SCHEMA + "admin1"), new LiteralValue(fields[admin1code]), null), isDescriptionOfCountry); // } // if (!fields[admin2code].isEmpty()) { // write(country, new Triple(uri, new Property(NS_EUROPEANA_SCHEMA + "admin2"), new LiteralValue(fields[admin2code]), null), isDescriptionOfCountry); // } // if (!fields[admin3code].isEmpty()) { // write(country, new Triple(uri, new Property(NS_EUROPEANA_SCHEMA + "admin3"), new LiteralValue(fields[admin3code]), null), isDescriptionOfCountry); // } // if (!fields[admin4code].isEmpty()) { // write(country, new Triple(uri, new Property(NS_EUROPEANA_SCHEMA + "admin4"), new LiteralValue(fields[admin4code]), null), isDescriptionOfCountry); // } } } } } finally { LineIterator.closeQuietly(it); } System.out.println("Finished conversion, flushing and closing output files"); System.out.flush(); for (Object country : countryToContinent.keySet()) { SesameWriter bf = files.get(country.toString()); if (bf != null) { bf.endRDF(); } } if (allCountries != null) { allCountries.endRDF(); } }
From source file:org.sipfoundry.sipxconfig.commserver.imdb.ReplicationManagerImpl.java
/** * Removes the specified Permission from the entities that have it. *//*from www.j a va 2 s . c o m*/ @Override public void removePermission(Permission permission) { try { DBCursor users = m_validUsers.getEntitiesWithPermission(permission.getName()); for (DBObject user : users) { Collection<String> prms = (Collection<String>) user.get(MongoConstants.PERMISSIONS); prms.remove(permission.getName()); user.put(MongoConstants.PERMISSIONS, prms); getEntityCollection().save(user); } } catch (Exception e) { LOG.error(ERROR_PERMISSION, e); throw new UserException(ERROR_PERMISSION, e); } }
From source file:org.kuali.kra.award.awardhierarchy.sync.helpers.AwardSyncPersonHelper.java
@SuppressWarnings("unchecked") @Override//ww w . j a v a 2s .c o m public void applySyncChange(Award award, AwardSyncChange change) throws NoSuchFieldException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException, InstantiationException { Collection awardPersons = award.getProjectPersons(); AwardPerson person = (AwardPerson) getAwardSyncUtilityService().findMatchingBo(awardPersons, change.getXmlExport().getKeys()); if (StringUtils.equals(change.getSyncType(), AwardSyncType.ADD_SYNC.getSyncValue())) { if (person != null) { this.setValuesOnSyncable(person, change.getXmlExport().getValues(), change); } else { person = new AwardPerson(); setValuesOnSyncable(person, change.getXmlExport().getKeys(), change); setValuesOnSyncable(person, change.getXmlExport().getValues(), change); award.add(person); } } else { if (person != null) { awardPersons.remove(person); } } }
From source file:uk.ac.ebi.intact.editor.services.curate.complex.ComplexEditorService.java
private void initialiseFeatures(ModelledParticipant parent, Collection<ModelledFeature> features, ModelledFeatureCloner featureCloner) { List<ModelledFeature> originalFeatures = new ArrayList<ModelledFeature>(features); for (ModelledFeature r : originalFeatures) { if (!isFeatureInitialised(r)) { ModelledFeature reloaded = initialiseFeature(r, featureCloner); if (reloaded != r) { features.remove(r); parent.addFeature(reloaded); }/* w w w . j a va2 s . c om*/ } } }
From source file:net.paissad.jcamstream.utils.PropertiesConfTest.java
/** * Test method for//from w ww . ja va 2 s . c o m * {@link net.paissad.jcamstream.utils.PropertiesConf#values()}. * * @throws IOException */ @Test public final void testValues() throws IOException { PropertiesConf props = new PropertiesConf(); props.load(new FileInputStream(testPropsFile)); Collection<String> expected_values = new ArrayList<String>(), actual_values; expected_values.add("AAA"); expected_values.add("BBB"); expected_values.add("CCC"); actual_values = props.values(); Assert.assertEquals(expected_values, actual_values); props.put("dd", "DDD"); expected_values.add("DDD"); actual_values = props.values(); Assert.assertEquals(expected_values, actual_values); props.remove("aa"); expected_values.remove("AAA"); actual_values = props.values(); Assert.assertEquals(expected_values, actual_values); props.clear(); actual_values = props.values(); Assert.assertNull(actual_values); }
From source file:com.haulmont.cuba.core.app.cache.StandardCacheLoader.java
@Override public void updateData(CacheSet cacheSet, Map<String, Object> params) throws CacheException { if (configuration.getConfig(GlobalConfig.class).getTestMode()) return;//from w w w .j a v a2 s . c om Collection<Object> items = cacheSet.getItems(); List updateItems = (List) params.get("items"); if ((updateItems != null) && (updateItems.size() > 0)) { MetaClass metaClass = metadata.getSession().getClass(metaClassName); View view = metadata.getViewRepository().getView(metaClass, viewName); Transaction tx = persistence.createTransaction(); try { EntityManager em = persistence.getEntityManager(); for (Object item : updateItems) { Entity entity = (Entity) item; entity = em.find(entity.getClass(), entity.getId(), view); items.remove(item); if (entity != null) items.add(entity); } tx.commit(); } catch (Exception e) { throw new CacheException(e); } finally { tx.end(); } } else { log.debug("Nothing to update"); } }
From source file:org.kuali.kra.award.awardhierarchy.sync.helpers.AwardSyncReportHelper.java
@SuppressWarnings("unchecked") @Override//from w ww . ja v a 2 s.c o m public void applySyncChange(Award award, AwardSyncChange change) throws NoSuchFieldException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException, InstantiationException { Collection reports = award.getAwardReportTermItems(); AwardReportTerm report = (AwardReportTerm) getAwardSyncUtilityService().findMatchingBo(reports, change.getXmlExport().getKeys()); if (StringUtils.equals(change.getSyncType(), AwardSyncType.ADD_SYNC.getSyncValue())) { if (report != null) { this.setValuesOnSyncable(report, change.getXmlExport().getValues(), change); } else { report = new AwardReportTerm(); setValuesOnSyncable(report, change.getXmlExport().getKeys(), change); setValuesOnSyncable(report, change.getXmlExport().getValues(), change); award.add(report); } } else { if (report != null) { reports.remove(report); } } }