List of usage examples for java.util Collection remove
boolean remove(Object o);
From source file:com.silverpeas.gallery.dao.MediaDAO.java
/** * Adding all data of streamings.//www . ja v a2 s .c om * @param con * @param media * @param streamings * @throws SQLException */ private static void decorateStreamings(final Connection con, List<Media> media, Map<String, Streaming> streamings) throws SQLException { if (!streamings.isEmpty()) { Collection<Collection<String>> idGroups = CollectionUtil .split(new ArrayList<String>(streamings.keySet())); StringBuilder queryBase = new StringBuilder( "select S.mediaId, S.homepageUrl, S.provider from SC_Gallery_Streaming S where S" + ".mediaId in "); for (Collection<String> mediaIds : idGroups) { PreparedStatement prepStmt = null; ResultSet rs = null; try { prepStmt = con.prepareStatement(DBUtil.appendListOfParameters(queryBase, mediaIds).toString()); DBUtil.setParameters(prepStmt, mediaIds); rs = prepStmt.executeQuery(); while (rs.next()) { String mediaId = rs.getString(1); mediaIds.remove(mediaId); Streaming currentStreaming = streamings.get(mediaId); currentStreaming.setHomepageUrl(rs.getString(2)); currentStreaming.setProvider(StreamingProvider.from(rs.getString(3))); } } finally { DBUtil.close(rs, prepStmt); } // Not found for (String mediaIdNotFound : mediaIds) { Streaming currentStreaming = streamings.remove(mediaIdNotFound); media.remove(currentStreaming); SilverTrace.warn(GalleryComponentSettings.COMPONENT_NAME, "MediaDAO.decorateStreamings()", "root.MSG_GEN_PARAM_VALUE", "streaming not found (removed from result): " + mediaIdNotFound); } } } }
From source file:com.silverpeas.gallery.dao.MediaDAO.java
/** * Adding all data of videos./*w ww . j av a2 s .co m*/ * @param con * @param media * @param videos * @throws SQLException */ private static void decorateVideos(final Connection con, List<Media> media, Map<String, Video> videos) throws SQLException { if (!videos.isEmpty()) { Collection<Collection<String>> idGroups = CollectionUtil.split(new ArrayList<String>(videos.keySet())); StringBuilder queryBase = new StringBuilder(SELECT_INTERNAL_MEDIA_PREFIX) .append("V.resolutionW, V.resolutionH, V.bitrate, V.duration from SC_Gallery_Internal I join " + "SC_Gallery_Video V on I.mediaId = V.mediaId where I.mediaId in "); for (Collection<String> mediaIds : idGroups) { PreparedStatement prepStmt = null; ResultSet rs = null; try { prepStmt = con.prepareStatement(DBUtil.appendListOfParameters(queryBase, mediaIds).toString()); DBUtil.setParameters(prepStmt, mediaIds); rs = prepStmt.executeQuery(); while (rs.next()) { String mediaId = rs.getString(1); mediaIds.remove(mediaId); Video currentVideo = videos.get(mediaId); decorateInternalMedia(rs, currentVideo); currentVideo.setDefinition(Definition.of(rs.getInt(8), rs.getInt(9))); currentVideo.setBitrate(rs.getLong(10)); currentVideo.setDuration(rs.getLong(11)); } } finally { DBUtil.close(rs, prepStmt); } // Not found for (String mediaIdNotFound : mediaIds) { Video currentVideo = videos.remove(mediaIdNotFound); media.remove(currentVideo); SilverTrace.warn(GalleryComponentSettings.COMPONENT_NAME, "MediaDAO.decorateVideos()", "root.MSG_GEN_PARAM_VALUE", "video not found (removed from result): " + mediaIdNotFound); } } } }
From source file:org.jactr.core.module.declarative.search.map.DefaultValueMap.java
public void remove(V value, I indexable) { if (value == null) throw new NullPointerException("null values are not permitted as keys"); ReentrantReadWriteLock lock = getLock(); try {//from w ww . java 2 s. co m lock.writeLock().lock(); Collection<I> indexables = getCoreMap().get(value); if (indexables != null) { indexables.remove(indexable); if (indexables.size() == 0) getCoreMap().remove(value); } } finally { lock.writeLock().unlock(); } }
From source file:uk.co.modularaudio.util.audio.mad.graph.GraphLinkMap.java
public void deleteLink(final MadLink link) throws RecordNotFoundException { final MadChannelInstance cci = link.getConsumerChannelInstance(); final MadInstance<?, ?> cmi = cci.instance; final MadChannelInstance pci = link.getProducerChannelInstance(); final MadInstance<?, ?> pmi = pci.instance; if (RUNTIME_CHECKING && !instanceLinks.contains(link) || !consumerInstanceLinks.containsKey(cmi) || !producerInstanceLinks.containsKey(pmi)) { throw new RecordNotFoundException("Removal of unknown link or unknown mads"); }//from www . j av a 2 s . c o m assert (instanceLinks.contains(link)); final Collection<MadLink> consumerLinks = consumerInstanceLinks.get(cmi); if (consumerLinks.contains(link)) { consumerLinks.remove(link); } else { if (log.isErrorEnabled()) { log.error("Missing consumer link entry for " + cmi.getInstanceName() + " " + cci.definition.name); } } final Collection<MadLink> producerLinks = producerInstanceLinks.get(pmi); if (producerLinks.contains(link)) { producerLinks.remove(link); } else { if (log.isErrorEnabled()) { log.error("Missing producer link entry for " + pmi.getInstanceName() + " " + pci.definition.name); } } instanceLinks.remove(link); }
From source file:com.smash.revolance.ui.comparator.element.ElementMatchMaker.java
@Override public Collection<ElementMatch> findMatch(Collection<ElementBean> elements, ElementBean element, ElementSearchMethod... methods) throws NoMatchFound, IllegalArgumentException { if (elements == null) { throw new IllegalArgumentException("Null content cannot be parsed"); }//from www. j a v a 2 s. c om if (element == null) { throw new IllegalArgumentException("Null element cannot be matched."); } if (elements.isEmpty()) { throw new NoMatchFound("Unable to find a single match. Empty element collection passed in."); } Collection<ElementBean> localElements = new ArrayList<ElementBean>(); localElements.addAll(elements); if (localElements.contains(element)) { localElements.remove(element); } List<ElementMatch> matches = getElementMatches(element, localElements, methods); if (matches.isEmpty()) { throw new NoMatchFound("Unable to find a single match."); } else { return matches; } }
From source file:org.nuxeo.ecm.core.versioning.DefaultVersionRemovalPolicy.java
@Override public void removeVersions(Session session, Document doc, CoreSession coreSession) throws ClientException { try {/* w ww. j av a2s . c o m*/ Collection<Document> proxies = session.getProxies(doc, null); if (doc.isProxy()) { // if doc is itself a proxy it should not be considered // in the list of remaining proxies proxies.remove(doc); if (proxies.isEmpty()) { // removal of last proxy Document source = doc.getSourceDocument(); if (source.isVersion()) { // get live doc from version try { source = source.getSourceDocument(); } catch (NoSuchDocumentException e) { // live already removed source = null; } } // else was a live proxy // if a live doc remains, still don't remove versions if (source != null) { return; } } } if (proxies.isEmpty()) { List<String> versionsIds = doc.getVersionsIds(); if (log.isDebugEnabled()) { log.debug(String.format("Removing %s versions for: %s", versionsIds.size(), doc.getUUID())); } if (versionsIds.size() > 0) { DocumentModel docModel = coreSession.getDocument(new IdRef(doc.getUUID())); EventContext evtctx = new EventContextImpl(coreSession, coreSession.getPrincipal(), new ShallowDocumentModel(docModel), versionsIds); Event evt = evtctx.newEvent(ORPHAN_VERSION_REMOVE); Framework.getLocalService(EventService.class).fireEvent(evt); } } } catch (DocumentException e) { throw new ClientException(e); } }
From source file:org.openflexo.antar.binding.TypeUtils.java
public static Class<?> getMostSpecializedClass(Collection<Class<?>> someClasses) { if (someClasses.size() == 0) { return null; }//from ww w. j a v a2 s. c om if (someClasses.size() == 1) { return someClasses.iterator().next(); } Class<?>[] array = someClasses.toArray(new Class[someClasses.size()]); for (int i = 0; i < someClasses.size(); i++) { for (int j = i + 1; j < someClasses.size(); j++) { Class<?> c1 = array[i]; Class<?> c2 = array[j]; if (c1.isAssignableFrom(c2)) { someClasses.remove(c1); return getMostSpecializedClass(someClasses); } if (c2.isAssignableFrom(c1)) { someClasses.remove(c2); return getMostSpecializedClass(someClasses); } } } // No parent were found, take first item logger.warning("Undefined specializing criteria between " + someClasses); return someClasses.iterator().next(); }
From source file:de.tudarmstadt.ukp.dkpro.wsd.graphconnectivity.algorithm.GraphConnectivityWSD.java
@Override public Map<Pair<String, POS>, Map<String, Double>> getDisambiguation(Collection<Pair<String, POS>> sods) throws SenseInventoryException { Graph<String, UnorderedPair<String>> siGraph = inventory.getUndirectedGraph(); Graph<String, UnorderedPair<String>> dGraph = new UndirectedSparseGraph<String, UnorderedPair<String>>(); int sodCount = 0; if (graphVisualizer != null) { graphVisualizer.initializeColorMap(sods.size()); graphVisualizer.setVertexToolTipTransformer(new VertexToolTipTransformer()); }//from w w w. j a v a2s . co m // Find the senses for the lemmas and add them to a graph for (Pair<String, POS> wsdItem : sods) { List<String> senses = inventory.getSenses(wsdItem.getFirst(), wsdItem.getSecond()); if (senses.isEmpty()) { logger.warn("unknown subject of disambiguation " + wsdItem); // throw new SenseInventoryException( // "unknown subject of disambiguation " + wsdItem); } for (String sense : senses) { if (graphVisualizer != null) { graphVisualizer.setColor(sense, sodCount); } dGraph.addVertex(sense); } sodCount++; } logger.debug(dGraph.toString()); if (graphVisualizer != null) { graphVisualizer.initialize(dGraph); } // For each synset v in s, perform a depth-first search on siGraph. // Every time we encounter a synset v' from s along a path of length // l, we add to dGraph all intermediate nodes and edges on the path // from v to v'. // Run DFS on each synset in s Collection<String> s = new HashSet<String>(dGraph.getVertices()); for (String v : s) { logger.debug("Beginning DFS from " + v); Collection<String> t = new HashSet<String>(s); t.remove(v); Stack<String> synsetPath = new Stack<String>(); synsetPath.push(v); dfs(v, t, siGraph, dGraph, synsetPath, new Stack<UnorderedPair<String>>(), searchDepth); } logger.debug(dGraph.toString()); // Find the best synsets for each word in the sentence final Map<Pair<String, POS>, Map<String, Double>> solutions = getDisambiguation(sods, dGraph); // Repaint the frame to show the disambiguated senses if (graphVisualizer != null) { graphVisualizer.refresh(); } return solutions; }
From source file:psidev.psi.mi.tab.expansion.SpokeExpansion.java
/** * Interaction having more than 2 participants get split following the spoke model expansion. That is, we build * pairs of participant following bait-prey and enzyme-target associations. * * @param interaction a non null interaction. * @return a non null collection of interaction, in case the expansion is not possible, we may return an empty * collection.//from w ww .ja v a 2 s. c o m */ public Collection<Interaction> expand(Interaction interaction) { Collection<Interaction> interactions = new ArrayList<Interaction>(); if (interaction.getParticipants().isEmpty()) { return interactions; } InteractionCategory category = findInteractionCategory(interaction); if (category == null) { return interactions; } if (isBinary(interaction) || category.equals(InteractionCategory.self_intra_molecular)) { log.debug("interaction " + interaction.getId() + "/" + interaction.getImexId() + " was binary or intra molecular, no further processing involved."); interactions.add(interaction); } if (category.equals(InteractionCategory.self_inter_molecular)) { //TODO when we return the list of binary interactions in this point we need duplicate the participant and //put zero to one of the stoichiometry log.debug("interaction " + interaction.getId() + "/" + interaction.getImexId() + " was inter molecular, reset stoichiometry of one of interactors"); interactions.add(interaction); } else { // split interaction Collection<Participant> participants = interaction.getParticipants(); log.debug(participants.size() + " participant(s) found."); Participant bait = searchBaitParticipant(participants); if (bait != null) { Collection<Participant> preys = new ArrayList<Participant>(participants.size() - 1); preys.addAll(participants); preys.remove(bait); for (Participant prey : preys) { if (log.isDebugEnabled()) { String baitStr = displayParticipant(bait); String preyStr = displayParticipant(prey); log.debug("Build new binary interaction [" + baitStr + "," + preyStr + "]"); } Interaction i = buildInteraction(interaction, bait, prey); interactions.add(i); } } else { Collection<Interaction> noBaitExpandedInteractions = processNoBaitExpansion(interaction); interactions.addAll(noBaitExpandedInteractions); } log.debug("After expansion: " + interactions.size() + " binary interaction(s) were generated."); } return interactions; }
From source file:com.fstx.stdlib.authen.users.old.GroupMembershipDAOTest.java
public void testGetMemberAndNonMemberList() throws Exception { Collection listUsers = UserDAO.factory.build().find(selectAll); GroupMembershipDAO dao = GroupMembershipDAO.factory.build(); List listMembers = dao.find(GroupMembershipDAO.SELECT_BY_GROUP_USER_MEMBERS, "" + group.getId()); log.info("Members: " + listMembers); Collection nonMembers = UserDAO.factory.build().find(selectAll); Iterator i = listMembers.listIterator(); while (i.hasNext()) { Object o = i.next();// www . j a va 2 s. c o m nonMembers.remove(o); } log.info("nonMemb: " + nonMembers); assertTrue(nonMembers.size() == listUsers.size() - listMembers.size()); }