List of usage examples for java.util Collection remove
boolean remove(Object o);
From source file:org.meveo.admin.action.BaseBean.java
/** * Change value in a collection. Collection to update an item index are passed as attributes * //from ww w. j a v a2s .co m * @param event Value change event */ @SuppressWarnings({ "rawtypes", "unchecked" }) public void updateItemInCollection(ValueChangeEvent event) { Collection values = (Collection) event.getComponent().getAttributes().get("values"); values.remove(event.getOldValue()); values.add(event.getNewValue()); // Unpredictable results when changing several values at a time, as Set does not guarantee same value order - could be used only in Ajax and only with refresh // int itemIndex = (int) event.getComponent().getAttributes().get("itemIndex"); // log.error("AKK changing value from {} to {} in index {} values {}", event.getOldValue(), event.getNewValue(), itemIndex, values.toArray()); // ArrayList newValues = new ArrayList(); // newValues.addAll(values); // // newValues.remove(itemIndex); // newValues.add(itemIndex, event.getNewValue()); // values.clear(); // values.addAll(newValues); // log.error("AKK end changing value from {} to {} in index {} values {}", event.getOldValue(), event.getNewValue(), itemIndex, values.toArray()); }
From source file:org.fusesource.meshkeeper.distribution.registry.zk.ZooKeeperRegistry.java
private Collection<String> list(String path, boolean recursive, Collection<String> results, Collection<String> filters) throws Exception { try {// ww w . jav a 2 s.c o m List<String> children = null; byte[] data = zk.getData(path, false, null); if (data != null && data.length > 0) { results.add(path + " [" + data.length + "]"); } else { children = zk.getChildren(path, recursive); if (children.size() == 0) { results.add(path + " [" + (data == null ? "-" : data.length) + "]"); if (recursive) { return results; } } } if (recursive) { children = zk.getChildren(path, recursive); if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } for (String child : children) { String childPath = path + "/" + child; if (!filters.remove(childPath)) { list(childPath, recursive, results, filters); } } } } catch (NoNodeException nne) { return results; } return results; }
From source file:com.adito.activedirectory.ActiveDirectoryUserDatabase.java
private void loadUsers(final String filter, InitialLdapContext context, final boolean removeMissingEntries) throws NamingException { final Collection<String> usernames = userContainer.retrievePrincipalNames(); PagedResultMapper mapper = new AbstractPagedResultMapper() { public void mapSearchResult(SearchResult searchResult) throws NamingException, UserDatabaseException { String dn = searchResult.getNameInNamespace(); ActiveDirectoryUser user = populateActiveDirectoryUser(dn, searchResult.getAttributes()); String key = userContainer.storePrincipal(user); usernames.remove(key); if (logger.isDebugEnabled()) { logger.debug("Found user " + user); }/*from w ww .j a v a2 s. c om*/ } }; try { String replacedFilter = buildUserFilter(filter); PagedResultTemplate pagedResultTemplate = configuration.getPagedResultTemplate(); pagedResultTemplate.search(context, replacedFilter, USER_ATTRS, mapper); } finally { if (removeMissingEntries) { userContainer.updateRemovedPrincipals(usernames); } } }
From source file:ubic.gemma.datastructure.matrix.ExpressionDataMatrixColumnSort.java
/** * @param start//from w w w .j a va2s . com * @param factorsToUse * @return list of factors, sorted from simplest (fewest number of values from the biomaterials passed in) to least * simple */ public static List<ExperimentalFactor> orderFactorsByExperimentalDesign(List<BioMaterial> start, Collection<ExperimentalFactor> factors) { if (factors == null || factors.isEmpty()) { log.warn("No factors supplied for sorting"); return new LinkedList<ExperimentalFactor>(); } LinkedList<ExperimentalFactor> sortedFactors = new LinkedList<ExperimentalFactor>(); Collection<ExperimentalFactor> factorsToTake = new HashSet<ExperimentalFactor>(factors); while (!factorsToTake.isEmpty()) { ExperimentalFactor simplest = chooseSimplestFactor(start, factorsToTake); if (simplest == null) { // none of the factors have more than one factor value. One-sided t-tests ... /* * This assertion isn't right -- we now allow this, though we can only have ONE such constant factor. * See bug 2390. Unless we are dealing with a subset, in which case there can be any number of constant * factors within the subset. */ // assert factors.size() == 1 : // "It's possible to have just one factor value, but only if there is only one factor."; sortedFactors.addAll(factors); return sortedFactors; } sortedFactors.addLast(simplest); factorsToTake.remove(simplest); } return sortedFactors; }
From source file:ubic.gemma.datastructure.matrix.ExpressionDataMatrixColumnSort.java
/** * @param start//from w ww.java 2 s .c om * @param factorsToUse * @return list of factors, sorted from simplest (fewest number of values from the biomaterials passed in) to least * simple */ public static List<ExperimentalFactor> orderFactorsByExperimentalDesignVO(List<BioMaterialValueObject> start, Collection<ExperimentalFactor> factors) { if (factors == null || factors.isEmpty()) { log.warn("No factors supplied for sorting"); return new LinkedList<ExperimentalFactor>(); } LinkedList<ExperimentalFactor> sortedFactors = new LinkedList<ExperimentalFactor>(); Collection<ExperimentalFactor> factorsToTake = new HashSet<ExperimentalFactor>(factors); while (!factorsToTake.isEmpty()) { ExperimentalFactor simplest = chooseSimplestFactorVO(start, factorsToTake); if (simplest == null) { // none of the factors have more than one factor value. One-sided t-tests ... /* * This assertion isn't right -- we now allow this, though we can only have ONE such constant factor. * See bug 2390. Unless we are dealing with a subset, in which case there can be any number of constant * factors within the subset. */ // assert factors.size() == 1 : // "It's possible to have just one factor value, but only if there is only one factor."; sortedFactors.addAll(factors); return sortedFactors; } sortedFactors.addLast(simplest); factorsToTake.remove(simplest); } return sortedFactors; }
From source file:forge.card.CardDb.java
private PaperCard tryGetCard(CardRequest request) { Collection<PaperCard> cards = allCardsByName.get(request.cardName); if (cards == null) { return null; }/*w ww. j a v a 2 s. co m*/ PaperCard result = null; String reqEdition = request.edition; if (reqEdition != null && !editions.contains(reqEdition)) { CardEdition edition = editions.get(reqEdition); if (edition != null) { reqEdition = edition.getCode(); } } if (request.artIndex <= 0) { // this stands for 'random art' Collection<PaperCard> candidates; if (reqEdition == null) { candidates = new ArrayList<PaperCard>(cards); } else { candidates = new ArrayList<PaperCard>(); for (PaperCard pc : cards) { if (pc.getEdition().equalsIgnoreCase(reqEdition)) { candidates.add(pc); } } } if (candidates.isEmpty()) { return null; } result = Aggregates.random(candidates); //if card image doesn't exist for chosen candidate, try another one if possible while (candidates.size() > 1 && !result.hasImage()) { candidates.remove(result); result = Aggregates.random(candidates); } } else { for (PaperCard pc : cards) { if (pc.getEdition().equalsIgnoreCase(reqEdition) && request.artIndex == pc.getArtIndex()) { result = pc; break; } } } if (result == null) { return null; } return request.isFoil ? getFoiled(result) : result; }
From source file:com.xchanging.support.batch.admin.service.SimpleJobService.java
public Collection<StepExecution> getStepExecutions(Long jobExecutionId) throws NoSuchJobExecutionException { JobExecution jobExecution = jobExecutionDao.getJobExecution(jobExecutionId); if (jobExecution == null) { throw new NoSuchJobExecutionException("No JobExecution with id=" + jobExecutionId); }//from w ww . j a v a 2s .com stepExecutionDao.addStepExecutions(jobExecution); String jobName = jobExecution.getJobInstance() == null ? null : jobExecution.getJobInstance().getJobName(); Collection<String> missingStepNames = new LinkedHashSet<String>(); if (jobName != null) { missingStepNames.addAll(stepExecutionDao.findStepNamesForJobExecution(jobName, "*:partition*")); logger.debug("Found step executions in repository: " + missingStepNames); } Job job = null; try { job = jobLocator.getJob(jobName); } catch (NoSuchJobException e) { // expected } if (job instanceof StepLocator) { Collection<String> stepNames = ((StepLocator) job).getStepNames(); missingStepNames.addAll(stepNames); logger.debug("Added step executions from job: " + missingStepNames); } for (StepExecution stepExecution : jobExecution.getStepExecutions()) { String stepName = stepExecution.getStepName(); if (missingStepNames.contains(stepName)) { missingStepNames.remove(stepName); } logger.debug("Removed step executions from job execution: " + missingStepNames); } for (String stepName : missingStepNames) { StepExecution stepExecution = jobExecution.createStepExecution(stepName); stepExecution.setStatus(BatchStatus.UNKNOWN); } return jobExecution.getStepExecutions(); }
From source file:nl.strohalm.cyclos.services.customization.CustomFieldServiceImpl.java
public void removePaymentCustomField(TransferType transferType, PaymentCustomField customField) { transferType = fetchService.fetch(transferType, TransferType.Relationships.LINKED_CUSTOM_FIELDS); customField = fetchService.fetch(customField); if (transferType.equals(customField.getTransferType())) { customFieldDao.delete(customField.getId()); } else {/* w w w.j a v a 2 s .co m*/ final Collection<PaymentCustomField> linkedCustomFields = transferType.getLinkedCustomFields(); // The underlying persistence engine should persist the relationship linkedCustomFields.remove(customField); } }
From source file:org.kaaproject.kaa.server.common.dao.service.ProfileServiceImpl.java
@Override public List<ProfileVersionPairDto> findVacantSchemasByEndpointGroupId(String endpointGroupId) { validateSqlId(endpointGroupId, "Can't find vacant schemas. Invalid endpoint group id: " + endpointGroupId); EndpointGroup group = endpointGroupDao.findById(endpointGroupId); String appId = group.getApplicationId(); List<ServerProfileSchemaDto> serverSchemas = serverProfileService.findServerProfileSchemasByAppId(appId); Collections.sort(serverSchemas); List<EndpointProfileSchemaDto> endpointProfileSchemas = findProfileSchemasByAppId(appId); Collections.sort(endpointProfileSchemas); Collection<ProfileVersionPairDto> pairVersionSet = new HashSet<>(); for (int i = 0; i < endpointProfileSchemas.size(); i++) { EndpointProfileSchemaDto endSchema = endpointProfileSchemas.get(i); for (ServerProfileSchemaDto serverSchema : serverSchemas) { if (i == 0) { pairVersionSet.add(new ProfileVersionPairDto(serverSchema.getId(), serverSchema.getVersion())); }//ww w.jav a 2 s.c o m pairVersionSet.add(new ProfileVersionPairDto(endSchema.getId(), endSchema.getVersion(), serverSchema.getId(), serverSchema.getVersion())); } pairVersionSet.add(new ProfileVersionPairDto(endSchema.getVersion(), endSchema.getId())); } List<ProfileFilter> profileFilters = profileFilterDao.findActualByEndpointGroupId(endpointGroupId); for (ProfileFilter pf : profileFilters) { pairVersionSet.remove( new ProfileVersionPairDto(pf.getEndpointProfileSchemaId(), pf.getEndpointProfileSchemaVersion(), pf.getServerProfileSchemaId(), pf.getServerProfileSchemaVersion())); } return new ArrayList<>(pairVersionSet); }
From source file:org.apache.solr.response.CSVResponseWriter.java
public void writeResponse() throws IOException { SolrParams params = req.getParams(); strategy = new CSVStrategy(',', '"', CSVStrategy.COMMENTS_DISABLED, CSVStrategy.ESCAPE_DISABLED, false, false, false, true);//from w w w . j av a 2 s . co m CSVStrategy strat = strategy; String sep = params.get(CSV_SEPARATOR); if (sep != null) { if (sep.length() != 1) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid separator:'" + sep + "'"); strat.setDelimiter(sep.charAt(0)); } String nl = params.get(CSV_NEWLINE); if (nl != null) { if (nl.length() == 0) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid newline:'" + nl + "'"); strat.setPrinterNewline(nl); } String encapsulator = params.get(CSV_ENCAPSULATOR); String escape = params.get(CSV_ESCAPE); if (encapsulator != null) { if (encapsulator.length() != 1) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid encapsulator:'" + encapsulator + "'"); strat.setEncapsulator(encapsulator.charAt(0)); } if (escape != null) { if (escape.length() != 1) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid escape:'" + escape + "'"); strat.setEscape(escape.charAt(0)); if (encapsulator == null) { strat.setEncapsulator(CSVStrategy.ENCAPSULATOR_DISABLED); } } if (strat.getEscape() == '\\') { // If the escape is the standard backslash, then also enable // unicode escapes (it's harmless since 'u' would not otherwise // be escaped. strat.setUnicodeEscapeInterpretation(true); } printer = new CSVPrinter(writer, strategy); CSVStrategy mvStrategy = new CSVStrategy(strategy.getDelimiter(), CSVStrategy.ENCAPSULATOR_DISABLED, CSVStrategy.COMMENTS_DISABLED, '\\', false, false, false, false); strat = mvStrategy; sep = params.get(MV_SEPARATOR); if (sep != null) { if (sep.length() != 1) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid mv separator:'" + sep + "'"); strat.setDelimiter(sep.charAt(0)); } encapsulator = params.get(MV_ENCAPSULATOR); escape = params.get(MV_ESCAPE); if (encapsulator != null) { if (encapsulator.length() != 1) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid mv encapsulator:'" + encapsulator + "'"); strat.setEncapsulator(encapsulator.charAt(0)); if (escape == null) { strat.setEscape(CSVStrategy.ESCAPE_DISABLED); } } escape = params.get(MV_ESCAPE); if (escape != null) { if (escape.length() != 1) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid mv escape:'" + escape + "'"); strat.setEscape(escape.charAt(0)); // encapsulator will already be disabled if it wasn't specified } returnScore = returnFields != null && returnFields.contains("score"); boolean needListOfFields = returnFields == null || returnFields.size() == 0 || (returnFields.size() == 1 && returnScore) || returnFields.contains("*"); Collection<String> fields = returnFields; Object responseObj = rsp.getValues().get("response"); if (needListOfFields) { if (responseObj instanceof SolrDocumentList) { // get the list of fields from the SolrDocumentList fields = new LinkedHashSet<String>(); for (SolrDocument sdoc : (SolrDocumentList) responseObj) { fields.addAll(sdoc.getFieldNames()); } } else { // get the list of fields from the index fields = req.getSearcher().getFieldNames(); } if (returnScore) { fields.add("score"); } else { fields.remove("score"); } } CSVSharedBufPrinter csvPrinterMV = new CSVSharedBufPrinter(mvWriter, mvStrategy); for (String field : fields) { if (field.equals("score")) { CSVField csvField = new CSVField(); csvField.name = "score"; csvFields.put("score", csvField); continue; } SchemaField sf = schema.getFieldOrNull(field); if (sf == null) { FieldType ft = new StrField(); sf = new SchemaField(field, ft); } // if we got the list of fields from the index, only list stored fields if (returnFields == null && sf != null && !sf.stored()) { continue; } // check for per-field overrides sep = params.get("f." + field + '.' + CSV_SEPARATOR); encapsulator = params.get("f." + field + '.' + CSV_ENCAPSULATOR); escape = params.get("f." + field + '.' + CSV_ESCAPE); CSVSharedBufPrinter csvPrinter = csvPrinterMV; if (sep != null || encapsulator != null || escape != null) { // create a new strategy + printer if there were any per-field overrides strat = (CSVStrategy) mvStrategy.clone(); if (sep != null) { if (sep.length() != 1) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid mv separator:'" + sep + "'"); strat.setDelimiter(sep.charAt(0)); } if (encapsulator != null) { if (encapsulator.length() != 1) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid mv encapsulator:'" + encapsulator + "'"); strat.setEncapsulator(encapsulator.charAt(0)); if (escape == null) { strat.setEscape(CSVStrategy.ESCAPE_DISABLED); } } if (escape != null) { if (escape.length() != 1) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid mv escape:'" + escape + "'"); strat.setEscape(escape.charAt(0)); if (encapsulator == null) { strat.setEncapsulator(CSVStrategy.ENCAPSULATOR_DISABLED); } } csvPrinter = new CSVSharedBufPrinter(mvWriter, strat); } CSVField csvField = new CSVField(); csvField.name = field; csvField.sf = sf; csvField.mvPrinter = csvPrinter; csvFields.put(field, csvField); } NullValue = params.get(CSV_NULL, ""); if (params.getBool(CSV_HEADER, true)) { for (CSVField csvField : csvFields.values()) { printer.print(csvField.name); } printer.println(); } if (responseObj instanceof DocList) { writeDocList(null, (DocList) responseObj, null, null); } else if (responseObj instanceof SolrDocumentList) { writeSolrDocumentList(null, (SolrDocumentList) responseObj, null, null); } }