List of usage examples for java.util ArrayList removeAll
public boolean removeAll(Collection<?> c)
From source file:com.ubershy.streamsis.project.CuteProject.java
/** * Sets the current SisScene and starts corresponding Actors if Project is running. <br> * Also cleans SisScenes from non-existing Actors. * * @param switchToSisSceneName/* w ww. j a v a 2s .com*/ * the name of SisScene to <i>which</i> we want to <i>switch</i> */ public final void switchSisSceneTo(String switchToSisSceneName) { SisScene switchToSisScene = getSisSceneByName(switchToSisSceneName); if (switchToSisScene == null || switchToSisSceneName.isEmpty()) return; boolean switched = false; if (switchToSisSceneName.equals(getCurrentSisSceneName())) { logger.info("Not switching to the same SisScene"); switched = false; } else { logger.info("Switching SisScene from: '" + getCurrentSisSceneName() + "' to: '" + switchToSisSceneName + "'"); currentSisSceneName.set(switchToSisSceneName); switched = true; } synchronized (currentActors) { if (switched) { // We will clean current SisScene from non-existing Actors // Also here we are filling the array of Actors to run. Working directly with // currentActors is bad idea. ArrayList<Actor> actorsThatNeedToBeRunning = new ArrayList<Actor>(); ArrayList<String> actorsToDeleteFromSisScene = new ArrayList<String>(); for (String actorName : switchToSisScene.getActorNames()) { Actor actor = getActorByName(actorName); if (actor == null) { actorsToDeleteFromSisScene.add(actorName); } else { actorsThatNeedToBeRunning.add(actor); } } for (String actorName : actorsToDeleteFromSisScene) { switchToSisScene.getActorNames().remove(actorName); logger.debug("Deleting from SisScene '" + switchToSisSceneName + "' the non-existing Actor name: '" + actorName + "'"); } // Lets find all Actors that need to be stopped // Firstly lets get list of currentActors ArrayList<Actor> actorsThatNeedToBeStopped = new ArrayList<Actor>(currentActors); // Finally subtraction will help us to find Actors to stop actorsThatNeedToBeStopped.removeAll(actorsThatNeedToBeRunning); if (isStarted()) stopChosenActors(actorsThatNeedToBeStopped); currentActors.setAll(actorsThatNeedToBeRunning); } if (isStarted()) { logger.info( "Executing SisScene '" + switchToSisSceneName + "' (" + currentActors.size() + " Actors):"); for (Actor actor : currentActors) { startActor(actor); } } } }
From source file:org.pentaho.platform.security.userroledao.jackrabbit.AbstractJcrBackedUserRoleDao.java
public void setUserRoles(Session session, final ITenant theTenant, final String userName, final String[] roles) throws RepositoryException, NotFoundException { if ((isMyself(userName) || isDefaultAdminUser(userName)) && !adminRoleExist(roles)) { throw new RepositoryException(Messages.getInstance() .getString("AbstractJcrBackedUserRoleDao.ERROR_0005_YOURSELF_OR_DEFAULT_ADMIN_USER")); }/*from w w w .ja v a2 s. c o m*/ Set<String> roleSet = new HashSet<String>(); if (roles != null) { roleSet.addAll(Arrays.asList(roles)); } roleSet.add(authenticatedRoleName); User jackrabbitUser = getJackrabbitUser(theTenant, userName, session); if ((jackrabbitUser == null) || !TenantUtils.isAccessibleTenant( theTenant == null ? tenantedUserNameUtils.getTenant(jackrabbitUser.getID()) : theTenant)) { throw new NotFoundException( Messages.getInstance().getString("AbstractJcrBackedUserRoleDao.ERROR_0003_USER_NOT_FOUND")); } HashMap<String, Group> currentlyAssignedGroups = new HashMap<String, Group>(); Iterator<Group> currentGroups = jackrabbitUser.memberOf(); while (currentGroups.hasNext()) { Group currentGroup = currentGroups.next(); currentlyAssignedGroups.put(currentGroup.getID(), currentGroup); } HashMap<String, Group> finalCollectionOfAssignedGroups = new HashMap<String, Group>(); ITenant tenant = theTenant == null ? JcrTenantUtils.getTenant(userName, true) : theTenant; for (String role : roleSet) { Group jackrabbitGroup = getJackrabbitGroup(tenant, role, session); if (jackrabbitGroup != null) { finalCollectionOfAssignedGroups.put(tenantedRoleNameUtils.getPrincipleId(tenant, role), jackrabbitGroup); } } ArrayList<String> groupsToRemove = new ArrayList<String>(currentlyAssignedGroups.keySet()); groupsToRemove.removeAll(finalCollectionOfAssignedGroups.keySet()); ArrayList<String> groupsToAdd = new ArrayList<String>(finalCollectionOfAssignedGroups.keySet()); groupsToAdd.removeAll(currentlyAssignedGroups.keySet()); for (String groupId : groupsToRemove) { currentlyAssignedGroups.get(groupId).removeMember(jackrabbitUser); } for (String groupId : groupsToAdd) { finalCollectionOfAssignedGroups.get(groupId).addMember(jackrabbitUser); } // Purge the UserDetails cache purgeUserFromCache(userName); }
From source file:org.pentaho.platform.security.userroledao.jackrabbit.AbstractJcrBackedUserRoleDao.java
public void setRoleMembers(Session session, final ITenant theTenant, final String roleName, final String[] memberUserNames) throws RepositoryException, NotFoundException { List<IPentahoUser> currentRoleMembers = getRoleMembers(session, theTenant, roleName); String[] usersToBeRemoved = findRemovedUsers(currentRoleMembers, memberUserNames); // If we are unassigning a user or users from the Administrator role, we need to check if this is a logged in user // or a user designated as a system user. If it is then we // will display a message to the user. if ((oneOfUserIsMySelf(usersToBeRemoved) || oneOfUserIsDefaultAdminUser(usersToBeRemoved)) && tenantAdminRoleName.equals(roleName)) { throw new RepositoryException(Messages.getInstance().getString( "AbstractJcrBackedUserRoleDao.ERROR_0009_USER_REMOVE_FAILED_YOURSELF_OR_DEFAULT_ADMIN_USER")); }//from w w w.j a v a 2s.c o m // If this is the last user from the Administrator role, we will not let the user remove. if (tenantAdminRoleName.equals(roleName) && (currentRoleMembers != null && currentRoleMembers.size() > 0) && memberUserNames.length == 0) { throw new RepositoryException(Messages.getInstance() .getString("AbstractJcrBackedUserRoleDao.ERROR_0001_LAST_ADMIN_ROLE", tenantAdminRoleName)); } Group jackrabbitGroup = getJackrabbitGroup(theTenant, roleName, session); if ((jackrabbitGroup == null) || !TenantUtils.isAccessibleTenant( theTenant == null ? tenantedRoleNameUtils.getTenant(jackrabbitGroup.getID()) : theTenant)) { throw new NotFoundException( Messages.getInstance().getString("AbstractJcrBackedUserRoleDao.ERROR_0002_ROLE_NOT_FOUND")); } HashMap<String, User> currentlyAssignedUsers = new HashMap<String, User>(); Iterator<Authorizable> currentMembers = jackrabbitGroup.getMembers(); while (currentMembers.hasNext()) { Authorizable member = currentMembers.next(); if (member instanceof User) { currentlyAssignedUsers.put(member.getID(), (User) member); } } HashMap<String, User> finalCollectionOfAssignedUsers = new HashMap<String, User>(); if (memberUserNames != null) { ITenant tenant = theTenant == null ? JcrTenantUtils.getTenant(roleName, false) : theTenant; for (String user : memberUserNames) { User jackrabbitUser = getJackrabbitUser(tenant, user, session); if (jackrabbitUser != null) { finalCollectionOfAssignedUsers.put(getTenantedUserNameUtils().getPrincipleId(tenant, user), jackrabbitUser); } } } ArrayList<String> usersToRemove = new ArrayList<String>(currentlyAssignedUsers.keySet()); usersToRemove.removeAll(finalCollectionOfAssignedUsers.keySet()); ArrayList<String> usersToAdd = new ArrayList<String>(finalCollectionOfAssignedUsers.keySet()); usersToAdd.removeAll(currentlyAssignedUsers.keySet()); for (String userId : usersToRemove) { jackrabbitGroup.removeMember(currentlyAssignedUsers.get(userId)); purgeUserFromCache(userId); } for (String userId : usersToAdd) { jackrabbitGroup.addMember(finalCollectionOfAssignedUsers.get(userId)); // Purge the UserDetails cache purgeUserFromCache(userId); } }
From source file:com.rickendirk.rsgwijzigingen.ZoekService.java
private Wijzigingen checkerNieuw(boolean clusters_enabled) { Wijzigingen wijzigingen = new Wijzigingen(false, null); //String halen uit SP String klasTextS = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) .getString("pref_klas", ""); //Checken of klas niet leeg is if (klasTextS.equals("")) { wijzigingen.setFout("geenKlas"); return wijzigingen; }//w w w . ja v a 2s . co m //Eerste teken klas mag geen letter zijn if (Character.isLetter(klasTextS.charAt(0))) { wijzigingen.setFout("EersteTekenLetter"); return wijzigingen; } String klasGoed = corrigeerKlas(klasTextS); if (klasGoed.equals("TeLangeKlas")) { wijzigingen.setFout("klasMeerDan4Tekens"); return wijzigingen; } ArrayList<String> clusters = new ArrayList<>(); if (clusters_enabled) { clusters.addAll(getClusters()); //Lege clusters weghalen clusters.removeAll(Collections.singleton("")); //Clusters moeten aanwezig zijn if (clusters.isEmpty()) { wijzigingen.setFout("geenClusters"); return wijzigingen; } } Document doc; try { doc = Jsoup.connect(TABLE_URL).get(); } catch (java.io.IOException e) { wijzigingen.setFout("verbindFout"); return wijzigingen; } Elements tables = doc.select("table"); if (tables.size() < 2) { //Geen geschikte tabel aanwezig wijzigingen.setFout("geenTabel"); return wijzigingen; } Element table = tables.get(1); Elements rows = table.select("tr"); ArrayList<Element> rowsList; if (clusters_enabled) { rowsList = getWijzigingenListClusters(rows, klasGoed, clusters); } else { rowsList = getwijzigingenListKlas(rows, klasGoed); } if (rowsList.isEmpty()) { //Geen wijzigingen TODO: Onderstaande comment weghalen als alles werkt //list.add("Er zijn geen roosterwijzigingen"); wijzigingen.zijnWijzigingen = false; } else { maakWijzigingenKlas(rowsList, wijzigingen); } addDagEnDatum(wijzigingen, doc); addMessage(wijzigingen, doc); return wijzigingen; }
From source file:opennlp.tools.fca.BasicLevelMetrics.java
public void predictability() { if (attributesExtent == null) this.setUp(); ArrayList<Integer> attributes = new ArrayList<Integer>(); ArrayList<Integer> outOfIntent = new ArrayList<Integer>(); Set<Integer> intersection; ArrayList<Integer> attrExtent; double sum, term; for (int i = 0; i < cl.attributeCount; i++) { attributes.add(i);/* w w w . j av a2s . co m*/ } for (FormalConcept c : cl.conceptList) { sum = 0; outOfIntent = new ArrayList<Integer>(); outOfIntent.addAll(attributes); outOfIntent.removeAll(c.intent); for (Integer y : outOfIntent) { intersection = new HashSet<Integer>(); intersection.addAll(c.extent); attrExtent = attributesExtent.get(y); intersection.retainAll(attrExtent); term = 1. * intersection.size() / c.extent.size(); if (term > 0) { sum -= term * Math.log(term); } } c.blP = Double.isNaN(1 - sum / outOfIntent.size()) ? 0 : 1 - sum / outOfIntent.size(); } }
From source file:org.alfresco.repo.search.impl.solr.facet.SolrFacetServiceImpl.java
@Override public void reorderFacets(List<String> facetIds) { // We need to validate the provided facet IDs if (facetIds == null) { throw new NullPointerException("Illegal null facetIds"); } else if (facetIds.isEmpty()) { throw new MissingFacetId("Illegal empty facetIds"); } else {//from www . j a va 2 s. com final List<SolrFacetProperties> existingFacets = getFacets(); final Map<String, SolrFacetProperties> sortedFacets = new LinkedHashMap<>(); // maintains insertion order final List<String> removedFacetIds = new ArrayList<>(); for (String facetId : facetIds) { final SolrFacetProperties facet = getFacet(facetId); if (facet == null) { // ACE-3083 logger.warn("Facet with [" + facetId + "] ID does not exist. Removing it from the facets' ordering list"); removedFacetIds.add(facetId); } else if (sortedFacets.containsKey(facetId)) { throw new DuplicateFacetId("Cannot reorder facets as sequence contains duplicate entry for ID:", facetId); } else { sortedFacets.put(facetId, facet); } } if (existingFacets.size() != sortedFacets.size()) { throw new IllegalArgument("Cannot reorder facets. Expected " + existingFacets.size() + " IDs but only received " + sortedFacets.size()); } // We can now safely apply the updates to the facet ID sequence. // // Put them in an ArrayList to ensure the collection is Serializable. // The alternative is changing the service API to look like <T extends Serializable & List<String>> // which is a bit verbose for an API. ArrayList<String> serializableProp = new ArrayList<>(facetIds); if (removedFacetIds.size() > 0) { boolean result = serializableProp.removeAll(removedFacetIds); if (result) { logger.info("Removed " + removedFacetIds + " from the facets' ordering list."); } } NodeRef facetsRoot = getFacetsRoot(); if (facetsRoot == null) { facetsRoot = createFacetsRootFolder(); } nodeService.setProperty(facetsRoot, SolrFacetModel.PROP_FACET_ORDER, serializableProp); } }
From source file:org.apache.hadoop.hive.ql.optimizer.physical.NullScanTaskDispatcher.java
private void processAlias(MapWork work, String path, ArrayList<String> aliasesAffected, ArrayList<String> aliases) { // the aliases that are allowed to map to a null scan. ArrayList<String> allowed = new ArrayList<String>(); for (String alias : aliasesAffected) { if (aliases.contains(alias)) { allowed.add(alias);/*from ww w. j av a 2 s . c o m*/ } } if (allowed.size() > 0) { work.setUseOneNullRowInputFormat(true); PartitionDesc partDesc = work.getPathToPartitionInfo().get(path).clone(); PartitionDesc newPartition = changePartitionToMetadataOnly(partDesc); Path fakePath = new Path(physicalContext.getContext().getMRTmpPath() + newPartition.getTableName() + encode(newPartition.getPartSpec())); work.getPathToPartitionInfo().put(fakePath.getName(), newPartition); work.getPathToAliases().put(fakePath.getName(), new ArrayList<String>(allowed)); aliasesAffected.removeAll(allowed); if (aliasesAffected.isEmpty()) { work.getPathToAliases().remove(path); work.getPathToPartitionInfo().remove(path); } } }
From source file:it.iit.genomics.cru.igb.bundles.mi.business.MIResult.java
public String getDiseasesHtml() { Collection<String> diseasesA = container1.getEntry().getDiseases(); Collection<String> diseasesB = container2.getEntry().getDiseases(); ArrayList<String> commonDiseases = new ArrayList<>(); ArrayList<String> uniqueDiseasesA = new ArrayList<>(); ArrayList<String> uniqueDiseasesB = new ArrayList<>(); commonDiseases.addAll(diseasesA);/*from ww w. j a v a 2 s . com*/ commonDiseases.retainAll(diseasesB); uniqueDiseasesA.addAll(diseasesA); uniqueDiseasesA.removeAll(uniqueDiseasesB); uniqueDiseasesB.addAll(diseasesB); uniqueDiseasesB.removeAll(uniqueDiseasesA); return "<html><font color=\"orange\">" + StringUtils.join(commonDiseases, ", ") + "</font> " + "<font color=\"green\">" + StringUtils.join(uniqueDiseasesA, ", ") + "</font> " + "<font color=\"blue\">" + StringUtils.join(uniqueDiseasesB, ", ") + "</font></html>"; }
From source file:net.sourceforge.ondex.cytoscape.task.ScanForKeysTask.java
/** * starts the task.//from ww w . j av a 2 s .c o m */ public void run() { monitor.setPercentCompleted(0); monitor.setStatus("scanning..."); CyAttributes nodeAtts = Cytoscape.getNodeAttributes(); String[] ans = nodeAtts.getAttributeNames(); HashMap<String, HashMap<String, String>> anMap = new HashMap<String, HashMap<String, String>>(); for (String an : ans) { anMap.put(an, new HashMap<String, String>()); } Map<String, Integer> counts = LazyMap.decorate(new HashMap<String, Integer>(), new Factory<Integer>() { @Override public Integer create() { return Integer.valueOf(0); } }); ArrayList<String> clashedANs = new ArrayList<String>(); ArrayList<String> remainingANs = new ArrayList<String>(); for (String an : ans) { remainingANs.add(an); } int[] index = network.getNodeIndicesArray(); for (int i = 0; i < index.length; i++) { String nodeId = network.getNode(index[i]).getIdentifier(); clashedANs.clear(); for (String an : remainingANs) { Object val = nodeAtts.getAttribute(nodeId, an); if (val != null && val instanceof String) { String sval = (String) val; int oldcount = counts.get(an); counts.put(an, oldcount + 1); HashMap<String, String> map = anMap.get(an); if (map.get(sval) == null) { map.put(sval, nodeId); } else {//an has clashes! clashedANs.add(an); } } } remainingANs.removeAll(clashedANs); if (remainingANs.size() == 0) { break; } monitor.setPercentCompleted((i * 100) / index.length); } for (String an : ans) { if (counts.get(an) == 0) { remainingANs.remove(an); } } monitor.setPercentCompleted(100); monitor.setStatus("done"); keys = remainingANs; }
From source file:org.pentaho.chart.plugin.jfreechart.JFreeChartFactoryEngine.java
private List<Integer> getPlotColors(Plot plot) { ArrayList<Integer> colors = new ArrayList<Integer>(); if (plot.getPalette() != null) { colors.addAll(plot.getPalette()); }/* w ww . j a v a2s .c om*/ ArrayList<Integer> defaultColors = new ArrayList<Integer>(org.pentaho.chart.model.Plot.DEFAULT_PALETTE); defaultColors.removeAll(colors); colors.addAll(defaultColors); return colors; }