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:org.powertac.common.repo.CustomerRepoTests.java

@Test
public void testAddList() {
    CustomerInfo c1 = new CustomerInfo("Podunk", 42);
    repo.add(c1);//  w  w w  . ja va2  s  .  com
    assertEquals("one so far", 1, repo.size());
    Collection<CustomerInfo> customers = repo.list();
    assertEquals("one in list", 1, customers.size());
    assertTrue("correct one", customers.contains(c1));

    CustomerInfo c2 = new CustomerInfo("Nowthen", 9);
    repo.add(c2);
    assertEquals("two", 2, repo.size());
    customers = repo.list();
    assertEquals("two in list", 2, customers.size());
    assertTrue("c1 there", customers.contains(c1));
    assertTrue("c2 there", customers.contains(c2));
}

From source file:de.dhke.projects.cutil.collections.MultiMapUtilTest.java

/**
 * Test of getTransitive method, of class MapUtil.
 *///from ww  w.  j a v  a 2s.co  m
@Test
public void testGetTransitive_MultiMap_GenericType() {
    MultiMap<String, String> aMultiMap = new MultiHashMap<>();
    aMultiMap.put("A", "B");
    aMultiMap.put("B", "C");
    Collection<String> result = MultiMapUtil.getTransitive(aMultiMap, "A");
    assertEquals(2, result.size());
    assertTrue(result.contains("B"));
    assertTrue(result.contains("C"));

    aMultiMap.put("C", "D");
    result = MultiMapUtil.getTransitive(aMultiMap, "A");
    assertEquals(3, result.size());
    assertTrue(result.contains("B"));
    assertTrue(result.contains("C"));
    assertTrue(result.contains("D"));

    aMultiMap.put("A", "E");
    result = MultiMapUtil.getTransitive(aMultiMap, "A");
    assertEquals(4, result.size());
    assertTrue(result.contains("B"));
    assertTrue(result.contains("C"));
    assertTrue(result.contains("D"));
    assertTrue(result.contains("E"));

    aMultiMap.put("C", "F");
    result = MultiMapUtil.getTransitive(aMultiMap, "A");
    assertEquals(5, result.size());
    assertTrue(result.contains("B"));
    assertTrue(result.contains("C"));
    assertTrue(result.contains("D"));
    assertTrue(result.contains("E"));
    assertTrue(result.contains("F"));

    aMultiMap.put("C", "A");
    result = MultiMapUtil.getTransitive(aMultiMap, "A");
    assertEquals(6, result.size());
    assertTrue(result.contains("A"));
    assertTrue(result.contains("B"));
    assertTrue(result.contains("C"));
    assertTrue(result.contains("D"));
    assertTrue(result.contains("E"));
    assertTrue(result.contains("F"));

}

From source file:org.trustedanalytics.user.current.AuthorizationController.java

/**
 * Returns permissions for specified organizations for administrator user. By default
 * administrators have access to every organization.
 *
 * @param orgs organizations//from  ww w.jav a  2  s. co m
 * @return permissions
 */
private Collection<CcOrgPermission> resolveAdminPermissions(Collection<UUID> orgs) {
    return ccClient.getOrgs()
            // filter organizations if at least one was specified, otherwise accept all
            .filter(org -> orgs.contains(org.getGuid()) || orgs.isEmpty())
            // grant full access
            .map(org -> new CcOrgPermission(org, true, true, true)).toList().toBlocking().single();
}

From source file:IndexedSet.java

@Override
public boolean retainAll(Collection<?> c) {
    boolean removed = false;
    Iterator<T> it = list.iterator();
    while (it.hasNext()) {
        T next = it.next();/*from w  w w.  j  av a  2  s. c  o  m*/
        if (!c.contains(next)) {
            it.remove();
            set.remove(it);
            removed = true;
        }
    }
    return removed;
}

From source file:doc.action.DocSelectedCell.java

public String getHtmlDisplay(TableModel model, Column column) {
    ColumnBuilder columnBuilder = new ColumnBuilder(column);

    columnBuilder.tdStart();//from w w  w .j  a v  a  2  s  .c o m

    try {
        Object bean = model.getCurrentRowBean();
        String docId = BeanUtils.getProperty(bean, "id");

        Collection selectedDocumentsIds = (Collection) model.getContext()
                .getSessionAttribute(Constant.SELECTED_PRESIDENTS);

        if (selectedDocumentsIds != null && selectedDocumentsIds.contains(docId)) {
            columnBuilder.getHtmlBuilder().input("hidden").name("chkbx_" + docId).value("SELECTED").xclose();
            columnBuilder.getHtmlBuilder().input("checkbox").name(BeanUtils.getProperty(bean, "id"));
            columnBuilder.getHtmlBuilder().onclick("setDocState(this)");
            columnBuilder.getHtmlBuilder().checked();
            columnBuilder.getHtmlBuilder().xclose();
        } else {
            columnBuilder.getHtmlBuilder().input("hidden").name("chkbx_" + docId).value("UNSELECTED").xclose();
            columnBuilder.getHtmlBuilder().input("checkbox").name(BeanUtils.getProperty(bean, "id"));
            columnBuilder.getHtmlBuilder().onclick("setDocState(this)");
            columnBuilder.getHtmlBuilder().xclose();
        }
    } catch (Exception e) {
    }

    columnBuilder.tdEnd();
    //System.out.println(columnBuilder.toString());

    return columnBuilder.toString();
}

From source file:de.hybris.platform.acceleratorcms.services.impl.RankingCMSRestrictionService.java

