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:net.sourceforge.fenixedu.presentationTier.Action.department.ReadTeacherProfessorshipsByExecutionYearAction.java

private void prepareConstants(User userView, InfoTeacher infoTeacher, HttpServletRequest request)
        throws FenixServiceException {

    List executionYears = ReadNotClosedExecutionYears.run();

    InfoExecutionYear infoExecutionYear = (InfoExecutionYear) CollectionUtils.find(executionYears,
            new Predicate() {
                @Override/*w  ww  .j  a va  2s . c  om*/
                public boolean evaluate(Object arg0) {
                    InfoExecutionYear infoExecutionYearElem = (InfoExecutionYear) arg0;
                    if (infoExecutionYearElem.getState().equals(PeriodState.CURRENT)) {
                        return true;
                    }
                    return false;
                }
            });

    Department department = infoTeacher.getTeacher().getCurrentWorkingDepartment();
    InfoDepartment teacherDepartment = InfoDepartment.newInfoFromDomain(department);

    if (userView == null || !userView.getPerson().hasRole(RoleType.CREDITS_MANAGER)) {

        final Collection<Department> departmentList = userView.getPerson().getManageableDepartmentCreditsSet();
        request.setAttribute("isDepartmentManager", Boolean.valueOf(departmentList.contains(department)));

    } else {
        request.setAttribute("isDepartmentManager", Boolean.FALSE);
    }

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

From source file:net.solarnetwork.util.DynamicServiceTracker.java

private boolean serviceMatchesFilters(Object service) {
    if (service == null) {
        return false;
    }/*from ww w.j  a  v  a  2  s.  c  om*/
    if (propertyFilters == null || propertyFilters.size() < 1) {
        log.debug("No property filter configured, {} service matches", serviceClassName);
        return true;
    }
    log.trace("Examining service {} for property match {}", service, propertyFilters);
    PropertyAccessor accessor = PropertyAccessorFactory.forBeanPropertyAccess(service);
    for (Map.Entry<String, Object> me : propertyFilters.entrySet()) {
        if (accessor.isReadableProperty(me.getKey())) {
            Object requiredValue = me.getValue();
            if (ignoreEmptyPropertyFilterValues && (requiredValue == null
                    || ((requiredValue instanceof String) && ((String) requiredValue).length() == 0))) {
                // ignore empty filter values, so this is a matching property... skip to the next filter
                continue;
            }
            Object serviceValue = accessor.getPropertyValue(me.getKey());
            if (requiredValue == null) {
                if (serviceValue == null) {
                    continue;
                }
                return false;
            }
            if (serviceValue instanceof Collection<?>) {
                // for collections, we test for containment
                Collection<?> collection = (Collection<?>) serviceValue;
                if (!collection.contains(requiredValue)) {
                    return false;
                }
            } else if (!requiredValue.equals(serviceValue)) {
                return false;
            }
        } else {
            return false;
        }
    }
    return true;
}

From source file:org.esco.portlet.changeetab.mvc.controller.ChangeEtablissementController.java

@ActionMapping("changeEtab")
public void changeEtab(@ModelAttribute("command") final ChangeEtabCommand changeEtabCommand,
        final ActionRequest request, final ActionResponse response) throws Exception {
    final String selectedEtabCode = changeEtabCommand.getSelectedEtabCode();
    Assert.hasText(selectedEtabCode, "No Etablissement code selected !");

    ChangeEtablissementController.LOG.debug("Selected Etab code to change: [{}]", selectedEtabCode);

    final Collection<String> changeableEtabCodes = this.userInfoService.getChangeableEtabCodes(request);
    if (!changeableEtabCodes.contains(selectedEtabCode)) {
        // If selected Id is not an allowed Id
        ChangeEtablissementController.LOG
                .warn("Attempt to switch to a not allowed Etablissement with code: [{}] !", selectedEtabCode);
        ChangeEtablissementController.LOG.debug("Allowed Etablissements are: [{}]",
                StringUtils.collectionToCommaDelimitedString(changeableEtabCodes));
    } else {/* w ww. j a  v  a  2  s . co  m*/
        // Process the etablissement swap.
        final String userId = this.userInfoService.getUserId(request);
        if (StringUtils.hasText(userId)) {
            final Etablissement selectedEtab = this.etablissementService
                    .retrieveEtablissementsByCode(selectedEtabCode);
            this.userService.changeCurrentEtablissement(userId, selectedEtab);

            if (this.redirectAfterChange) {
                request.getPortalContext();
                response.sendRedirect(this.logoutUrlRedirect);
            }
        } else {
            ChangeEtablissementController.LOG
                    .warn("No user Id found in request ! Cannot process the etablishment swapping !");
        }
    }

    changeEtabCommand.reset();
}

From source file:com.auditbucket.engine.service.TagTrackService.java

private void removeUnusedTagRelationships(MetaHeader ah, Iterable<TrackTag> existingTags,
        Collection<TrackTag> newTags) throws DatagioException {
    Collection<TrackTag> deleteMe = new ArrayList<>();
    for (TrackTag tag : existingTags) {
        if (!newTags.contains(tag))
            deleteMe.add(tag);//from w  w w  .j  av  a 2s.co m
    }
    trackTagDao.deleteAuditTags(ah, deleteMe);

}

From source file:org.echocat.jomon.maven.OverwriteWithMavenResourcesClassLoader.java

protected void enrichWithAllModulesRecursively(@Nonnull Collection<MavenProjectWithModules> what,
        @Nonnull MavenProjectWithModules withProject) throws Exception {
    if (!what.contains(withProject)) {
        what.add(withProject);//from w w  w  . java2 s.  co  m
        final Collection<MavenProjectWithModules> modules = withProject.getModules();
        if (modules != null) {
            for (final MavenProjectWithModules module : modules) {
                enrichWithAllModulesRecursively(what, module);
            }
        }
    }
}

From source file:SoftSet.java

public boolean retainAll(Collection c) {
    Iterator iter = iterator();//from  ww w  .  j  a v  a 2 s.  c om
    boolean removed = false;
    while (iter.hasNext()) {
        Object value = iter.next();
        if (c.contains(value) == false) {
            iter.remove();
            removed = true;
        }
    }
    return removed;
}

From source file:org.grails.datastore.mapping.model.config.DefaultMappingConfigurationStrategy.java

private boolean isExcludedProperty(String propertyName, ClassMapping classMapping, Collection transients) {
    IdentityMapping id = classMapping != null ? classMapping.getIdentifier() : null;
    return id != null && id.getIdentifierName()[0].equals(propertyName)
            || EXCLUDED_PROPERTIES.contains(propertyName) || transients.contains(propertyName);
}

From source file:eu.dime.ps.semantic.query.BasicQueryTest.java

@Test
public void testQueryIds() {
    tripleStore.addStatement(null, new URIImpl("urn:person1"), RDF.type, PIMO.Person);
    tripleStore.addStatement(null, new URIImpl("urn:person2"), RDF.type, PIMO.Person);
    tripleStore.addStatement(null, new URIImpl("urn:person3"), RDF.type, PIMO.Person);

    Collection<org.ontoware.rdf2go.model.node.Resource> ids = resourceStore.find(Person.class).ids();
    assertTrue(ids.contains(new URIImpl("urn:person1")));
    assertTrue(ids.contains(new URIImpl("urn:person2")));
    assertTrue(ids.contains(new URIImpl("urn:person3")));
}

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

/**
 * Registers a job(service) to zookeeper (Curator) and adds a listener to its cache change
 * Method is synchronized because jobConfigService is being updated (Parallel updates may lead to problems)
 * @param jobName Name of the job//  w  w  w .  ja  v  a  2  s  . c o m
 */
public synchronized void addJobInstance(String jobName) {
    //Register the job to ZK
    //Get current host attributes
    JobHost currentHost = this.jobConfigurationService.getCurrentHostName();
    try {
        //First Check if job is already registered in ZooKeeper (Curator)
        boolean isRegistered = false;

        LOGGER.info("Querying zookepper to see if already there is an entry ");
        //NOTE: This might not send cache changed in case job is redeployed on a jobHost
        Collection<String> serviceNames = this.serviceDiscovery.queryForNames();
        if (serviceNames.contains(jobName)) {
            for (ServiceInstance<JobInstanceDetails> serviceInstance : this.serviceDiscovery
                    .queryForInstances(jobName)) {
                if (serviceInstance.getAddress().equals(currentHost.getIP())) {
                    if (serviceInstance.getPort() == currentHost.getPort()) {
                        isRegistered = true;
                        break;
                    }
                }
            }
        }
        if (isRegistered == false) {
            //Register current job to current server
            this.serviceDiscovery.registerService(ServiceInstance.<JobInstanceDetails>builder().name(jobName)
                    .address(currentHost.getIP()).port(currentHost.getPort())
                    .payload(new JobInstanceDetails(currentHost.getHostName())).build());
            LOGGER.info("Registering " + jobName + " to " + currentHost.getAddress());
        }
        //Adding the listeners
        if (!this.serviceCacheMap.containsKey(jobName)) { //Service cache doesn't have this job
            ServiceCache<JobInstanceDetails> sc = this.serviceDiscovery.serviceCacheBuilder().name(jobName)
                    .build();
            sc.addListener(new ServiceListner());
            sc.start();
            this.serviceCacheMap.put(jobName, sc);
        }
        LOGGER.info("Added listener");
    } catch (Exception e) {
        LOGGER.error("Exception while adding job instance", e);
    }
    //Just in case. Because listener is added after registering, it may not activate
    this.updateHosts();
}

From source file:org.socialsignin.springsocial.security.signin.SpringSocialSecurityAuthenticationFactory.java

private Collection<? extends GrantedAuthority> addAuthorities(Authentication authentication,
        Collection<GrantedAuthority> newAuthorities) {
    Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
    authorities.addAll(authentication.getAuthorities());
    if (newAuthorities != null) {
        for (GrantedAuthority newAuthority : newAuthorities) {
            if (!authorities.contains(newAuthority)) {
                authorities.add(newAuthority);
            }//w  w  w  .  ja v  a  2 s .  com
        }
    }

    return authorities;
}