List of usage examples for java.util Collection remove
boolean remove(Object o);
From source file:ubic.gemma.core.analysis.service.ArrayDesignAnnotationServiceImpl.java
/** * @param ty Configures which GO terms to return: With all parents, biological process only, or direct annotations * only.//from ww w . ja v a2 s.c o m * @return the goTerms for a given gene, as configured */ private Collection<OntologyTerm> getGoTerms(Collection<Characteristic> ontologyTerms, OutputType ty) { Collection<OntologyTerm> results = new HashSet<>(); if (ontologyTerms == null || ontologyTerms.size() == 0) return results; for (Characteristic vc : ontologyTerms) { results.add(goService.getTermForId(vc.getValue())); } if (ty.equals(OutputType.SHORT)) return results; if (ty.equals(OutputType.LONG)) { Collection<OntologyTerm> oes = goService.getAllParents(results); results.addAll(oes); } else if (ty.equals(OutputType.BIOPROCESS)) { Collection<OntologyTerm> toRemove = new HashSet<>(); for (OntologyTerm ont : results) { if ((ont == null)) { continue; // / shouldn't happen! } if (!goService.isBiologicalProcess(ont)) { toRemove.add(ont); } } for (OntologyTerm toRemoveOnto : toRemove) { results.remove(toRemoveOnto); } } return results; }
From source file:org.rhq.core.clientapi.agent.metadata.PluginDependencyGraph.java
/** * Given a known plugin name, this returns all dependencies of that plugin (including those dependencies of its * dependencies, down N levels). If a dependency is missing but is required, an exception is thrown - missing * optional plugins are simply ignored and not returned in the set but otherwise no errors occur. * * @param pluginName//from w w w.j a va 2s . c o m * @param dependingPlugins set of plugins that are known to be depending on pluginName (must not be <code> * null</code>) * @param required if <code>true</code>, then <code>pluginName</code> must exist in the graph. If it does not, an * exception will be thrown. Otherwise, it is considered an optional plugin and if it is missing, * it will be ignored. * * @return the dependencies * * @throws IllegalStateException if the given plugin has a circular dependency * @throws IllegalArgumentException if the plugin hasn't been added to the graph yet */ private Set<String> getDeepDependencies(String pluginName, Collection<String> dependingPlugins, boolean required) throws IllegalStateException, IllegalArgumentException { HashSet<String> results = new HashSet<String>(); List<PluginDependency> childDependencies = dependencyMap.get(pluginName); if (childDependencies == null) { if (required) { throw new IllegalArgumentException("Plugin [" + pluginName + "] is required by plugins [" + dependingPlugins + "] but it does not exist in the dependency graph yet"); } log.info("Optional plugin [" + pluginName + "] was requested by plugins [" + dependingPlugins + "] but it does not exist in the dependency graph yet and will be ignored"); } else { for (PluginDependency childDependency : childDependencies) { if (dependingPlugins.contains(childDependency.name)) { throw createCircularDependencyException(childDependency.name); } dependingPlugins.add(pluginName); Set<String> childDeepDependencies = getDeepDependencies(childDependency.name, dependingPlugins, childDependency.required); dependingPlugins.remove(pluginName); results.add(childDependency.name); results.addAll(childDeepDependencies); } } return results; }
From source file:org.folg.names.search.Searcher.java
/** * Get additional tokens to search// w w w . j a va 2 s . c o m * @param namePiece normalized name piece * @return tokens to search in addition to the namePiece */ public Collection<String> getAdditionalSearchTokens(String namePiece) { Collection<String> tokens = new HashSet<String>(); // add search tokens for this name addSearchTokens(namePiece, tokens, false, true); if (isSurname) { // if prefixed surname, include basename and similar names String basename = getBasename(namePiece); if (basename != null) { addSearchTokens(basename, tokens, true, true); } else { // if this is a basename, include all prefixed versions (but not similar names or the codes for them) Collection<String> prefixedNames = getPrefixedNames(namePiece); if (prefixedNames != null) { for (String prefixedName : prefixedNames) { tokens.add(prefixedName); // don't add codes for prefixed names; I think it would be non-intuitive to have names with the same soundex as a prefixed form show up // we index the code for the basename of rare prefixed surnames to compensate // addSearchTokens(prefixedName, tokens, true, false); } } } } tokens.remove(namePiece); // just in case the namePiece was added return tokens; }
From source file:eu.medsea.mimeutil.MimeUtil2.java
/** * Get all of the matching mime types for this InputStream object. * The method delegates down to each of the registered MimeHandler(s) and returns a * normalised list of all matching mime types. If no matching mime types are found the returned * Collection will contain the unknownMimeType passed in. * @param in the InputStream object to detect. * @param unknownMimeType./*from w w w . java 2 s. c om*/ * @return the Collection of matching mime types. If the collection would be empty i.e. no matches then this will * contain the passed in parameter unknownMimeType * @throws MimeException if there are problems such as reading files generated when the MimeHandler(s) * executed. */ public final Collection getMimeTypes(final InputStream in, final MimeType unknownMimeType) throws MimeException { Collection mimeTypes = new MimeTypeHashSet(); if (in == null) { log.error("InputStream reference cannot be null."); } else { if (!in.markSupported()) { throw new MimeException("InputStream must support the mark() and reset() methods."); } if (log.isDebugEnabled()) { log.debug("Getting MIME types for InputSteam [" + in + "]."); } mimeTypes.addAll(mimeDetectorRegistry.getMimeTypes(in)); // We don't want the unknownMimeType added to the collection by MimeDetector(s) mimeTypes.remove(unknownMimeType); } // If the collection is empty we want to add the unknownMimetype if (mimeTypes.isEmpty()) { mimeTypes.add(unknownMimeType); } if (log.isDebugEnabled()) { log.debug("Retrieved MIME types [" + mimeTypes.toString() + "]"); } return mimeTypes; }
From source file:eu.medsea.mimeutil.MimeUtil2.java
/** * Get a Collection of possible MimeType(s) that this byte array could represent * according to the registered MimeDetector(s). If no MimeType(s) are detected * then the returned Collection will contain only the passed in unknownMimeType * @param data/* w w w.ja v a2s.c om*/ * @param unknownMimeType used if the registered MimeDetector(s) fail to match any MimeType(s) * @return all matching MimeType(s) * @throws MimeException */ public final Collection getMimeTypes(final byte[] data, final MimeType unknownMimeType) throws MimeException { Collection mimeTypes = new MimeTypeHashSet(); if (data == null) { log.error("byte array cannot be null."); } else { if (log.isDebugEnabled()) { try { log.debug("Getting MIME types for byte array [" + StringUtil.getHexString(data) + "]."); } catch (UnsupportedEncodingException e) { throw new MimeException(e); } } mimeTypes.addAll(mimeDetectorRegistry.getMimeTypes(data)); // We don't want the unknownMimeType added to the collection by MimeDetector(s) mimeTypes.remove(unknownMimeType); } // If the collection is empty we want to add the unknownMimetype if (mimeTypes.isEmpty()) { mimeTypes.add(unknownMimeType); } if (log.isDebugEnabled()) { log.debug("Retrieved MIME types [" + mimeTypes.toString() + "]"); } return mimeTypes; }
From source file:org.jahia.modules.portal.service.PortalService.java
public PortalContext buildPortalContext(RenderContext renderContext, JCRNodeWrapper portalTabNode, JCRSessionWrapper sessionWrapper, final boolean updateLastPortalUsed) throws RepositoryException { final String currentPath = portalTabNode.getPath(); final boolean isEditable = portalTabNode.hasPermission("jcr:write_live"); final Locale mainResourceLocale = renderContext.getMainResourceLocale(); final String siteKey = renderContext.getSite().getSiteKey(); PortalContext portalContext = JCRTemplate.getInstance().doExecuteWithSystemSession( sessionWrapper.getUser().getUsername(), sessionWrapper.getWorkspace().getName(), sessionWrapper.getLocale(), new JCRCallback<PortalContext>() { @Override//from w w w . ja va2s .c o m public PortalContext doInJCR(JCRSessionWrapper session) throws RepositoryException { JCRNodeWrapper portalTabNode = session.getNode(currentPath); JCRNodeWrapper portalNode = JCRContentUtils.getParentOfType(portalTabNode, PortalConstants.JMIX_PORTAL); PortalContext portalContext = new PortalContext(); boolean isModel = portalNode.isNodeType(PortalConstants.JNT_PORTAL_MODEL); portalContext.setEditable(isEditable); portalContext.setPath(portalNode.getPath()); portalContext.setIdentifier(portalNode.getIdentifier()); portalContext.setTabPath(portalTabNode.getPath()); portalContext.setTabIdentifier(portalTabNode.getIdentifier()); portalContext.setFullTemplate( portalNode.getProperty(PortalConstants.J_FULL_TEMPLATE).getString()); portalContext.setLock(portalNode.hasProperty(PortalConstants.J_LOCKED) && portalNode.getProperty(PortalConstants.J_LOCKED).getBoolean()); portalContext.setModel(isModel); portalContext.setCustomizable(isModel && portalNode.hasProperty(PortalConstants.J_ALLOW_CUSTOMIZATION) && portalNode.getProperty(PortalConstants.J_ALLOW_CUSTOMIZATION).getBoolean()); JCRSiteNode site = JahiaSitesService.getInstance().getSiteByKey(siteKey, session); JCRNodeWrapper modelNode = null; boolean modelDeleted = false; if (isModel) { portalContext.setEnabled(portalNode.hasProperty(PortalConstants.J_ENABLED) && portalNode.getProperty(PortalConstants.J_ENABLED).getBoolean()); } else { try { modelNode = (JCRNodeWrapper) portalNode.getProperty(PortalConstants.J_MODEL) .getNode(); } catch (Exception e) { // model deleted } if (modelNode != null) { portalContext.setModelPath(modelNode.getPath()); portalContext.setModelIdentifier(modelNode.getIdentifier()); portalContext.setEnabled(modelNode.hasProperty(PortalConstants.J_ENABLED) && modelNode.getProperty(PortalConstants.J_ENABLED).getBoolean()); } else { portalContext.setEnabled(false); modelDeleted = true; } } portalContext.setSiteKey(site.getSiteKey()); portalContext.setPortalTabTemplates(new ArrayList<PortalKeyNameObject>()); portalContext.setPortalTabSkins(new ArrayList<PortalKeyNameObject>()); portalContext.setPortalWidgetTypes(new TreeSet<PortalWidgetType>(WIDGET_TYPES_COMPARATOR)); if (isEditable) { // Templates for portal tabs List<JCRNodeWrapper> templates = getPortalTabTemplates( portalNode.getProperty(PortalConstants.J_TEMPLATE_ROOT_PATH).getString(), session); for (JCRNodeWrapper template : templates) { PortalKeyNameObject portalTabTemplate = new PortalKeyNameObject(); portalTabTemplate.setName(template.getDisplayableName()); portalTabTemplate.setKey(template.getName()); portalContext.getPortalTabTemplates().add(portalTabTemplate); } // Widget skins SortedSet<View> widgetSkins = getViewSet(PortalConstants.JMIX_PORTAL_WIDGET, site); for (View widgetView : widgetSkins) { if (widgetView.getKey().startsWith("box")) { PortalKeyNameObject portalTabSkin = new PortalKeyNameObject(); try { portalTabSkin.setName(Messages.get(widgetView.getModule(), widgetView.getKey(), mainResourceLocale)); } catch (MissingResourceException e) { // no resourceBundle for skin portalTabSkin.setName(widgetView.getKey()); } portalTabSkin.setKey(widgetView.getKey()); portalContext.getPortalTabSkins().add(portalTabSkin); } } // Widget types Collection<ExtendedNodeType> widgetTypes = getPortalWidgetNodeTypes(portalNode); Collection<ExtendedNodeType> modelWidgetTypes = !isModel && !modelDeleted ? getPortalWidgetNodeTypes(modelNode) : null; for (ExtendedNodeType widgetType : widgetTypes) { if (!isModel && !modelDeleted) { if (modelWidgetTypes.contains(widgetType)) { PortalWidgetType portalWidgetType = buildPortalWidgetType(widgetType, site, mainResourceLocale, false); portalContext.getPortalWidgetTypes().add(portalWidgetType); modelWidgetTypes.remove(widgetType); } } else { PortalWidgetType portalWidgetType = buildPortalWidgetType(widgetType, site, mainResourceLocale, false); portalContext.getPortalWidgetTypes().add(portalWidgetType); } } if (!isModel && !modelDeleted) { for (ExtendedNodeType modelWidgetType : modelWidgetTypes) { PortalWidgetType portalWidgetType = buildPortalWidgetType(modelWidgetType, site, mainResourceLocale, true); portalContext.getPortalWidgetTypes().add(portalWidgetType); } } } if (updateLastPortalUsed) { DateTime currentDateTime = new DateTime(); String lastViewed = portalNode.getPropertyAsString(PortalConstants.J_LASTVIEWED); boolean firstView = StringUtils.isEmpty(lastViewed); if (firstView || currentDateTime.getDayOfYear() != ISODateTimeFormat .dateOptionalTimeParser().parseDateTime(lastViewed).getDayOfYear()) { portalNode.setProperty(PortalConstants.J_LASTVIEWED, currentDateTime.toCalendar(mainResourceLocale)); portalNode.saveSession(); } } return portalContext; } }); portalContext.setBaseUrl(StringUtils.isNotEmpty(renderContext.getURLGenerator().getContext()) ? renderContext.getURLGenerator().getContext() + renderContext.getURLGenerator().getBaseLive() : renderContext.getURLGenerator().getBaseLive()); return portalContext; }
From source file:ubic.gemma.core.loader.expression.arrayDesign.ArrayDesignSequenceProcessingServiceImpl.java
/** * Copy sequences into the original versions, or create new sequences in the DB, as needed. * * @param force If true, if an existing BioSequence that matches if found in the system, any existing sequence * information in the BioSequence will be overwritten. * @return Items that were found.//from ww w .ja v a 2 s.c o m */ private Map<String, BioSequence> findOrUpdateSequences(Collection<String> accessionsToFetch, Collection<BioSequence> retrievedSequences, Taxon taxon, boolean force) { Map<String, BioSequence> found = new HashMap<>(); for (BioSequence sequence : retrievedSequences) { if (ArrayDesignSequenceProcessingServiceImpl.log.isDebugEnabled()) ArrayDesignSequenceProcessingServiceImpl.log.debug("Processing retrieved sequence: " + sequence); sequence.setTaxon(taxon); sequence = this.createOrUpdateGenbankSequence(sequence, force); String accession = sequence.getSequenceDatabaseEntry().getAccession(); found.put(accession, sequence); accessionsToFetch.remove(accession); } return found; }
From source file:nl.strohalm.cyclos.services.groups.GroupServiceImpl.java
@SuppressWarnings("unchecked") private void removeFromInverseCollections(final Group group) { // Payment filters final Collection<PaymentFilter> paymentFilters = group.getPaymentFilters(); for (final PaymentFilter paymentFilter : paymentFilters) { final Collection<Group> groups = (Collection<Group>) paymentFilter.getGroups(); groups.remove(group); paymentFilterDao.update(paymentFilter); }//from w w w . jav a 2 s . c om // Record types final Collection<MemberRecordType> recordTypes = group.getMemberRecordTypes(); for (final MemberRecordType recordType : recordTypes) { recordType.getGroups().remove(group); memberRecordTypeDao.update(recordType); } if (group instanceof AdminGroup) { final AdminGroup adminGroup = (AdminGroup) group; // Connected admins viewed by final Collection<AdminGroup> connectedAdminsViewedBy = adminGroup.getConnectedAdminsViewedBy(); for (final AdminGroup viewerAdminGroup : connectedAdminsViewedBy) { viewerAdminGroup.getViewConnectedAdminsOf().remove(adminGroup); groupDao.update(viewerAdminGroup); } // Admin custom fields final Collection<AdminCustomField> adminCustomFields = adminGroup.getAdminCustomFields(); for (final AdminCustomField adminCustomField : adminCustomFields) { adminCustomField.getGroups().remove(adminGroup); customFieldDao.update(adminCustomField); } } if (group instanceof MemberGroup) { final MemberGroup memberGroup = (MemberGroup) group; // Account fees final Collection<AccountFee> accountFees = memberGroup.getAccountFees(); for (final AccountFee accountFee : accountFees) { final Collection<MemberGroup> groups = accountFee.getGroups(); groups.remove(memberGroup); accountFeeDao.update(accountFee); } // Managed by groups final Collection<AdminGroup> managedByGroups = memberGroup.getManagedByGroups(); for (final AdminGroup adminGroup : managedByGroups) { adminGroup.getManagesGroups().remove(memberGroup); groupDao.update(adminGroup); } // Member custom fields and general remark custom fields) final Collection<CustomField> customFields = memberGroup.getCustomFields(); for (final CustomField customField : customFields) { // Get the groups using reflection final Collection<MemberGroup> groups = PropertyHelper.get(customField, "groups"); groups.remove(memberGroup); customFieldDao.update(customField); } // From transaction fees final Collection<TransactionFee> fromTransactionFees = memberGroup.getFromTransactionFees(); for (final TransactionFee transactionFee : fromTransactionFees) { transactionFee.getFromGroups().remove(memberGroup); transactionFeeDao.update(transactionFee); } // To transaction fees final Collection<TransactionFee> toTransactionFees = memberGroup.getToTransactionFees(); for (final TransactionFee transactionFee : toTransactionFees) { transactionFee.getToGroups().remove(memberGroup); transactionFeeDao.update(transactionFee); } } }
From source file:eu.medsea.mimeutil.MimeUtil2.java
/** * Get all of the matching mime types for this file object. * The method delegates down to each of the registered MimeHandler(s) and returns a * normalised list of all matching mime types. If no matching mime types are found the returned * Collection will contain the unknownMimeType passed in. * @param file the File object to detect. * @param unknownMimeType.//w w w . j a va 2s . c o m * @return the Collection of matching mime types. If the collection would be empty i.e. no matches then this will * contain the passed in parameter unknownMimeType * @throws MimeException if there are problems such as reading files generated when the MimeHandler(s) * executed. */ public final Collection getMimeTypes(final File file, final MimeType unknownMimeType) throws MimeException { Collection mimeTypes = new MimeTypeHashSet(); if (file == null) { log.error("File reference cannot be null."); } else { if (log.isDebugEnabled()) { log.debug("Getting MIME types for file [" + file.getAbsolutePath() + "]."); } if (file.isDirectory()) { mimeTypes.add(MimeUtil2.DIRECTORY_MIME_TYPE); } else { // Defer this call to the file name and stream methods mimeTypes.addAll(mimeDetectorRegistry.getMimeTypes(file)); // We don't want the unknownMimeType added to the collection by MimeDetector(s) mimeTypes.remove(unknownMimeType); } } // If the collection is empty we want to add the unknownMimetype if (mimeTypes.isEmpty()) { mimeTypes.add(unknownMimeType); } if (log.isDebugEnabled()) { log.debug("Retrieved MIME types [" + mimeTypes.toString() + "]"); } return mimeTypes; }
From source file:eu.medsea.mimeutil.MimeUtil2.java
/** * Get all of the matching mime types for this file name . * The method delegates down to each of the registered MimeHandler(s) and returns a * normalised list of all matching mime types. If no matching mime types are found the returned * Collection will contain the unknownMimeType passed in. * @param fileName the name of a file to detect. * @param unknownMimeType./*from w ww . j ava 2 s . c om*/ * @return the Collection of matching mime types. If the collection would be empty i.e. no matches then this will * contain the passed in parameter unknownMimeType * @throws MimeException if there are problems such as reading files generated when the MimeHandler(s) * executed. */ public final Collection getMimeTypes(final String fileName, final MimeType unknownMimeType) throws MimeException { Collection mimeTypes = new MimeTypeHashSet(); if (fileName == null) { log.error("fileName cannot be null."); } else { if (log.isDebugEnabled()) { log.debug("Getting MIME types for file name [" + fileName + "]."); } // Test if this is a directory File file = new File(fileName); if (file.isDirectory()) { mimeTypes.add(MimeUtil2.DIRECTORY_MIME_TYPE); } else { mimeTypes.addAll(mimeDetectorRegistry.getMimeTypes(fileName)); // We don't want the unknownMimeType added to the collection by MimeDetector(s) mimeTypes.remove(unknownMimeType); } } // If the collection is empty we want to add the unknownMimetype if (mimeTypes.isEmpty()) { mimeTypes.add(unknownMimeType); } if (log.isDebugEnabled()) { log.debug("Retrieved MIME types [" + mimeTypes.toString() + "]"); } return mimeTypes; }