@Override
public Collection<AbstractPageModel> evaluatePages(final Collection<AbstractPageModel> pages,
        final RestrictionData data) {
    final NavigableMap<Integer, List<AbstractPageModel>> allowedPages = new TreeMap<>();

    final Collection<AbstractPageModel> defaultPages = getDefaultPages(pages);
    for (final AbstractPageModel page : pages) {
        if (defaultPages.contains(page)) {
            continue;
        }//from w  ww  . j a v  a 2 s.c o m

        final List<AbstractRestrictionModel> restrictions = page.getRestrictions();
        if (restrictions == null || restrictions.isEmpty()) {
            LOG.debug("Page [" + page.getName()
                    + "] is not default page and contains no restrictions. Skipping this page.");
        } else {
            LOG.debug("Evaluating restrictions for page [" + page.getName() + "].");
            final boolean onlyOneRestrictionMustApply = page.isOnlyOneRestrictionMustApply();
            final boolean allowed = evaluate(restrictions, data, onlyOneRestrictionMustApply);
            if (allowed) {
                LOG.debug("Adding page [" + page.getName() + "] to allowed pages");
                final Integer countOfMatchingRestrictions = Integer
                        .valueOf(onlyOneRestrictionMustApply ? 1 : restrictions.size());

                if (allowedPages.containsKey(countOfMatchingRestrictions)) {
                    // Add to existing list
                    allowedPages.get(countOfMatchingRestrictions).add(page);
                } else {
                    // Add a new entry
                    final List<AbstractPageModel> list = new ArrayList<>();
                    list.add(page);
                    allowedPages.put(countOfMatchingRestrictions, list);
                }
            }
        }
    }

    final List<AbstractPageModel> result = new ArrayList<>();

    if (MapUtils.isNotEmpty(allowedPages)) {
        // Take the highest match count
        result.addAll(allowedPages.lastEntry().getValue());
    } else {
        if (defaultPages.size() > 1) {
            LOG.warn(createMoreThanOneDefaultPageWarning(defaultPages));
        }
        if (CollectionUtils.isNotEmpty(defaultPages)) {
            LOG.debug("Returning default page");
            result.add(defaultPages.iterator().next());
        }
    }

    return result;
}

From source file:com.orange.clara.tool.controllers.AbstractDefaultController.java

protected boolean isCurrentUserHasRole(RoleType... roleTypes) {
    SecurityContext securityContext = this.getSecurityContext();
    if (securityContext == null || securityContext.getAuthentication() == null) {
        return false;
    }/*from  ww  w .j  a  va  2  s . com*/
    Collection<? extends GrantedAuthority> authorities = securityContext.getAuthentication().getAuthorities();
    for (RoleType roleType : roleTypes) {
        if (!authorities.contains(new SimpleGrantedAuthority(roleType.getRealName()))) {
            return false;
        }
    }
    return true;
}

From source file:com.thoughtworks.go.server.initializers.PluginsInitializerTest.java

@Test
public void shouldNotReplacePluginsIfTheSameVersionWasAlreadyExploded() throws IOException {
    String version = "13.3.0(17222-4c7fabcb9c9e9c)";
    File versionFile = temporaryFolder.newFile("go-plugins/version.txt");
    FileUtils.writeStringToFile(versionFile, version, UTF_8);
    pluginsInitializer.initialize();//www . j a  v  a 2  s  . c o  m
    Collection collection = FileUtils.listFiles(goPluginsDir, null, true);
    assertThat(collection.size(), is(1));
    assertThat(collection.contains(versionFile), is(true));
}

From source file:com.thoughtworks.go.server.initializers.PluginsInitializerTest.java

@Test
public void shouldDeleteAllExistingPluginsWhileExplodingPluginsZip() throws IOException {
    File oldPlugin = temporaryFolder.newFile("go-plugins/old-plugin.jar");
    FileUtils.writeStringToFile(temporaryFolder.newFile("go-plugins/version.txt"),
            "13.2.0(17222-4c7fabcb9c9e9c)", UTF_8);
    pluginsInitializer.initialize();//from  w w  w  .j  a  v a  2 s  . c o  m
    Collection collection = FileUtils.listFiles(goPluginsDir, null, true);
    assertThat(collection.size(), is(2));
    assertThat(collection.contains(oldPlugin), is(false));
}

From source file:de.dhke.projects.cutil.collections.aspect.AspectMultiMapKeySet.java

private boolean batchRemove(final Collection<?> c, final boolean retain) {
    for (K key : _keySet) {
        if (c.contains(key) != retain) {
            Collection<V> values = _aspectMap.get(key);
            for (V value : values) {
                Map.Entry<K, V> entry = new DefaultMapEntry<>(key, value);
                _aspectMap.notifyBeforeElementRemoved(_aspectMap, entry);
            }// www  .  j  ava  2 s.com
        }
    }

    Iterator<K> iter = _keySet.iterator();
    boolean wasRemoved = false;
    while (iter.hasNext()) {
        K key = iter.next();
        if (c.contains(key) != retain) {
            /* use a copy, as the original collection may be modified */
            Collection<V> values = new ArrayList<>(_aspectMap.get(key));
            iter.remove();
            wasRemoved = true;
            for (V value : values) {
                Map.Entry<K, V> entry = new DefaultMapEntry<>(key, value);
                _aspectMap.notifyAfterElementRemoved(_aspectMap, entry);
            }
        }
    }
    return wasRemoved;
}