Example usage for java.util List retainAll

List of usage examples for java.util List retainAll

Introduction

In this page you can find the example usage for java.util List retainAll.

Prototype

boolean retainAll(Collection<?> c);

Source Link

Document

Retains only the elements in this list that are contained in the specified collection (optional operation).

Usage

From source file:com.gargoylesoftware.htmlunit.javascript.host.PropertiesTest.java

/**
 * Test./*from www .  j  a v  a  2  s  . c om*/
 * @throws IOException If an error occurs
 */
@Test
public void test() throws IOException {
    final List<String> realList;
    final List<String> simulatedList;
    final DefaultCategoryDataset dataset;
    final StringBuilder html;
    final MutableInt actualPropertyCount;
    final MutableInt remainingPropertyCount;
    if (browserVersion_ == BrowserVersion.INTERNET_EXPLORER_6) {
        realList = IE6_;
        simulatedList = IE6_SIMULATED_;
        dataset = CATEGORY_DATASET_IE6_;
        html = IE6_HTML_;
        actualPropertyCount = IE6_ACTUAL_PROPERTY_COUNT_;
        remainingPropertyCount = IE6_REMAINING_PROPERTY_COUNT_;
    } else if (browserVersion_ == BrowserVersion.INTERNET_EXPLORER_7) {
        realList = IE7_;
        simulatedList = IE7_SIMULATED_;
        dataset = CATEGORY_DATASET_IE7_;
        html = IE7_HTML_;
        actualPropertyCount = IE7_ACTUAL_PROPERTY_COUNT_;
        remainingPropertyCount = IE7_REMAINING_PROPERTY_COUNT_;
    } else if (browserVersion_ == BrowserVersion.INTERNET_EXPLORER_8) {
        realList = IE8_;
        simulatedList = IE8_SIMULATED_;
        dataset = CATEGORY_DATASET_IE8_;
        html = IE8_HTML_;
        actualPropertyCount = IE8_ACTUAL_PROPERTY_COUNT_;
        remainingPropertyCount = IE8_REMAINING_PROPERTY_COUNT_;
    } else if (browserVersion_ == BrowserVersion.FIREFOX_3) {
        realList = FF3_;
        simulatedList = FF3_SIMULATED_;
        dataset = CATEGORY_DATASET_FF3_;
        html = FF3_HTML_;
        actualPropertyCount = FF3_ACTUAL_PROPERTY_COUNT_;
        remainingPropertyCount = FF3_REMAINING_PROPERTY_COUNT_;
    } else if (browserVersion_ == BrowserVersion.FIREFOX_3_6) {
        realList = FF3_6_;
        simulatedList = FF3_6_SIMULATED_;
        dataset = CATEGORY_DATASET_FF3_6_;
        html = FF3_6_HTML_;
        actualPropertyCount = FF3_6_ACTUAL_PROPERTY_COUNT_;
        remainingPropertyCount = FF3_6_REMAINING_PROPERTY_COUNT_;
    } else {
        fail("Unknown BrowserVersion " + browserVersion_);
        return;
    }

    List<String> realProperties = Arrays.asList(getValueOf(realList, name_).split(","));
    List<String> simulatedProperties = Arrays.asList(getValueOf(simulatedList, name_).split(","));
    if (realProperties.size() == 1 && realProperties.get(0).length() == 0) {
        realProperties = new ArrayList<String>();
    }
    if (simulatedProperties.size() == 1 && simulatedProperties.get(0).length() == 0) {
        simulatedProperties = new ArrayList<String>();
    }
    final List<String> originalRealProperties = new ArrayList<String>(realProperties);
    removeParentheses(realProperties);
    removeParentheses(simulatedProperties);

    final List<String> erroredProperties = new ArrayList<String>(simulatedProperties);
    erroredProperties.removeAll(realProperties);

    final List<String> implementedProperties = new ArrayList<String>(simulatedProperties);
    implementedProperties.retainAll(realProperties);

    dataset.addValue(implementedProperties.size(), "Implemented", name_);
    dataset.addValue(realProperties.size(),
            browserVersion_.getNickname().replace("FF", "Firefox ").replace("IE", "Internet Explorer "), name_);
    dataset.addValue(erroredProperties.size(), "Should not be implemented", name_);

    final List<String> remainingProperties = new ArrayList<String>(realProperties);
    remainingProperties.removeAll(implementedProperties);

    actualPropertyCount.add(realProperties.size());
    remainingPropertyCount.add(remainingProperties.size());

    if (LOG.isDebugEnabled()) {
        LOG.debug(name_ + ':' + browserVersion_.getNickname() + ':' + realProperties);
        LOG.debug("Remaining" + ':' + remainingProperties);
        LOG.debug("Error" + ':' + erroredProperties);
    }

    appendHtml(html, originalRealProperties, simulatedProperties, erroredProperties);
    if (dataset.getColumnCount() == IE7_.size()) {
        saveChart(dataset);
        html.append("<tr><td colspan='3' align='right'><b>Total Implemented: ")
                .append(actualPropertyCount.intValue() - remainingPropertyCount.intValue()).append(" / ")
                .append(actualPropertyCount.intValue()).append("</b></td></tr>");
        html.append("</table>").append('\n').append("<br>").append("Legend:").append("<br>")
                .append("<span style='color: blue'>").append("To be implemented").append("</span>")
                .append("<br>").append("<span style='color: green'>").append("Implemented").append("</span>")
                .append("<br>").append("<span style='color: red'>").append("Should not be implemented")
                .append("</span>").append("</html>");

        FileUtils.writeStringToFile(
                new File(getArtifactsDirectory() + "/properties-" + browserVersion_.getNickname() + ".html"),
                html.toString());
    }
}

