Example usage for java.util Collection contains

List of usage examples for java.util Collection contains

Introduction

In this page you can find the example usage for java.util Collection contains.

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this collection contains the specified element.

Usage

From source file:com.ctc.storefront.filters.cms.CMSSiteFilter.java

/**
 * Filters the preview language to a language supported by the site. If the requested preview language is not
 * supported, returns the default site language instead.
 *
 * @param httpRequest/*from  w ww  .  j  a  v  a2 s .  c o m*/
 *           current request
 * @param previewDataModel
 *           the preview data model
 * @return LanguageModel the filtered language for previewing
 */
protected LanguageModel filterPreviewLanguageForSite(final HttpServletRequest httpRequest,
        final PreviewDataModel previewDataModel) {
    final BaseSiteModel previewSite = previewDataModel.getActiveSite() == null ? getCurrentCmsSite()
            : previewDataModel.getActiveSite();
    getBaseSiteService().setCurrentBaseSite(previewSite, false);
    final Collection<LanguageModel> siteLanguages = getCommerceCommonI18NService().getAllLanguages();
    if (siteLanguages.contains(previewDataModel.getLanguage())) {
        // The preview language is supported
        return previewDataModel.getLanguage();
    }
    return getCommerceCommonI18NService().getDefaultLanguage();
}

From source file:com.jkoolcloud.tnt4j.streams.parsers.AbstractSyslogParser.java

