List of usage examples for java.util Set remove
boolean remove(Object o);
From source file:com.parse.ParseRelationOperation.java
private void removeParseObjectFromSet(ParseObject obj, Set<ParseObject> set) { if (Parse.getLocalDatastore() != null || obj.getObjectId() == null) { // There's no way there could be duplicate instances. set.remove(obj); return;// w w w. j a v a 2s . c o m } // We have to do this the hard way. for (ParseObject existingObject : set) { if (obj.getObjectId().equals(existingObject.getObjectId())) { set.remove(existingObject); } } }
From source file:com.xpn.xwiki.plugin.skinx.AbstractDocumentSkinExtensionPlugin.java
/** * {@inheritDoc}//from w ww . j a va 2 s . c o m * <p> * Make sure to keep the {@link #alwaysUsedExtensions} map consistent when the database changes. * * @see org.xwiki.observation.EventListener#onEvent(org.xwiki.observation.event.Event, java.lang.Object, * java.lang.Object) */ @Override public void onEvent(Event event, Object source, Object data) { XObjectPropertyEvent propertyEvent = (XObjectPropertyEvent) event; XWikiDocument document = (XWikiDocument) source; XWikiContext context = (XWikiContext) data; boolean remove; if (propertyEvent instanceof XObjectPropertyDeletedEvent) { remove = true; } else { remove = !StringUtils.equals((String) document .getXObjectProperty((ObjectPropertyReference) propertyEvent.getReference()).getValue(), "always"); } Set<String> extensions = getAlwaysUsedExtensions(context); if (remove) { extensions.remove(document.getFullName()); } else { extensions.add(document.getFullName()); } }
From source file:edu.asu.ca.kaushik.algorithms.derandomized.pe.structures.ExtInteractionGraph.java
public int deleteInteractions(Integer[] newRow) { int coverage = 0; this.resetDeletionEstimates(); Iterator<ColGroup> colGrIt = this.iSet.keySet().iterator(); while (colGrIt.hasNext()) { ColGroup colGr = colGrIt.next(); int[] indices = colGr.getCols(); int[] syms = new int[this.t]; for (int i = 0; i < this.t; i++) { syms[i] = newRow[indices[i]].intValue(); }//from w w w . ja va 2s . c o m SymTuple tuple = new SymTuple(syms); Set<IFitness> iFitnessSet = this.iSet.get(colGr); if (iFitnessSet.contains(tuple)) { coverage += 1; this.updateDeletionEstimate(colGr, tuple); iFitnessSet.remove(tuple); if (iFitnessSet.isEmpty()) { colGrIt.remove(); } } } this.bInteraction = this.findBestInteraction(coverage); return coverage; }
From source file:fr.mby.portal.coreimpl.context.PropertiesAppConfigFactoryTest.java
@Test public void testProcessAclRolesOnOkConf() throws Exception { final BasicAppConfig appConfig = this.processAclRoles(this.okConfig); this.assertSpecialRolesExistence(appConfig); final Set<IRole> declaredRoles = appConfig.getDeclaredRoles(); Assert.assertNotNull("Declared permissions should not be null !", declaredRoles); Assert.assertEquals("Declared permissions should be 4 !", 4, declaredRoles.size()); // Conf ok//from www. j ava2s .c o m final IRole guest = appConfig.getSpecialRole(SpecialRole.GUEST); final IRole logged = appConfig.getSpecialRole(SpecialRole.LOGGED); final IRole admin = appConfig.getSpecialRole(SpecialRole.ADMIN); final Set<IPermission> loggedPerms = logged.getPermissions(); final Set<IPermission> adminPerms = admin.getPermissions(); // logged sub-role of admin Assert.assertEquals("Special logged role should be sub-role of admin !", logged, admin.getSubRoles().iterator().next()); // logged has can_render Assert.assertEquals("Special logged role should have 1 perm : CAN_RENDER !", 1, loggedPerms.size()); Assert.assertEquals("Special logged role should have 1 perm : CAN_RENDER !", this.permissionsMap.get("CAN_RENDER"), loggedPerms.iterator().next()); Assert.assertTrue("Special logged role should have 1 perm : CAN_RENDER !", logged.isGranted(this.permissionsMap.get("CAN_RENDER"))); // admin has can_edit and is granted of can_render by sub-roling Assert.assertEquals("Special admin role should have 1 perm : CAN_EDIT !", 1, adminPerms.size()); Assert.assertEquals("Special admin role should have 1 perm : CAN_EDIT !", this.permissionsMap.get("CAN_EDIT"), adminPerms.iterator().next()); Assert.assertTrue("Special admin role should be granted 2 perms : CAN_RENDER & CAN_EDIT !", admin.isGranted(this.permissionsMap.get("CAN_RENDER"))); Assert.assertTrue("Special admin role should be granted 2 perms : CAN_RENDER & CAN_EDIT !", admin.isGranted(this.permissionsMap.get("CAN_EDIT"))); // lambdaRole have lambaPerm and logged has sub-role final Set<IRole> roles = new HashSet<IRole>(declaredRoles); roles.remove(guest); roles.remove(logged); roles.remove(admin); final IRole lambdaRole = roles.iterator().next(); Assert.assertEquals("Lanmda role should have 1 perm : lambdaPerm !", 1, lambdaRole.getPermissions().size()); Assert.assertEquals("Lanmda role should have 1 perm : lambdaPerm !", this.permissionsMap.get("lambdaPerm"), lambdaRole.getPermissions().iterator().next()); Assert.assertTrue("Lambda role should be granted 2 perms : CAN_RENDER & lambdaPerm !", lambdaRole.isGranted(this.permissionsMap.get("CAN_RENDER"))); Assert.assertTrue("Lambda role should be granted 2 perms : CAN_RENDER & lambdaPerm !", lambdaRole.isGranted(this.permissionsMap.get("lambdaPerm"))); }
From source file:de.phoenix.submission.SubmissionCompilerAndTest.java
@Override public PhoenixSubmissionResult controlSubmission(TaskSubmission submission) { SubmissionTask task = new SubmissionTask(); File dir = PhoenixApplication.submissionPipelineDir; List<String> commands = getCommands(); // Check, if all necessary classes are submitted Set<String> classes = new HashSet<String>(); for (Text text : submission.getTask().getTexts()) { classes.add(text.getTitle());// w w w .j av a 2 s. c om } for (Text clazz : submission.getTexts()) { task.addClass(clazz.convert()); classes.remove(clazz.getTitle()); } // Some to implement classes are missing -> error if (!classes.isEmpty()) { return new PhoenixSubmissionResult(SubmissionStatus.MISSING_FILES, "Missing classes to implement/submit. Maybe you wrote the name of the class wrong? Missing Classes:\r\n" + classes.toString()); } if (submission.getTask().isAutomaticTest()) { for (TaskTest test : submission.getTask().getTaskTests()) { addTest(task, test); } } // TODO: Add libraries ProcessBuilder builder = new ProcessBuilder(commands); builder.directory(dir); File errorLog = new File(dir, "error.log"); errorLog.delete(); builder.redirectError(errorLog); try { Process process = builder.start(); JSON_MAPPER.writeValue(process.getOutputStream(), task); process.getOutputStream().close(); PhoenixSubmissionResult result = JSON_MAPPER.readValue(process.getInputStream(), PhoenixSubmissionResult.class); return result; } catch (Exception e) { DebugLog.log(e); } return new PhoenixSubmissionResult(SubmissionStatus.OK, "Fine"); }
From source file:com.comcast.cdn.traffic_control.traffic_router.core.router.DnsRoutePerformanceTest.java
@Before public void before() throws Exception { CacheRegister cacheRegister = new CacheRegister(); JSONTokener healthTokener = new JSONTokener(new FileReader("src/test/db/health.json")); JSONObject healthObject = new JSONObject(healthTokener); JSONTokener jsonTokener = new JSONTokener(new FileReader("src/test/db/cr-config.json")); JSONObject crConfigJson = new JSONObject(jsonTokener); JSONObject locationsJo = crConfigJson.getJSONObject("edgeLocations"); final Set<CacheLocation> locations = new HashSet<CacheLocation>(locationsJo.length()); for (final String loc : JSONObject.getNames(locationsJo)) { final JSONObject jo = locationsJo.getJSONObject(loc); locations.add(new CacheLocation(loc, jo.optString("zoneId"), new Geolocation(jo.getDouble("latitude"), jo.getDouble("longitude")))); }//ww w . java 2 s.c om names = new DnsNameGenerator().getNames(crConfigJson.getJSONObject("deliveryServices"), crConfigJson.getJSONObject("config")); cacheRegister.setConfig(crConfigJson); CacheRegisterBuilder.parseDeliveryServiceConfig(crConfigJson.getJSONObject("deliveryServices"), cacheRegister); cacheRegister.setConfiguredLocations(locations); CacheRegisterBuilder.parseCacheConfig(crConfigJson.getJSONObject("contentServers"), cacheRegister); NetworkUpdater networkUpdater = new NetworkUpdater(); networkUpdater.setDatabasesDirectory(Paths.get("src/test/db")); networkUpdater.setDatabaseName("czmap.json"); networkUpdater.setExecutorService(Executors.newSingleThreadScheduledExecutor()); networkUpdater.setTrafficRouterManager(mock(TrafficRouterManager.class)); JSONObject configJson = crConfigJson.getJSONObject("config"); networkUpdater.setDataBaseURL(configJson.getString("coveragezone.polling.url"), configJson.getLong("coveragezone.polling.interval")); File coverageZoneFile = new File("src/test/db/czmap.json"); while (!coverageZoneFile.exists()) { Thread.sleep(500); } NetworkNode.generateTree(coverageZoneFile); ZoneManager zoneManager = mock(ZoneManager.class); MD5HashFunctionPoolableObjectFactory md5factory = new MD5HashFunctionPoolableObjectFactory(); GenericObjectPool pool = new GenericObjectPool(md5factory); whenNew(ZoneManager.class) .withArguments(any(TrafficRouter.class), any(StatTracker.class), any(TrafficOpsUtils.class)) .thenReturn(zoneManager); trafficRouter = new TrafficRouter(cacheRegister, mock(GeolocationService.class), mock(GeolocationService.class), pool, mock(StatTracker.class), mock(TrafficOpsUtils.class), mock(FederationRegistry.class)); trafficRouter.setApplicationContext(mock(ApplicationContext.class)); trafficRouter = spy(trafficRouter); doCallRealMethod().when(trafficRouter).getCoverageZoneCache(anyString(), any(DeliveryService.class)); doCallRealMethod().when(trafficRouter).selectCache(any(Request.class), any(DeliveryService.class), any(Track.class)); doCallRealMethod().when(trafficRouter, "selectCache", any(CacheLocation.class), any(DeliveryService.class)); doCallRealMethod().when(trafficRouter, "getSupportingCaches", any(List.class), any(DeliveryService.class)); doCallRealMethod().when(trafficRouter).setState(any(JSONObject.class)); doCallRealMethod().when(trafficRouter).selectDeliveryService(any(Request.class), anyBoolean()); doReturn(new Geolocation(39.739167, -104.984722)).when(trafficRouter).getLocation(anyString()); trafficRouter.setState(healthObject); JSONObject coverageZoneMap = new JSONObject(new JSONTokener(new FileReader("src/test/db/czmap.json"))); JSONObject coverageZones = coverageZoneMap.getJSONObject("coverageZones"); Iterator iterator = coverageZones.keys(); Map<String, Integer> seen = new HashMap<String, Integer>(); while (iterator.hasNext()) { String coverageZoneName = (String) iterator.next(); JSONObject coverageZoneJson = coverageZones.getJSONObject(coverageZoneName); JSONArray networks = coverageZoneJson.getJSONArray("network"); Set<String> hosts = hostMap.get(coverageZoneName); if (hosts == null) { hosts = new HashSet<String>(); } for (int i = 0; i < networks.length(); i++) { String network = networks.getString(i).split("/")[0]; InetAddress ip = InetAddresses.forString(network); ip = InetAddresses.increment(ip); String ipstr = InetAddresses.toAddrString(ip); hosts.add(ipstr); if (seen.containsKey(ipstr)) { seen.put(ipstr, seen.get(ipstr) + 1); } else { seen.put(ipstr, 1); } } final CacheLocation location = cacheRegister.getCacheLocation(coverageZoneName); if (location != null || (location == null && coverageZoneJson.has("coordinates"))) { coverageZoneRouted.add(coverageZoneName); } hostMap.put(coverageZoneName, hosts); } // remove any dups that will cause a GEO result for (String ip : seen.keySet()) { if (seen.get(ip) > 1) { for (String coverageZoneName : hostMap.keySet()) { Set<String> ips = hostMap.get(coverageZoneName); ips.remove(ip); } } } }
From source file:com.cloudera.impala.catalog.AuthorizationPolicy.java
/** * Removes a role. Returns the removed role or null if no role with * this name existed.// ww w . ja va 2s . c o m */ public synchronized Role removeRole(String roleName) { Role removedRole = roleCache_.remove(roleName); if (removedRole == null) return null; // Cleanup grant groups for (String grantGroup : removedRole.getGrantGroups()) { // Remove this role from all of its grant groups. Set<String> roles = groupsToRoles_.get(grantGroup); if (roles != null) roles.remove(roleName.toLowerCase()); } // Cleanup role id. roleIds_.remove(removedRole.getId()); return removedRole; }
From source file:org.gaixie.micrite.security.service.impl.UserServiceImpl.java
public void unBindUsers(int[] userIds, int roleId) { Role role = roleDAO.get(roleId); for (int i = 0; i < userIds.length; i++) { User user = userDAO.get(userIds[i]); Set<Role> roles = user.getRoles(); roles.remove(role); user.setRoles(roles);//from w w w .j a v a 2s . c o m // cache if (userCache != null) { userCache.removeUserFromCache(user.getLoginname()); } } }
From source file:com.cloudera.impala.catalog.AuthorizationPolicy.java
/** * Removes a grant group from the specified role. Returns the updated * Role, if a matching role was found. If the role does not exist a * CatalogException is thrown.//from ww w . jav a 2 s . c om */ public synchronized Role removeGrantGroup(String roleName, String groupName) throws CatalogException { Role role = roleCache_.get(roleName); if (role == null) throw new CatalogException("Role does not exist: " + roleName); role.removeGrantGroup(groupName); Set<String> grantedRoles = groupsToRoles_.get(groupName); if (grantedRoles != null) { grantedRoles.remove(roleName.toLowerCase()); } return role; }
From source file:de.hybris.platform.category.impl.DefaultCategoryService.java
/** * @see #notVisited(CategoryModel, Set)// ww w. j a v a 2s . c o m */ private void markNotVisited(final CategoryModel cat, final Set<CategoryModel> visitedCategories) { visitedCategories.remove(cat); }