From source file:com.xpn.xwiki.plugin.calendar.CalendarData.java

public String getContent(Calendar tddate, String filteredUser, String filteredLocation, List filteredCategories,
        XWikiContext context) {//from w w  w .j  a v a2s.  c om
    StringBuffer result = new StringBuffer();
    for (Iterator it = getCalendarData(tddate).iterator(); it.hasNext();) {
        CalendarEvent event = (CalendarEvent) it.next();
        String user = event.getUser();
        if (!StringUtils.isBlank(filteredUser) && (!filteredUser.trim().equals(user))) {
            continue;
        }
        String location = event.getLocation();
        if (!StringUtils.isBlank(filteredLocation) && (!filteredLocation.trim().equals(location))) {
            continue;
        }
        List categories;
        if (filteredCategories != null && filteredCategories.size() > 0) {
            categories = new ArrayList(event.getCategory());
            categories.retainAll(filteredCategories);
            if (categories.size() <= 0) {
                continue;
            }
        }
        categories = event.getCategory();
        String title = event.getTitle();
        String url = event.getUrl();
        result.append("<div class=\"event");
        if (categories != null && categories.size() > 0) {
            for (Iterator cit = categories.iterator(); cit.hasNext();) {
                result.append(" " + cit.next());
            }
        }
        result.append("\">");
        if (!StringUtils.isBlank(user)) {
            result.append("<span class=\"username\">"
                    + context.getWiki().getLocalUserName(event.getUser(), context) + "</span>");
        }
        if (!StringUtils.isBlank(user) && !StringUtils.isBlank(title)) {
            result.append(": ");
        }
        if (!StringUtils.isBlank(url)) {
            result.append("<a href=\"" + url + "\">");
        }
        result.append(title);
        if (!StringUtils.isBlank(url)) {
            result.append("</a>");
        }
        result.append("</div>");
    }
    return result.toString();
}

From source file:es.us.isa.ideas.app.controllers.WSMController.java

@RequestMapping(value = "", method = RequestMethod.GET)
public ModelAndView index(Model model, @RequestParam(value = "filter", required = false) String filter) {

    ModelAndView result;/* w w  w . j  a  v a  2 s . c om*/

    if (!studioConfiguration.getAdvancedMode()) {
        return new ModelAndView("redirect:/app/editor");
    }
    result = new ModelAndView("app/wsm");

    Collection<Workspace> taggedWS = null;

    if (filter != null && filter.length() > 0) {
        String[] tags = filter.split(" ");
        taggedWS = workspaceService.findByTags(tags);
    }

    List<Workspace> workspaces = (List<Workspace>) workspaceService.findByPrincipal();
    List<Workspace> demos = (List<Workspace>) workspaceService.findByDemoPrincipal();
    List<Workspace> otherdemos = (List<Workspace>) workspaceService.findByOtherDemos();
    Collection<Tag> tagsCollection = tagService.findTagsInUse();

    if (taggedWS != null && workspaces != null) {
        workspaces.retainAll(taggedWS);
    }

    if (taggedWS != null && demos != null) {
        demos.retainAll(taggedWS);
    }

    if (taggedWS != null && otherdemos != null) {
        otherdemos.retainAll(taggedWS);
    }

    result.addObject("workspaces", workspaces);
    result.addObject("demos", demos);
    result.addObject("otherdemos", otherdemos);
    result.addObject("tags", tagsCollection);

    return result;
}

