List of usage examples for com.google.common.collect Iterators removeAll
public static boolean removeAll(Iterator<?> removeFrom, Collection<?> elementsToRemove)
From source file:ch.njol.skript.effects.EffHidePlayerFromServerList.java
@Override protected void execute(Event e) { Iterator<Player> it = ((ServerListPingEvent) e).iterator(); Iterators.removeAll(it, Arrays.asList(players.getArray(e))); }
From source file:org.eclipse.sirius.business.internal.session.danalysis.SessionResourcesTracker.java
/** * Check the resources in the resourceSet. Detect new resources and add them * to the session as new semantic resources or referenced session resources.<BR> * <BR>/* www . ja va2s .c o m*/ * New semantic resources are : * <UL> * <LI>Resources that are not in the <code>knownResources</code> list</LI> * <LI>Resources that are not in the semantic resources of this session</LI> * <LI>Resources that are not in the referenced representations files * resources of this session</LI> * <LI>Resources that are not the Sirius environment resource</LI> * </UL> * <BR> * New referenced session resources are : * <UL> * <LI>Resources that are not in the <code>knownResources</code> list</LI> * <LI>Resources that are in the referenced representations files resources * of this session (the list is computed from the allAnalyses() result)</LI> * </UL> * * @param knownResources * List of resources that is already loaded before the resolveAll * of the representations file load. */ static void manageAutomaticallyLoadedResources(final DAnalysisSessionImpl session, List<Resource> knownResources) { TransactionalEditingDomain domain = session.getTransactionalEditingDomain(); List<Resource> resourcesAfterLoadOfSession = Lists.newArrayList(domain.getResourceSet().getResources()); // Remove the known resources Iterators.removeAll(resourcesAfterLoadOfSession.iterator(), knownResources); if (resourcesAfterLoadOfSession.isEmpty()) { return; } Set<Resource> referencedSessionResources = session.getReferencedSessionResources(); Collection<Resource> newReferencedSessionResources = Lists.newArrayList( Iterables.filter(resourcesAfterLoadOfSession, Predicates.in(referencedSessionResources))); if (!newReferencedSessionResources.isEmpty()) { for (Resource newReferencedSessionResource : newReferencedSessionResources) { session.registerResourceInCrossReferencer(newReferencedSessionResource); for (DAnalysis refAnalysis : Iterables.filter(newReferencedSessionResource.getContents(), DAnalysis.class)) { session.addAdaptersOnAnalysis(refAnalysis); } } } // Remove the known semantic resources Iterators.removeAll(resourcesAfterLoadOfSession.iterator(), session.getSemanticResources()); // Remove the known referenced representations file resources Iterators.removeAll(resourcesAfterLoadOfSession.iterator(), referencedSessionResources); final Iterable<Resource> newSemanticResourcesIterator = Iterables.filter(resourcesAfterLoadOfSession, new Predicate<Resource>() { public boolean apply(Resource resource) { // Remove empty resource and the Sirius environment return !resource.getContents().isEmpty() && !(new URIQuery(resource.getURI()).isEnvironmentURI()); } }); if (!Iterables.isEmpty(newSemanticResourcesIterator)) { domain.getCommandStack().execute(new RecordingCommand(domain, Messages.SessionResourcesTracker_addReferencedSemanticResourcesMsg) { @Override protected void doExecute() { for (Resource resource : newSemanticResourcesIterator) { session.addSemanticResource(resource.getURI(), new NullProgressMonitor()); } } }); } }
From source file:com.eucalyptus.network.NetworkGroupManager.java
public RevokeSecurityGroupIngressResponseType revoke(final RevokeSecurityGroupIngressType request) throws EucalyptusCloudException { final Context ctx = Contexts.lookup(); final RevokeSecurityGroupIngressResponseType reply = request.getReply(); reply.markFailed();/*w w w. jav a2 s.com*/ final EntityTransaction db = Entities.get(NetworkGroup.class); try { final List<IpPermissionType> ipPermissions = handleOldAndNewIpPermissions(request.getCidrIp(), request.getIpProtocol(), request.getFromPort(), request.getToPort(), request.getSourceSecurityGroupName(), request.getSourceSecurityGroupOwnerId(), request.getIpPermissions()); final NetworkGroup ruleGroup = lookupGroup(request.getGroupId(), request.getGroupName()); if (RestrictedTypes.filterPrivileged().apply(ruleGroup)) { NetworkGroups.resolvePermissions(ipPermissions, ctx.getUser().getAccountNumber(), true); try { Iterators.removeAll( // iterator used to work around broken equals/hashCode in NetworkRule ruleGroup.getNetworkRules().iterator(), NetworkGroups.ipPermissionsAsNetworkRules(ipPermissions)); } catch (IllegalArgumentException e) { throw new ClientComputeException("InvalidPermission.Malformed", e.getMessage()); } } else { throw new EucalyptusCloudException("Not authorized to revoke network group " + request.getGroupName() + " for " + ctx.getUser()); } reply.set_return(true); db.commit(); NetworkGroups.flushRules(); } catch (EucalyptusCloudException ex) { throw ex; } catch (Exception ex) { Logs.exhaust().error(ex, ex); throw new EucalyptusCloudException("RevokeSecurityGroupIngress failed because: " + ex.getMessage(), ex); } finally { if (db.isActive()) db.rollback(); } return reply; }
From source file:org.eclipse.sirius.ecore.extender.tool.api.ModelUtils.java
/** * Browse the whole model resolving references (and do it recursively in new * resources if recursive parameter is true). * /*from w w w .j a v a 2 s .c o m*/ * @param res * any model. * @param recursive * true to resolveAll resources loading during the resolveAll of * the <code>res<code>, false otherwise. */ public static void resolveAll(final Resource res, boolean recursive) { final IPermissionAuthority authority = PermissionAuthorityRegistry.getDefault().getPermissionAuthority(res); if (authority != null) { authority.setListening(false); } List<Resource> cachedIDsResources = Collections.emptyList(); if (res != null && res.getResourceSet() != null) { cachedIDsResources = ModelUtils.cachedEObjectIDs(res.getResourceSet()); } List<Resource> resourcesBeforeResolveAll = Lists.newArrayList(res.getResourceSet().getResources()); EcoreUtil.resolveAll(res); if (recursive) { List<Resource> resourcesAfterResolveAll = Lists.newArrayList(res.getResourceSet().getResources()); // Remove the known resources Iterators.removeAll(resourcesAfterResolveAll.iterator(), resourcesBeforeResolveAll); for (Resource resource : resourcesAfterResolveAll) { resolveAll(resource, recursive); } } ModelUtils.uncachedEObejctIDs(cachedIDsResources); if (authority != null) { authority.setListening(true); } }