List of usage examples for org.apache.commons.collections CollectionUtils intersection
public static Collection intersection(final Collection a, final Collection b)
From source file:fi.csc.idp.stepup.impl.InitializeStepUpChallengeContext.java
/** {@inheritDoc} */ @Override//from w w w. j a v a 2 s .c o m protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext, @Nonnull final AuthenticationContext authenticationContext) { StepUpMethodContext stepUpMethodContext = (StepUpMethodContext) authenticationContext .addSubcontext(new StepUpMethodContext(), true); for (Iterator<Entry<StepUpMethod, List<? extends Principal>>> it = stepUpMethods.entrySet().iterator(); it .hasNext();) { Entry<StepUpMethod, List<? extends Principal>> entry = it.next(); StepUpMethod stepupMethod = entry.getKey(); log.debug("{} initializing StepUp method and accounts for {}", getLogPrefix(), stepupMethod.getName()); try { if (!stepupMethod.initialize(attributeContext)) { log.debug("{} not able to initialize method {} removed from available methods", getLogPrefix(), stepupMethod.getName()); it.remove(); } } catch (Exception e) { log.error("{} something unexpected happened", getLogPrefix()); log.error(e.getMessage()); ActionSupport.buildEvent(profileRequestContext, StepUpEventIds.EXCEPTION); return; } } log.debug("{} setting {} stepup methods to context", getLogPrefix(), stepUpMethods.size()); stepUpMethodContext.setStepUpMethods(stepUpMethods); for (Entry<StepUpMethod, List<? extends Principal>> entry : stepUpMethods.entrySet()) { if (CollectionUtils.intersection(entry.getValue(), shibbolethContext.getInitialRequestedContext()) .size() > 0) { // We set the last iterated method as the method log.debug("{} setting method {} as default method", getLogPrefix(), entry.getKey().getName()); stepUpMethodContext.setStepUpMethod(entry.getKey()); // That method has accounts try { if (entry.getKey().getAccounts() != null) { for (StepUpAccount account : entry.getKey().getAccounts()) { // and the account is enabled if (account.isEnabled()) { log.debug("{} setting a default stepup account", getLogPrefix()); log.debug("Account type is {}", entry.getKey().getName()); log.debug("Account name is {}", (account.getName() == null ? "" : account.getName())); stepUpMethodContext.setStepUpAccount(account); return; } } } } catch (Exception e) { log.debug("{} something unexpected happened", getLogPrefix()); log.error(e.getMessage()); ActionSupport.buildEvent(profileRequestContext, StepUpEventIds.EXCEPTION); return; } } } // No default account automatically chosen }
From source file:com.sonymobile.jenkins.plugins.lenientshutdown.ShutdownManageLink.java
/** * Checks if any of the queue ids in argument list is coming from a white listed project run. * * @param queueIds the list of queue ids to check * @return true if at least one of the projects is white listed *//*from w w w. ja v a 2s . com*/ public boolean isAnyWhiteListedUpstreamProject(Set<Long> queueIds) { Collection<?> intersection = CollectionUtils.intersection(queueIds, whiteListedQueueIds); return !intersection.isEmpty(); }
From source file:edu.scripps.fl.pubchem.promiscuity.PCPromiscuityFactory.java
@SuppressWarnings("unchecked") private void addMLPProjectCounts(OverallListsAndMaps overall, Map<String, PromiscuityCount<?>> countMap) { PromiscuityCount<Long> summaryCount = (PromiscuityCount<Long>) countMap.get(allProjectsName); if (summaryCount != null) { List<Long> mlpSummaryTotal = (List<Long>) CollectionUtils.intersection(summaryCount.getTotal(), overall.getMlpSummaries()); List<Long> mlpSummaryActive = (List<Long>) CollectionUtils.intersection(summaryCount.getActive(), overall.getMlpSummaries()); PromiscuityCount<Long> mlpSummaryCount = new PromiscuityCount<Long>(mlpProjectsNames, mlpSummaryActive, mlpSummaryTotal);/*from w w w. j ava 2s. com*/ countMap.put(mlpSummaryCount.getName(), mlpSummaryCount); } }
From source file:expansionBlocks.ProcessCommunities.java
private static Map<Entity, Double> fusion(Map<Entity, Double> c1, Map<Entity, Double> c2) { Map<Entity, Double> result = new HashMap<>(); Map<Entity, Double> c1c = new HashMap<>(c1); Map<Entity, Double> c2c = new HashMap<>(c2); Set<Long> intersection = new HashSet(CollectionUtils.intersection(c1c.keySet(), c2c.keySet())); for (Map.Entry<Entity, Double> e : c1c.entrySet()) { Entity id = e.getKey();/* w w w .j a v a 2 s.c o m*/ Double d = e.getValue(); if (intersection.contains(id)) { Double d2 = c2c.get(id); d = (d + d2) / 2; c2c.remove(id); } result.put(id, d); } for (Map.Entry<Entity, Double> e : c2c.entrySet()) { Entity id = e.getKey(); Double d = e.getValue(); result.put(id, d); } return result; }
From source file:controllers.Service.java
public static void selectedToKML(String surveyId, String resultIDs) { Survey survey = Survey.findById(Long.decode(surveyId)); String[] resultsIds = resultIDs.split(","); Collection<NdgResult> results = new ArrayList<NdgResult>(); Collection<NdgResult> removalResults = new ArrayList<NdgResult>(); NdgResult result = null;/* w w w .jav a 2 s .c o m*/ if (resultsIds.length > 0) { for (int i = 0; i < resultsIds.length; i++) { result = NdgResult.find("byId", Long.parseLong(resultsIds[i])).first(); if (result != null) { results.add(result); } } } for (NdgResult current : results) { if (current.latitude == null || current.longitude == null) { removalResults.add(current); } } results.removeAll(removalResults); ByteArrayOutputStream arqExport = new ByteArrayOutputStream(); String fileName = surveyId + ".kml"; try { final Kml kml = new Kml(); final Document document = kml.createAndSetDocument(); for (NdgResult current : results) { // String description = "<![CDATA[ "; String description = ""; int i = 0; List<Question> questions = new ArrayList<Question>(); questions = survey.getQuestions(); if (questions.isEmpty()) { description += "<b> NO QUESTION </b> <br><br>"; } for (Question question : questions) { i++; description += "<h3><b>" + i + " - " + question.label + "</b></h3><br>"; Collection<Answer> answers = CollectionUtils.intersection(question.answerCollection, current.answerCollection); if (answers.isEmpty()) { description += "<br><br>"; } else if (answers.size() == 1) { Answer answer = answers.iterator().next(); if (answer.question.questionType.typeName.equalsIgnoreCase(QuestionTypesConsts.IMAGE)) { /* ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; InputStream in = answer.binaryData.get(); int n = 0; try { while( (n = in.read(buf) ) >= 0) { baos.write(buf, 0, n); } in.close(); } catch(IOException ex) { System.out.println("IO"); } byte[] bytes = baos.toByteArray(); System.out.println("image = " + Base64.encodeBase64String(bytes)); description += "<img src='data:image/jpeg;base64," + Base64.encodeBase64String(bytes) + "'/> <br><br>"; */ description += "<b> #image</b> <br><br>"; } else { description += "<h4 style='color:#3a77ca'><b>" + answer.textData + "</b></h4><br>"; } } } // description += " ]]>"; document.createAndAddPlacemark().withName(current.title).withOpen(Boolean.TRUE) .withDescription(description).createAndSetPoint() .addToCoordinates(current.longitude + ", " + current.latitude); } kml.marshal(arqExport); send(fileName, arqExport.toByteArray()); } catch (FileNotFoundException ex) { } }
From source file:com.univocity.app.DataUpdateTest.java
private void validateAbsentRecordsGotRemoved(String entityName, RowDataCollector dataCollector, String deleteFile) {//from www . j av a2 s . com String[] fieldNames = dataCollector.getFieldNames(); DataSource dataSource = DataStores.getInstance().getSourceDatabase().getDataSource(); List<Map<String, Object>> results = new JdbcTemplate(dataSource) .queryForList("SELECT " + toString(fieldNames).replace('^', ',') + " FROM " + entityName); Set<String> idsOnDatabase = new HashSet<String>(results.size()); for (Map<String, Object> e : results) { String id = toString(fieldNames, e); idsOnDatabase.add(id); } System.gc(); if (deleteFile == null) { Set<String> sr25Rows = getMapOfRows(entityName, fieldNames, true).keySet(); Set<String> sr26Rows = getMapOfRows(entityName, fieldNames, false).keySet(); @SuppressWarnings("unchecked") Collection<String> commonIds = CollectionUtils.intersection(sr25Rows, sr26Rows); sr25Rows.removeAll(commonIds); sr26Rows.removeAll(commonIds); sr25Rows = new TreeSet<String>(sr25Rows); sr26Rows = new TreeSet<String>(sr26Rows); for (String id : idsOnDatabase) { //table does not retain ids that are not in SR26 assertFalse(sr25Rows.contains(id)); sr26Rows.remove(id); } // ensures no unexpected ID is found on SR26. assertTrue(sr26Rows.isEmpty()); } else { parserSettings.setRowProcessor(dataCollector); new CsvParser(parserSettings) .parse(DataStores.getInstance().getSourceData().openUpdateFile(deleteFile)); Set<String> expectedToBeRemoved = dataCollector.getExpected(); for (String toBeRemoved : expectedToBeRemoved) { assertFalse(idsOnDatabase.contains(toBeRemoved)); } } }
From source file:expansionBlocks.ProcessCommunities.java
private static double compareCommunities(Set<Entity> c1, Set<Entity> c2) { Collection intersection = CollectionUtils.intersection(c1, c2); double d, d1, d2; d1 = ((double) intersection.size()) / ((double) c1.size()); d2 = ((double) intersection.size()) / ((double) c2.size()); d = d1 > d2 ? d1 : d2;// w w w .ja v a2 s . c o m return d; }
From source file:com.squid.kraken.v4.core.analysis.engine.index.DimensionStore.java
@Override public List<DimensionMember> getMembersFilterByParents(Map<DimensionIndex, List<DimensionMember>> selections, int offset, int size) { ArrayList<DimensionMember> result = new ArrayList<>(); Set<DimensionMember> flatsel = new HashSet<>(); int types = 0; for (List<DimensionMember> forType : selections.values()) { flatsel.addAll(forType);/*from w w w .j a v a 2s . c om*/ types++; } for (DimensionMember member : members) { @SuppressWarnings("unchecked") Collection<DimensionMember> check = CollectionUtils.intersection(getCorrelations(member), flatsel); if (!check.isEmpty() && check.size() >= types) { // ok, in some special cases, the test is not enough - we should check that we have a hit for each type result.add(member); } } return result; }
From source file:gov.nih.nci.cabig.caaers.web.security.FabricatedAuthenticationFilter.java
private GrantedAuthority[] findAdjustedAuthorities(GrantedAuthority[] authorities, HttpServletRequest request) { ArrayList<GrantedAuthority> adjustedAuthorities = new ArrayList<GrantedAuthority>(); if (authorities != null && authorities.length > 0) { Collection<String> applicableRoleNames = new ArrayList<String>(); //default all roles in the authorities are applicable for (GrantedAuthority authority : authorities) applicableRoleNames.add(authority.getAuthority()); URLToRoleListMapEntry urlRolesEntry = getURLToRolesEntryFromRequest(request); if (urlRolesEntry != null) { //only retain those roles suggested for the url. applicableRoleNames = CollectionUtils.intersection(applicableRoleNames, urlRolesEntry.getRoleNames()); URLToEntityIdMapEntry entityRolesEntry = getURLToEntityIdEntryFromRequest(request); if (entityRolesEntry != null) { //only retain those roles suggested for the entity. applicableRoleNames = CollectionUtils.intersection(applicableRoleNames, getSuggestedRolesForEntity(entityRolesEntry)); }/*from ww w . j a va 2 s .c o m*/ } for (String roleName : applicableRoleNames) adjustedAuthorities.add(new GrantedAuthorityImpl(roleName)); } return adjustedAuthorities.toArray(new GrantedAuthority[0]); }
From source file:edu.scripps.fl.pubchem.promiscuity.PCPromiscuityFactory.java
@SuppressWarnings("unchecked") private void addProjectCountsPerCompoundAndProtein(OverallListsAndMaps overall, Map<String, PromiscuityCount<?>> countMapPerProtein, Map<String, PromiscuityCount<?>> countMapPerCompound) { PromiscuityCount<Long> allAssayCount = (PromiscuityCount<Long>) countMapPerProtein.get(allAssayName); if (allAssayCount != null) { PromiscuityCount<Long> allSummariesPerCompound = (PromiscuityCount<Long>) countMapPerCompound .get(allProjectsName);//from ww w . java2 s . c o m if (allSummariesPerCompound != null) { List<Long> totalSummary = getTotalSummaryListPerCompoundAndProtein( allSummariesPerCompound.getTotal(), overall.getSummaryToAIDsMap(), allAssayCount.getTotal()); List<Long> activeSummary = new ArrayList<Long>(); activeSummary = (List<Long>) CollectionUtils.intersection(allSummariesPerCompound.getActive(), totalSummary); PromiscuityCount<Long> count = new PromiscuityCount<Long>(allProjectsName, activeSummary, totalSummary); countMapPerProtein.put(allProjectsName, count); } } }