From source file:org.constretto.spring.EnvironmentAnnotationConfigurer.java

private boolean decideIfAutowireCandiate(String beanName, final Environment environmentAnnotation) {
    List<String> targetEnvironments = new ArrayList<String>() {
        {//  w  w w .  j  ava 2 s .  c  om
            addAll(asList(environmentAnnotation.value()));
        }
    };
    validateAnnotationValues(beanName, targetEnvironments);
    List<String> assemblyContext = assemblyContextResolver.getAssemblyContext();
    targetEnvironments.retainAll(assemblyContext);
    boolean autowireCandidate = !targetEnvironments.isEmpty();
    if (autowireCandidate) {
        logger.info(beanName + " is annotated with environment '" + environmentAnnotation.value()
                + "', and is selected for autowiring in the current environment '"
                + assemblyContextResolver.getAssemblyContext() + "'");
    } else {
        logger.info(beanName + " is annotated with environment '" + environmentAnnotation.value()
                + "', and is discarded for autowiring in the current environment '"
                + assemblyContextResolver.getAssemblyContext() + "'");
    }
    return autowireCandidate;
}

From source file:org.wso2.carbon.apimgt.keymgt.handlers.ScopesIssuer.java

public boolean setScopes(OAuthTokenReqMessageContext tokReqMsgCtx) {
    String[] requestedScopes = tokReqMsgCtx.getScope();
    String[] defaultScope = new String[] { DEFAULT_SCOPE_NAME };

    //If no scopes were requested.
    if (requestedScopes == null || requestedScopes.length == 0) {
        tokReqMsgCtx.setScope(defaultScope);
        return true;
    }//w ww .  ja va  2  s. c  o m

    String consumerKey = tokReqMsgCtx.getOauth2AccessTokenReqDTO().getClientId();
    String username = tokReqMsgCtx.getAuthorizedUser();

    String cacheKey = getAppUserScopeCacheKey(consumerKey, username, requestedScopes);
    Cache cache = Caching.getCacheManager(APIConstants.API_MANAGER_CACHE_MANAGER)
            .getCache(APIConstants.APP_USER_SCOPE_CACHE);

    //Cache hit
    if (cache.containsKey(cacheKey)) {
        tokReqMsgCtx.setScope((String[]) cache.get(cacheKey));
        return true;
    }

    List<String> reqScopeList = Arrays.asList(requestedScopes);

    try {
        Map<String, String> appScopes = null;
        Cache appCache = Caching.getCacheManager(APIConstants.API_MANAGER_CACHE_MANAGER)
                .getCache(APIConstants.APP_SCOPE_CACHE);

        //Cache hit
        if (appCache.containsKey(consumerKey)) {
            appScopes = (Map<String, String>) appCache.get(consumerKey);
        }
        //Cache miss
        else {
            ApiMgtDAO apiMgtDAO = new ApiMgtDAO();
            //Get all the scopes and roles against the scopes defined for the APIs subscribed to the application.
            appScopes = apiMgtDAO.getScopeRolesOfApplication(consumerKey);
            //If scopes is null, set empty hashmap to scopes so that we avoid adding a null entry to the cache.
            if (appScopes == null) {
                appScopes = new HashMap<String, String>();
            }
            appCache.put(consumerKey, appScopes);
        }

        //If no scopes can be found in the context of the application
        if (appScopes.isEmpty()) {
            if (log.isDebugEnabled()) {
                log.debug("No scopes defined for the Application "
                        + tokReqMsgCtx.getOauth2AccessTokenReqDTO().getClientId());
            }

            String[] allowedScopes = getAllowedScopes(reqScopeList);
            tokReqMsgCtx.setScope(allowedScopes);
            cache.put(cacheKey, allowedScopes);
            return true;
        }

        int tenantId;
        RealmService realmService = OAuthComponentServiceHolder.getRealmService();
        UserStoreManager userStoreManager = null;
        String[] userRoles = null;

        try {
            tenantId = IdentityUtil.getTenantIdOFUser(username);
            userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
            userRoles = userStoreManager.getRoleListOfUser(MultitenantUtils.getTenantAwareUsername(username));
        } catch (IdentityException e) {
            //Log and return since we do not want to stop issuing the token in case of scope validation failures.
            log.error("Error when obtaining tenant Id of user " + username, e);
            return false;
        } catch (UserStoreException e) {
            //Log and return since we do not want to stop issuing the token in case of scope validation failures.
            log.error("Error when getting the tenant's UserStoreManager or when getting roles of user ", e);
            return false;
        }

        if (userRoles == null || userRoles.length == 0) {
            if (log.isDebugEnabled()) {
                log.debug("Could not find roles of the user.");
            }
            tokReqMsgCtx.setScope(defaultScope);
            cache.put(cacheKey, defaultScope);
            return true;
        }

        List<String> authorizedScopes = new ArrayList<String>();
        List<String> userRoleList = new ArrayList<String>(Arrays.asList(userRoles));

        //Iterate the requested scopes list.
        for (String scope : reqScopeList) {
            //Get the set of roles associated with the requested scope.
            String roles = appScopes.get(scope);
            //If the scope has been defined in the context of the App and if roles have been defined for the scope
            if (roles != null && roles.length() != 0) {
                List<String> roleList = new ArrayList<String>(
                        Arrays.asList(roles.replaceAll(" ", "").split(",")));
                //Check if user has at least one of the roles associated with the scope
                roleList.retainAll(userRoleList);
                if (!roleList.isEmpty()) {
                    authorizedScopes.add(scope);
                }
            }
            //The requested scope is defined for the context of the App but no roles have been associated with the scope
            //OR
            //The scope string starts with 'device_'.
            else if (appScopes.containsKey(scope) || scope.startsWith(DEVICE_SCOPE_PREFIX)) {
                authorizedScopes.add(scope);
            }
        }
        if (!authorizedScopes.isEmpty()) {
            String[] authScopesArr = authorizedScopes.toArray(new String[authorizedScopes.size()]);
            cache.put(cacheKey, authScopesArr);
            tokReqMsgCtx.setScope(authScopesArr);
        } else {
            cache.put(cacheKey, defaultScope);
            tokReqMsgCtx.setScope(defaultScope);
        }
    } catch (APIManagementException e) {
        log.error("Error while getting scopes of application " + e.getMessage());
        return false;
    }
    return true;
}

