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.hp.mqm.atrf.alm.services.AlmWrapperService.java

private Set<String> getIdsNotIncludedInSet(Collection<? extends AlmEntity> entities, String keyFieldName,
        Collection<String> ids) {
    Set<String> notIncludedIds = new HashSet<>();
    for (AlmEntity entity : entities) {
        String id = entity.getString(keyFieldName);
        if (StringUtils.isNotEmpty(id) && !ids.contains(id)) {
            notIncludedIds.add(id);/*w w w.  jav  a  2 s . c  o m*/
        }
    }
    return notIncludedIds;
}

From source file:org.jasig.cas.ticket.registry.AbstractTicketRegistryTests.java

@Test
public void testGetTicketsFromRegistryEqualToTicketsAdded() {
    final Collection<Ticket> tickets = new ArrayList<Ticket>();

    for (int i = 0; i < TICKETS_IN_REGISTRY; i++) {
        final TicketGrantingTicket ticketGrantingTicket = new TicketGrantingTicketImpl("TEST" + i,
                getAuthentication(), new NeverExpiresExpirationPolicy());
        final ServiceTicket st = ticketGrantingTicket.grantServiceTicket("tests" + i, getService(),
                new NeverExpiresExpirationPolicy(), false);
        tickets.add(ticketGrantingTicket);
        tickets.add(st);//  www  . j  a v a2s  .c o m
        this.ticketRegistry.addTicket(ticketGrantingTicket);
        this.ticketRegistry.addTicket(st);
    }

    try {
        Collection<Ticket> ticketRegistryTickets = this.ticketRegistry.getTickets();
        assertEquals("The size of the registry is not the same as the collection.",
                ticketRegistryTickets.size(), tickets.size());

        for (final Ticket ticket : tickets) {
            if (!ticketRegistryTickets.contains(ticket)) {
                fail("Ticket was added to registry but was not found in retrieval of collection of all tickets.");
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        fail("Caught an exception. But no exception should have been thrown.");
    }
}

From source file:org.xeneo.db.JdbcTaskContextManager.java

public Map<String, Collection<String>> getTaskContexts(String activityURI) {
    Map<String, Collection<String>> response = new HashMap<String, Collection<String>>();

    List<Map<String, java.lang.Object>> result = jdbcTemplate.queryForList(TASK_CONTEXT_BY_ACTIVITY,
            activityURI);/*  w  w  w.j av  a2s.  c  om*/
    if (!result.isEmpty()) {
        Iterator<Map<String, java.lang.Object>> it = result.iterator();
        Map<String, java.lang.Object> map;
        String caseURI, taskURI;
        Collection<String> tasks;
        while (it.hasNext()) {
            map = it.next();
            if (map.containsKey("CaseURI") && map.containsKey("TaskURI")) {
                caseURI = (String) map.get("CaseURI");
                taskURI = (String) map.get("TaskURI");
                if (response.containsKey(caseURI)) {
                    tasks = response.get(caseURI);
                    if (!tasks.contains(taskURI)) {
                        tasks.add(taskURI);
                        response.put(caseURI, tasks);
                    }
                } else {
                    tasks = new ArrayList<String>();
                    tasks.add(taskURI);
                    response.put(caseURI, tasks);
                }
            }
        }
    }

    return response;
}

From source file:edu.ksu.cis.indus.staticanalyses.callgraphs.CallInfo.java

/**
 * Validates the information. This is designed to be used inside an assertion.
 * //from  w  w w. j a  va 2s.c o m
 * @return <code>true</code> if the info is valid. An assertion violation is raised otherwise.
 */
private boolean validate() {
    final Collection<SootMethod> _k1 = caller2callees.keySet();
    for (final Iterator<Collection<CallTriple>> _i = callee2callers.values().iterator(); _i.hasNext();) {
        final Collection<CallTriple> _c = _i.next();
        for (final Iterator<CallTriple> _j = _c.iterator(); _j.hasNext();) {
            final CallTriple _ctrp = _j.next();
            assert _k1.contains(_ctrp.getMethod());
        }
    }

    final Collection<SootMethod> _k2 = callee2callers.keySet();
    for (final Iterator<Collection<CallTriple>> _i = caller2callees.values().iterator(); _i.hasNext();) {
        final Collection<CallTriple> _c = _i.next();
        for (final Iterator<CallTriple> _j = _c.iterator(); _j.hasNext();) {
            final CallTriple _ctrp = _j.next();
            assert _k2.contains(_ctrp.getMethod());
        }
    }

    assert _k1.containsAll(reachables) : SetUtils.difference(reachables, _k1);
    assert _k2.containsAll(reachables) : SetUtils.difference(reachables, _k2);
    assert reachables.containsAll(_k1) : SetUtils.difference(_k1, reachables);
    assert reachables.containsAll(_k2) : SetUtils.difference(_k2, reachables);

    return true;
}

From source file:org.jdal.vaadin.ui.table.ConfigurableTable.java

@Override
public void setContainerDataSource(Container newDataSource, Collection<?> visibleIds) {
    if (visibleIds != null && visibleIds.size() > 0) {
        for (String id : properties) {
            if (PropertyUtils.isNested(id)) {
                addNestedPropertyIfPossible(newDataSource, id);
            }/*from  w w  w  .j  av  a  2 s  .  c om*/

            if (!visibleIds.contains(id) && !PropertyUtils.isNested(id)) {
                throw new IllegalStateException("Unknown property [" + id + "]");
            }
        }
    }
    super.setContainerDataSource(newDataSource, properties);
}

From source file:com.auditbucket.registration.bean.TagInputBean.java

public TagInputBean setTargets(String relationshipName, Collection<TagInputBean> fromThoseTags) {
    Collection<TagInputBean> theseTags = targets.get(relationshipName);
    if (theseTags == null)
        targets.put(relationshipName, fromThoseTags);
    else {//from ww  w  .j a v  a 2 s.  c om
        for (TagInputBean tagToAdd : fromThoseTags) {
            if (!theseTags.contains(tagToAdd))
                theseTags.add(tagToAdd);
        }
    }
    return this;

}

From source file:nu.localhost.tapestry5.springsecurity.components.IfRole.java

/**
 * Find the common authorities between the current authentication's {@link
 * GrantedAuthority} and the ones that have been specified in the tag's
 * ifAny, ifNot or ifAllGranted attributes.
 * /* w  w  w .j  av a  2 s .  c o m*/
 * <p>
 * We need to manually iterate over both collections, because the granted
 * authorities might not implement {@link Object#equals(Object)} and
 * {@link Object#hashCode()} in the same way as {@link
 * GrantedAuthority}, thereby invalidating {@link
 * Collection#retainAll(java.util.Collection)} results.
 * </p>
 * 
 * <p>
 * <strong>CAVEAT</strong>: This method <strong>will not</strong> work if
 * the granted authorities returns a <code>null</code> string as the
 * return value of {@link
 * org.springframework.security.GrantedAuthority#getAuthority()}.
 * </p>
 * 
 * <p>
 * Reported by rawdave, on Fri Feb 04, 2005 2:11 pm in the Spring Security
 * System for Spring forums.
 * </p>
 * 
 * @param granted
 *            The authorities granted by the authentication. May be any
 *            implementation of {@link GrantedAuthority} that does
 *            <strong>not</strong> return <code>null</code> from {@link
 *            org.springframework.security.GrantedAuthority#getAuthority()}.
 * @param required
 *            A {@link Set} of {@link GrantedAuthority}s that have been
 *            built using ifAny, ifAll or ifNotGranted.
 * 
 * @return A set containing only the common authorities between <var>granted</var>
 *         and <var>required</var>.
 * 
 */

private Collection<GrantedAuthority> retainAll(final Collection<GrantedAuthority> granted,
        final Collection<GrantedAuthority> required) {
    Collection<GrantedAuthority> grantedRoles = authoritiesToRoles(granted);
    Collection<GrantedAuthority> requiredRoles = authoritiesToRoles(required);
    ArrayList<GrantedAuthority> intersection = new ArrayList<GrantedAuthority>();
    for (GrantedAuthority requiredAuthory : requiredRoles) {
        if (grantedRoles.contains(requiredAuthory)) {
            intersection.add(requiredAuthory);
        } else {
        }
    }

    return intersection;
}

From source file:ddf.catalog.data.dynamic.impl.DynamicMetacardImplTest.java

@Test
public void testAddAttribute() throws Exception {
    Attribute attribute = null;// ww w  .ja v  a 2s.  co m
    metacard.addAttribute(STRING, "123");
    assertEquals("123", baseBean.get(STRING));

    // replace the existing value for single-valued attributes
    metacard.addAttribute(STRING, "234");
    assertEquals("234", baseBean.get(STRING));

    // add a single value to an empty list
    metacard.addAttribute(STRING_LIST, "123");
    List<Serializable> list = new ArrayList<>();
    list.add("123");
    assertEquals(list, baseBean.get(STRING_LIST));

    // adds a value to the existing list
    metacard.addAttribute(STRING_LIST, "234");
    Collection c = (Collection) baseBean.get(STRING_LIST);
    assertEquals(2, c.size());
    assertTrue(c.contains("123"));
    assertTrue(c.contains("234"));

    // adding a list adds all values to the existing list
    list.clear();
    list.add("345");
    list.add("456");
    metacard.addAttribute(STRING_LIST, list);
    c = (Collection) baseBean.get(STRING_LIST);
    assertEquals(4, c.size());
    assertTrue(c.contains("123"));
    assertTrue(c.contains("234"));
    assertTrue(c.contains("345"));
    assertTrue(c.contains("456"));
}

From source file:de.hybris.platform.servicelayer.media.impl.DefaultMediaPermissionServiceIntegrationTest.java

/**
 * Test method for//from   w  w w  .  ja v a  2s .  com
 * {@link de.hybris.platform.servicelayer.media.impl.DefaultMediaPermissionService#setPermittedPrincipals(MediaModel, Collection)}
 * .
 */
@Test
public void testSetPermittedPrincipals() {
    Collection<PrincipalModel> permittedPrincipals = mediaPermissionService
            .getPermittedPrincipals(testMediaItem);
    Assert.assertTrue(permittedPrincipals.size() == 1);
    Assert.assertTrue(permittedPrincipals.contains(userService.getCurrentUser()));

    //create new user and assign proper permission
    final UserModel testUser = modelService.create(UserModel.class);
    testUser.setUid("testGroup");
    testUser.setName("Testgroup");
    modelService.save(testUser);

    final Collection<PrincipalModel> principalsToBeSet = new HashSet<PrincipalModel>();
    principalsToBeSet.add(userService.getCurrentUser());
    principalsToBeSet.add(testUser);

    //update the permitted principals list. Expected result - 2 assigned principals
    mediaPermissionService.setPermittedPrincipals(testMediaItem, principalsToBeSet);

    permittedPrincipals = mediaPermissionService.getPermittedPrincipals(testMediaItem);
    Assert.assertTrue(permittedPrincipals.size() == 2);
    Assert.assertTrue(permittedPrincipals.contains(userService.getCurrentUser()));
    Assert.assertTrue(permittedPrincipals.contains(testUser));

    principalsToBeSet.clear();
    //update the permitted principals list. Expected result - empty list (no assigned principals)
    mediaPermissionService.setPermittedPrincipals(testMediaItem, principalsToBeSet);

    permittedPrincipals = mediaPermissionService.getPermittedPrincipals(testMediaItem);
    Assert.assertTrue(CollectionUtils.isEmpty(permittedPrincipals));
}