List of usage examples for java.util List retainAll
boolean retainAll(Collection<?> c);
From source file:org.bibsonomy.webapp.util.RankingUtil.java
/** * TODO: impove doc//ww w.ja v a2 s . c om * * @param <T> * @param sourceUserTags * @param targetUserTags */ public static <T extends Resource> void computeRanking(List<Tag> sourceUserTags, List<Tag> targetUserTags) { // first, build map of target user's tags Map<String, Integer> tagGlobalCounts = new HashMap<String, Integer>(); Map<String, Integer> tagUserCounts = new HashMap<String, Integer>(); int maxUserFreq = 0; for (Tag t : sourceUserTags) { if (t.getGlobalcount() > 0) { tagGlobalCounts.put(t.getName(), t.getGlobalcount()); } if (t.getUsercount() > 0) { tagUserCounts.put(t.getName(), t.getUsercount()); } if (t.getUsercount() > maxUserFreq) { maxUserFreq = t.getUsercount(); } } // compute the intersection of tags targetUserTags.retainAll(sourceUserTags); // compute the ranking for the intersection for (Tag tag : targetUserTags) { // double weight = ( ( ( (double) tagUserCounts.get(tag.getName()) ) / maxUserFreq ) * Math.log(MAX_TAG_GLOBALCOUNT / tagGlobalCounts.get(tag.getName()) ) ) * 100 ; tag.setGlobalcount(tag.getUsercount()); LOGGER.debug("working on tag " + tag.getName() + ", having user freq " + tagUserCounts.get(tag.getName()) + " and global count " + tagGlobalCounts.get(tag.getName())); if (tagUserCounts.get(tag.getName()) != null && tagGlobalCounts.get(tag.getName()) != null) { double weight = ((((double) tagUserCounts.get(tag.getName())) / maxUserFreq) * Math.log(MAX_TAG_GLOBALCOUNT / tagGlobalCounts.get(tag.getName()))) * 10; // tag.setGlobalcount((int) weight); tag.setUsercount((int) weight); } else { tag.setUsercount(0); } } }
From source file:gov.nih.nci.eagle.service.validation.ListValidationServiceImpl.java
public List<String> validateList(List<String> items, SpecimenType specimenType) { if (dataPatientMap == null) buildMap();//w ww .ja va2 s . co m List list = dataPatientMap.get(specimenType); List returnList = new ArrayList(list); returnList.retainAll(items); return returnList; }
From source file:de.tudarmstadt.ukp.csniper.resbuild.stuff.InclusionsCreator.java
private List<String> cut(List<String> aList1, List<String> aList2) { List<String> ret = new ArrayList<String>(aList1); ret.retainAll(aList2); return ret;//from w w w .jav a2 s . c om }
From source file:org.opendaylight.vpnservice.itm.impl.ItmUtils.java
private static void validateForSingleGreTep(String schemaName, List<BigInteger> lstDpnsForAdd, List<VtepConfigSchema> existingSchemas) { for (VtepConfigSchema existingSchema : emptyIfNull(existingSchemas)) { if ((TunnelTypeGre.class).equals(existingSchema.getTunnelType()) && !StringUtils.equalsIgnoreCase(schemaName, existingSchema.getSchemaName())) { List<BigInteger> lstConflictingDpns = new ArrayList<>(getDpnIdList(existingSchema.getDpnIds())); lstConflictingDpns.retainAll(emptyIfNull(lstDpnsForAdd)); if (!lstConflictingDpns.isEmpty()) { String errMsg = new StringBuilder("DPN's ").append(lstConflictingDpns).append( " already configured with GRE TEP. Mutiple GRE TEP's on a single DPN are not allowed.") .toString();/* w w w . j a v a 2 s . c om*/ Preconditions.checkArgument(false, errMsg); } } } }
From source file:org.opendaylight.vpnservice.itm.impl.ItmUtils.java
public static VtepConfigSchema validateForUpdateVtepSchema(String schemaName, List<BigInteger> lstDpnsForAdd, List<BigInteger> lstDpnsForDelete, IITMProvider itmProvider) { Preconditions.checkArgument(StringUtils.isNotBlank(schemaName)); if ((lstDpnsForAdd == null || lstDpnsForAdd.isEmpty()) && (lstDpnsForDelete == null || lstDpnsForDelete.isEmpty())) { Preconditions.checkArgument(false, new StringBuilder("DPN ID list for add | delete is null or empty in schema ").append(schemaName) .toString());//from w w w. ja va2 s . c o m } VtepConfigSchema schema = itmProvider.getVtepConfigSchema(schemaName); if (schema == null) { Preconditions.checkArgument(false, new StringBuilder("Specified VTEP Schema [").append(schemaName) .append("] doesn't exists!").toString()); } List<BigInteger> existingDpnIds = getDpnIdList(schema.getDpnIds()); if (isNotEmpty(lstDpnsForAdd)) { if (isNotEmpty(existingDpnIds)) { List<BigInteger> lstAlreadyExistingDpns = new ArrayList<>(existingDpnIds); lstAlreadyExistingDpns.retainAll(lstDpnsForAdd); Preconditions.checkArgument(lstAlreadyExistingDpns.isEmpty(), new StringBuilder("DPN ID's ").append(lstAlreadyExistingDpns) .append(" already exists in VTEP schema [").append(schemaName).append("]") .toString()); } if (schema.getTunnelType().equals(TunnelTypeGre.class)) { validateForSingleGreTep(schema.getSchemaName(), lstDpnsForAdd, itmProvider.getAllVtepConfigSchemas()); } } if (isNotEmpty(lstDpnsForDelete)) { if (existingDpnIds == null || existingDpnIds.isEmpty()) { StringBuilder builder = new StringBuilder("DPN ID's ").append(lstDpnsForDelete) .append(" specified for delete from VTEP schema [").append(schemaName) .append("] are not configured in the schema."); Preconditions.checkArgument(false, builder.toString()); } else if (!existingDpnIds.containsAll(lstDpnsForDelete)) { List<BigInteger> lstConflictingDpns = new ArrayList<>(lstDpnsForDelete); lstConflictingDpns.removeAll(existingDpnIds); StringBuilder builder = new StringBuilder("DPN ID's ").append(lstConflictingDpns) .append(" specified for delete from VTEP schema [").append(schemaName) .append("] are not configured in the schema."); Preconditions.checkArgument(false, builder.toString()); } } return schema; }
From source file:org.biokoframework.system.services.authentication.impl.AbstractAuthenticationService.java
protected void ensureRoles(List<String> requiredRoles, String userRolesString) throws AuthenticationFailureException { if (requiredRoles == null || requiredRoles.isEmpty()) { return;//from w w w.ja v a 2s . c o m } if (StringUtils.isEmpty(userRolesString)) { throw CommandExceptionsFactory.createInsufficientPrivilegesException(); } List<String> userRoles = new LinkedList<>(Arrays.asList(userRolesString.split("\\|"))); userRoles.retainAll(requiredRoles); if (userRoles.isEmpty()) { throw CommandExceptionsFactory.createInsufficientPrivilegesException(); } }
From source file:org.openmrs.module.reporting.query.obs.evaluator.SqlObsQueryEvaluator.java
/** * @see ObsQueryEvaluator#evaluate(ObsQuery, EvaluationContext) * @should evaluate a SQL query into an ObsQuery * @should filter results given a base Obs Query Result in an EvaluationContext * @should filter results given a base Encounter Query Result in an EvaluationContext * @should filter results given a base cohort in an EvaluationContext *//* ww w . j av a 2s .co m*/ public ObsQueryResult evaluate(ObsQuery definition, EvaluationContext context) { context = ObjectUtil.nvl(context, new EvaluationContext()); SqlObsQuery sqlObsQuery = (SqlObsQuery) definition; ObsQueryResult queryResult = new ObsQueryResult(sqlObsQuery, context); ObsIdSet obsIds = new ObsIdSet(ObsDataUtil.getObsIdsForContext(context, false)); if (obsIds.getSize() == 0) { return queryResult; } SqlQueryBuilder qb = new SqlQueryBuilder(); qb.append(sqlObsQuery.getQuery()); qb.setParameters(context.getParameterValues()); if (sqlObsQuery.getQuery().contains(":obsIds")) { qb.addParameter("obsIds", obsIds); } List<Integer> l = evaluationService.evaluateToList(qb, Integer.class, context); l.retainAll(obsIds.getMemberIds()); queryResult.addAll(l); return queryResult; }
From source file:org.openmrs.module.reporting.query.encounter.evaluator.SqlEncounterQueryEvaluator.java
/** * @see EncounterQueryEvaluator#evaluate(EncounterQuery, EvaluationContext) * @should evaluate a SQL query into an EncounterQuery * @should filter results given a base Encounter Query Result in an EvaluationContext * @should filter results given a base cohort in an EvaluationContext */// w w w.j a v a 2s .c om public EncounterQueryResult evaluate(EncounterQuery definition, EvaluationContext context) throws EvaluationException { context = ObjectUtil.nvl(context, new EvaluationContext()); SqlEncounterQuery sqlEncounterQuery = (SqlEncounterQuery) definition; EncounterQueryResult queryResult = new EncounterQueryResult(sqlEncounterQuery, context); EncounterIdSet encounterIds = new EncounterIdSet( EncounterDataUtil.getEncounterIdsForContext(context, false)); if (encounterIds.getSize() == 0) { return queryResult; } SqlQueryBuilder qb = new SqlQueryBuilder(); qb.append(sqlEncounterQuery.getQuery()); qb.setParameters(context.getParameterValues()); if (sqlEncounterQuery.getQuery().contains(":encounterIds")) { qb.addParameter("encounterIds", encounterIds); } List<Integer> l = evaluationService.evaluateToList(qb, Integer.class, context); l.retainAll(encounterIds.getMemberIds()); queryResult.addAll(l); return queryResult; }
From source file:org.b3mn.poem.handler.TagHandler.java
@SuppressWarnings("unchecked") @FilterMethod(FilterName = "tags") public static Collection<String> tagFilter(Identity subject, String params) throws Exception { List<String> finalUris = Persistance.getSession() .createSQLQuery("SELECT DISTINCT access.object_name " + "FROM access " + "WHERE (access.subject_name='public' OR access.subject_id=:subject_id) ") .setInteger("subject_id", subject.getId()).list(); for (String tag : params.split(",")) { tag = StringEscapeUtils.unescapeHtml(tag); tag = removeSpaces(tag);//from ww w. ja v a2s . c o m List<String> tagUris = Persistance.getSession() .createSQLQuery("SELECT access.object_name " + "FROM tag_relation, tag_definition, access " + "WHERE tag_relation.tag_id=tag_definition.id " + "AND (access.subject_name='public' OR access.subject_id=:subject_id) " + "AND tag_relation.object_id=access.object_id " + "AND tag_definition.name=:tag_name") .setInteger("subject_id", subject.getId()).setString("tag_name", tag).list(); Persistance.commit(); finalUris.retainAll(tagUris); } return finalUris; }
From source file:nl.strohalm.cyclos.services.accounts.AccountTypeServiceSecurity.java
@Override public List<? extends AccountType> search(final AccountTypeQuery query) { List<? extends AccountType> accountTypes = accountTypeService.search(query); accountTypes.retainAll(accountTypeService.getVisibleAccountTypes()); return accountTypes; }