From source file:org.wso2.carbon.apimgt.keymgt.ScopesIssuer.java

public boolean setScopes(OAuthTokenReqMessageContext tokReqMsgCtx) {
    String[] requestedScopes = tokReqMsgCtx.getScope();
    String[] defaultScope = new String[] { DEFAULT_SCOPE_NAME };
    //If no scopes were requested.
    if (requestedScopes == null || requestedScopes.length == 0) {
        tokReqMsgCtx.setScope(defaultScope);
        return true;
    }//from   w  w w .  jav a 2  s.com

    String consumerKey = tokReqMsgCtx.getOauth2AccessTokenReqDTO().getClientId();
    String username = tokReqMsgCtx.getAuthorizedUser().getUserName();
    String endUsernameWithDomain = UserCoreUtil.addDomainToName(username,
            tokReqMsgCtx.getAuthorizedUser().getUserStoreDomain());
    List<String> reqScopeList = Arrays.asList(requestedScopes);
    Map<String, String> restAPIScopesOfCurrentTenant;
    try {
        Map<String, String> appScopes;
        ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
        //Get all the scopes and roles against the scopes defined for the APIs subscribed to the application.
        appScopes = apiMgtDAO.getScopeRolesOfApplication(consumerKey);
        //Add API Manager rest API scopes set. This list should be loaded at server start up and keep
        //in memory and add it to each and every request coming.
        String tenantDomain = tokReqMsgCtx.getAuthorizedUser().getTenantDomain();
        restAPIScopesOfCurrentTenant = (Map) Caching.getCacheManager(APIConstants.API_MANAGER_CACHE_MANAGER)
                .getCache("REST_API_SCOPE_CACHE").get(tenantDomain);
        if (restAPIScopesOfCurrentTenant != null) {
            appScopes.putAll(restAPIScopesOfCurrentTenant);
        } else {
            restAPIScopesOfCurrentTenant = APIUtil
                    .getRESTAPIScopesFromConfig(APIUtil.getTenantRESTAPIScopesConfig(tenantDomain));
            //call load tenant config for rest API.
            //then put cache
            appScopes.putAll(restAPIScopesOfCurrentTenant);
            Caching.getCacheManager(APIConstants.API_MANAGER_CACHE_MANAGER).getCache("REST_API_SCOPE_CACHE")
                    .put(tenantDomain, restAPIScopesOfCurrentTenant);
        }
        //If no scopes can be found in the context of the application
        if (appScopes.isEmpty()) {
            if (log.isDebugEnabled()) {
                log.debug("No scopes defined for the Application "
                        + tokReqMsgCtx.getOauth2AccessTokenReqDTO().getClientId());
            }

            String[] allowedScopes = getAllowedScopes(reqScopeList);
            tokReqMsgCtx.setScope(allowedScopes);
            return true;
        }

        int tenantId;
        RealmService realmService = APIKeyMgtDataHolder.getRealmService();
        UserStoreManager userStoreManager;
        String[] userRoles;

        try {
            tenantId = realmService.getTenantManager().getTenantId(tenantDomain);

            // If tenant Id is not set in the tokenReqContext, deriving it from username.
            if (tenantId == 0 || tenantId == -1) {
                tenantId = IdentityTenantUtil.getTenantIdOfUser(username);
            }
            userStoreManager = realmService.getTenantUserRealm(tenantId).getUserStoreManager();
            userRoles = userStoreManager
                    .getRoleListOfUser(MultitenantUtils.getTenantAwareUsername(endUsernameWithDomain));
        } catch (UserStoreException e) {
            //Log and return since we do not want to stop issuing the token in case of scope validation failures.
            log.error("Error when getting the tenant's UserStoreManager or when getting roles of user ", e);
            return false;
        }

        if (userRoles == null || userRoles.length == 0) {
            if (log.isDebugEnabled()) {
                log.debug("Could not find roles of the user.");
            }
            tokReqMsgCtx.setScope(defaultScope);
            return true;
        }

        List<String> authorizedScopes = new ArrayList<String>();
        List<String> userRoleList = new ArrayList<String>(Arrays.asList(userRoles));

        //Iterate the requested scopes list.
        for (String scope : reqScopeList) {
            //Get the set of roles associated with the requested scope.
            String roles = appScopes.get(scope);
            //If the scope has been defined in the context of the App and if roles have been defined for the scope
            if (roles != null && roles.length() != 0) {
                List<String> roleList = new ArrayList<String>(
                        Arrays.asList(roles.replaceAll(" ", "").split(",")));
                //Check if user has at least one of the roles associated with the scope
                roleList.retainAll(userRoleList);
                if (!roleList.isEmpty()) {
                    authorizedScopes.add(scope);
                }
            }
            // The requested scope is defined for the context of the App but no roles have been associated with the
            // scope
            // OR
            // The scope string starts with 'device_'.
            else if (appScopes.containsKey(scope) || isWhiteListedScope(scope)) {
                authorizedScopes.add(scope);
            }
        }
        if (!authorizedScopes.isEmpty()) {
            String[] authScopesArr = authorizedScopes.toArray(new String[authorizedScopes.size()]);
            tokReqMsgCtx.setScope(authScopesArr);
        } else {
            tokReqMsgCtx.setScope(defaultScope);
        }
    } catch (APIManagementException e) {
        log.error("Error while getting scopes of application " + e.getMessage(), e);
        return false;
    }
    return true;
}