@SuppressWarnings("unchecked")
private void updateDigest(MessageDigest digest, Map<String, Object> logDataMap,
        Collection<String> ignoredFields, String keyPrefix) {
    for (Map.Entry<String, Object> ldme : logDataMap.entrySet()) {
        String fKey = keyPrefix + ldme.getKey();

        if (ignoredFields != null && ignoredFields.contains(fKey)) {
            continue;
        }//  w ww .j a v a  2s  .c o m

        if (ldme.getValue() instanceof Map) {
            updateDigest(digest, (Map<String, Object>) ldme.getValue(), ignoredFields, fKey + nodePathDelim);
        } else {
            digest.update(Utils.toString(ldme.getValue()).getBytes());
        }
    }
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.department.ReadPersonProfessorshipsByExecutionYearAction.java

private void prepareConstants(User userView, InfoPerson infoPerson, HttpServletRequest request)
        throws FenixServiceException {

    List executionYears = ReadNotClosedExecutionYears.run();

    InfoExecutionYear infoExecutionYear = (InfoExecutionYear) CollectionUtils.find(executionYears,
            new Predicate() {
                @Override/*from   w w  w  .  j  av  a2s.  c  o m*/
                public boolean evaluate(Object arg0) {
                    InfoExecutionYear infoExecutionYearElem = (InfoExecutionYear) arg0;
                    if (infoExecutionYearElem.getState().equals(PeriodState.CURRENT)) {
                        return true;
                    }
                    return false;
                }
            });
    Person person = (Person) FenixFramework.getDomainObject(infoPerson.getExternalId());
    InfoDepartment teacherDepartment = null;
    if (person.getTeacher() != null) {
        Department department = person.getTeacher().getCurrentWorkingDepartment();
        teacherDepartment = InfoDepartment.newInfoFromDomain(department);
        if (userView == null || !userView.getPerson().hasRole(RoleType.CREDITS_MANAGER)) {
            final Collection<Department> departmentList = userView.getPerson()
                    .getManageableDepartmentCreditsSet();
            request.setAttribute("isDepartmentManager",
                    (departmentList.contains(department) || department == null));
        } else {
            request.setAttribute("isDepartmentManager", Boolean.FALSE);
        }
    } else {
        request.setAttribute("isDepartmentManager", Boolean.TRUE);
    }

    request.setAttribute("teacherDepartment", teacherDepartment);
    request.setAttribute("executionYear", infoExecutionYear);
    request.setAttribute("executionYears", executionYears);
}

From source file:edu.northwestern.bioinformatics.studycalendar.osgi.felixcm.internal.PscFelixPersistenceManager.java

@SuppressWarnings({ "unchecked" })
private void doStore(String pid, Dictionary values) {
    List<OsgiConfigurationProperty> existingProperties = getProperties(pid);
    Collection<String> newKeys = EnumerationUtils.toList(values.keys());
    Collection<String> existingKeys = new HashSet<String>();
    for (OsgiConfigurationProperty existingProperty : existingProperties) {
        String existingKey = existingProperty.getName();
        if (newKeys.contains(existingKey)) {
            existingProperty.setValue(values.get(existingKey));
            existingKeys.add(existingKey);
        } else {/*from   w w  w  . j  av a2s  .co m*/
            getHibernateTemplate().delete(existingProperty);
        }
    }
    for (String newKey : newKeys) {
        if (!EXCLUDED_PROPERTIES.contains(newKey) && !existingKeys.contains(newKey)) {
            getHibernateTemplate().save(OsgiConfigurationProperty.create(pid, newKey, values.get(newKey)));
        }
    }
}

From source file:de.tolina.common.validation.AnnotationValidation.java

private void addIfNotPresent(@Nonnull final Collection<Annotation> collection,
        @Nonnull final Annotation[] annotations) {
    for (final Annotation annotation : annotations) {
        if (!collection.contains(annotation)) {
            collection.add(annotation);//from  w  ww.  j a v a  2 s  .  c o  m
        }
    }
}

From source file:eu.dime.ps.semantic.privacy.PrivacyPreferenceServiceTest.java

@Test
public void testgetIncludesBySharedThrough() throws Exception {
    Agent simon = modelFactory.getPIMOFactory().createAgent();
    Account account = buildAccount();//www.ja  v  a2 s  . co m
    PrivacyPreference databox = manager.getOrCreate("business", PrivacyPreferenceType.DATABOX);
    manager.grantAccess(databox, account.asURI(), simon);

    // reload
    databox = manager.getOrCreate("business", PrivacyPreferenceType.DATABOX);
    Collection<Agent> includes = manager.getIncludesBySharedThrough(databox, account.toString());
    assertNotNull(includes);
    assertTrue(includes.contains(simon));

}

From source file:org.trpr.platform.batch.impl.job.ha.service.CuratorJobSyncHandler.java

/**
 * This method updates the list of servers in the jobConfigurationService.
 *//* w  ww . j  a  v  a 2  s .c om*/
public void updateHosts() {
    LOGGER.info("Updating list of servers");
    this.jobConfigurationService.clearJobInstances();
    try {
        //Get all the registered services in Zookeeper
        Collection<String> serviceNames = serviceDiscovery.queryForNames();
        //Remove any service not found in ZK
        for (String serviceName : this.serviceCacheMap.keySet()) {
            if (!serviceNames.contains(serviceName)) {
                this.serviceCacheMap.get(serviceName).close();
                this.serviceCacheMap.remove(serviceName);
            }
        }
        //Loop over all serviceNames and build the info in jobConfigurationService
        for (String serviceName : serviceNames) {
            //Add listeners and cache to all the services, if not added
            if (!this.serviceCacheMap.containsKey(serviceName)) { //Service cache doesn't have this job
                ServiceCache<JobInstanceDetails> sc = this.serviceDiscovery.serviceCacheBuilder()
                        .name(serviceName).build();
                sc.start();
                sc.addListener(new ServiceListner());
                this.serviceCacheMap.put(serviceName, sc);
                LOGGER.info("Job: " + serviceName + "'s Cache listener removed.");
            }
            //Add all the hosts in the service to jobConfigService
            Collection<ServiceInstance<JobInstanceDetails>> instances = this.serviceCacheMap.get(serviceName)
                    .getInstances();
            for (ServiceInstance<JobInstanceDetails> instance : instances) {
                JobHost instHost = new JobHost(instance.getPayload().getHostName(), instance.getAddress(),
                        instance.getPort());
                this.jobConfigurationService.addJobInstance(serviceName, instHost);
            }
        }
    } catch (Exception e) {
        LOGGER.error("Error while updating server list", e);
    }
}

From source file:forge.game.mana.ManaPool.java

public boolean accountFor(final AbilityManaPart ma) {
    if (ma == null) {
        return false;
    }/* ww  w  . j  a v a 2s .co  m*/
    if (floatingMana.isEmpty()) {
        return false;
    }

    final List<Mana> removeFloating = new ArrayList<Mana>();

    boolean manaNotAccountedFor = false;
    // loop over mana produced by mana ability
    for (Mana mana : ma.getLastManaProduced()) {
        Collection<Mana> poolLane = floatingMana.get(mana.getColor());

        if (poolLane != null && poolLane.contains(mana)) {
            removeFloating.add(mana);
        } else {
            manaNotAccountedFor = true;
            break;
        }
    }

    // When is it legitimate for all the mana not to be accountable?
    // Does this condition really indicate an bug in Forge?
    if (manaNotAccountedFor) {
        return false;
    }

    for (int k = 0; k < removeFloating.size(); k++) {
        removeMana(removeFloating.get(k));
    }
    return true;
}

From source file:com.glaf.core.security.LoginContext.java

public boolean hasAdvancedPermission() {
    boolean hasPermission = false;
    Collection<Long> roles = this.getRoleIds();
    if (roles != null) {
        if (roles.contains(10000L)) {
            hasPermission = true;//from  w ww .  j  av a 2  s.c o  m
        }
    }
    return hasPermission;
}

From source file:com.glaf.activiti.executionlistener.UserTaskExecutionListener.java

@Override
public void notify(DelegateExecution execution) {
    logger.debug("----------------------------------------------------");
    logger.debug("-----------------UserTaskExecutionListener----------");
    logger.debug("----------------------------------------------------");

    CommandContext commandContext = Context.getCommandContext();

    logger.debug("dbSqlsession:" + commandContext.getDbSqlSession());
    logger.debug("sqlsession:" + commandContext.getDbSqlSession().getSqlSession());

    if (execution != null && outputVar != null) {
        Map<String, Object> paramMap = new java.util.HashMap<String, Object>();
        paramMap.putAll(execution.getVariables());

        String statement = "getMembershipUsers";

        String output = (String) outputVar.getValue(execution);

        if (statementId != null && statementId.getExpressionText() != null) {
            statement = statementId.getExpressionText();
            logger.debug("statementId:" + statement);
        }//from  w w w . ja v a 2s.co  m

        if (roleId != null && roleId.getExpressionText() != null) {
            logger.debug("roleId:" + roleId.getExpressionText());
            paramMap.put("roleId", roleId.getExpressionText());
        }

        if (StringUtils.isNotEmpty(statement)) {
            MyBatisEntityDAO entityDAO = new MyBatisEntityDAO(commandContext.getDbSqlSession().getSqlSession());
            List<?> list = entityDAO.getList(statement, paramMap);
            if (list != null && !list.isEmpty()) {
                Collection<String> users = new java.util.HashSet<String>();

                for (Object object : list) {
                    if (object instanceof org.activiti.engine.identity.User) {
                        String actorId = ((org.activiti.engine.identity.User) object).getId();
                        if (!users.contains(actorId)) {
                            users.add(actorId);
                        }
                    } else if (object instanceof com.glaf.core.identity.User) {
                        String actorId = ((com.glaf.core.identity.User) object).getActorId();
                        if (!users.contains(actorId)) {
                            users.add(actorId);
                        }
                    }
                }

                logger.debug("users:" + users);

                if (users.size() > 0) {
                    execution.setVariable(output, users);
                }

            } else {
                String expr = (String) expression.getValue(execution);
                if (expr != null) {
                    if (expr.startsWith("user(") && expr.endsWith("")) {
                        expr = StringTools.replaceIgnoreCase(expr, "user(", "");
                        expr = StringTools.replaceIgnoreCase(expr, ")", "");
                        execution.setVariable(output, expr);
                    } else if (expr.startsWith("users(") && expr.endsWith("")) {
                        expr = StringTools.replaceIgnoreCase(expr, "users(", "");
                        expr = StringTools.replaceIgnoreCase(expr, ")", "");
                        List<String> candidateUsers = StringTools.split(expr, ",");
                        execution.setVariable(output, candidateUsers);
                    }
                }
            }
        }
    }
}