From source file:org.openengsb.core.edbi.jdbc.JdbcService.java

public int[] update(Table table, List<IndexRecord> records) {
    List<String> columns = table.getColumns().getColumnNames();
    String whereClause = makeWhereClause(table.getPrimaryKey());

    // FIXME: find an elegant solution for a dynamic SET clause within an UPDATE statement for batch updates
    // either column exclusions or find subsets of columns within the list of IndexRecords
    IndexRecord record = records.get(0);
    columns.retainAll(record.getValues().keySet());

    return update(table.getName(), columns, whereClause, toParameterSourceArray(records));
}

From source file:org.wso2.emm.agent.services.PolicyComplianceChecker.java

/**
 * Check the app restriction policy (black list or white list) for compliance
  *//from  www  .  j a v  a2s . c o  m
  * @param operation - Operation object
  * @return - Compliance feature object
  * @throws AndroidAgentException
  */

private ComplianceFeature checkAppRestrictionPolicy(org.wso2.emm.agent.beans.Operation operation)
        throws AndroidAgentException {

    AppRestriction appRestriction = CommonUtils.getAppRestrictionTypeAndList(operation, null, null);

    List<String> installedAppPackages = CommonUtils.getInstalledAppPackages(context);

    String ownershipType = Preference.getString(context, Constants.DEVICE_TYPE);

    if (Constants.OWNERSHIP_COPE.equals(ownershipType)) {

        if (Constants.AppRestriction.BLACK_LIST.equals(appRestriction.getRestrictionType())) {
            List<String> commonApps = new ArrayList<>(installedAppPackages);
            if (commonApps.retainAll(appRestriction.getRestrictedList())) {
                if (commonApps.size() > 0) {
                    policy.setCompliance(false);
                    policy.setMessage(commonApps.toString());
                    return policy;
                }
            }
        } else if (Constants.AppRestriction.WHITE_LIST.equals(appRestriction.getRestrictionType())) {
            List<String> installedAppPackagesByUser = CommonUtils.getInstalledAppPackagesByUser(context);
            List<String> remainApps = new ArrayList<>(installedAppPackagesByUser);
            remainApps.remove(Constants.AGENT_PACKAGE);
            remainApps.remove(Constants.SYSTEM_SERVICE_PACKAGE);
            remainApps.removeAll(appRestriction.getRestrictedList());
            if (remainApps.size() > 0) {
                policy.setCompliance(false);
                policy.setMessage(remainApps.toString());
                return policy;
            }
        }

        policy.setCompliance(true);
        return policy;

    } else if (Constants.OWNERSHIP_BYOD.equals(ownershipType)) {
        if (Constants.AppRestriction.BLACK_LIST.equals(appRestriction.getRestrictionType())) {
            List<String> commonApps = new ArrayList<>(installedAppPackages);
            if (commonApps.retainAll(appRestriction.getRestrictedList())) {
                if (commonApps.size() > 0) {
                    policy.setCompliance(false);
                    return policy;
                }
            }
        } else if (Constants.AppRestriction.WHITE_LIST.equals(appRestriction.getRestrictionType())) {
            List<String> remainApps = new ArrayList<>(installedAppPackages);
            remainApps.removeAll(appRestriction.getRestrictedList());
            if (remainApps.size() > 0) {
                policy.setCompliance(false);
                return policy;
            }
        }
        policy.setCompliance(true);
        return policy;

    }
    policy.setCompliance(true);
    return policy;
}

From source file:pcgen.cdom.facet.analysis.ChallengeRatingFacet.java

private Float calcClassesForRaceCR(CharID id) {
    Float CR = new Float(0);
    int levelsKey = 0;
    int levelsNonKey = 0;
    int levelsConverted = 0;
    int threshold = 0;

    List<String> raceRoleList = raceFacet.get(id).getListFor(ListKey.MONSTER_ROLES);
    if (raceRoleList == null || raceRoleList.isEmpty()) {
        raceRoleList = SettingsHandler.getGame().getMonsterRoleDefaultList();
    }//from w  ww . j  a v a  2s.c  o  m

    // Calculate and add the CR from the PC Classes
    for (PCClass pcClass : classFacet.getClassSet(id)) {
        Float levels = calcClassCR(id, pcClass);
        if (levels.isNaN()) {
            return Float.NaN;
        }

        List<String> classRoleList = pcClass.getListFor(ListKey.MONSTER_ROLES);
        if (classRoleList != null) {
            classRoleList.retainAll(raceRoleList);
            if (classRoleList.size() > 0) {
                levelsKey += (int) levels.floatValue();
            } else {
                levelsNonKey += (int) levels.floatValue();
            }
        } else {
            if (raceRoleList != null) {
                levelsNonKey += (int) levels.floatValue();
            } else {
                levelsKey += (int) levels.floatValue();
            }
        }

    }
    String sThreshold = SettingsHandler.getGame().getCRThreshold();
    if (sThreshold != null) {
        threshold = formulaResolvingFacet.resolve(id, FormulaFactory.getFormulaFor(sThreshold), "").intValue();
    }

    while (levelsNonKey > 1) {
        CR++;
        // TODO: maybe the divisor 2 should be be made configurable, 
        // or the whole calculation put into a formula
        levelsNonKey -= 2;
        levelsConverted += 2;
        if (levelsConverted >= threshold) {
            break;
        }
    }
    if (levelsConverted > 0) {
        CR += levelsNonKey;
    }
    CR += levelsKey;

    return CR;
}

From source file:org.obiba.mica.search.JoinQueryExecutor.java

private List<String> queryStudyIds(List<DocumentQueryInterface> queries) {
    List<String> studyIds = queries.get(0).queryStudyIds();

    queries.stream().skip(1).forEach(query -> {
        if (studyIds.size() > 0) {
            studyIds.retainAll(query.queryStudyIds());
        }/*from w ww. j a  va 2s.co m*/
    });

    return studyIds;
}