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.myrrix.common.collection.FastIDSetTest.java

@Test
public void testVersusHashSet() {
    FastIDSet actual = new FastIDSet(1);
    Collection<Integer> expected = new HashSet<Integer>(1000000);
    RandomGenerator r = RandomManager.getRandom();
    for (int i = 0; i < 1000000; i++) {
        double d = r.nextDouble();
        Integer key = r.nextInt(100);
        if (d < 0.4) {
            assertEquals(expected.contains(key), actual.contains(key));
        } else {//from ww w  .  jav a 2 s  .  c o m
            if (d < 0.7) {
                assertEquals(expected.add(key), actual.add(key));
            } else {
                assertEquals(expected.remove(key), actual.remove(key));
            }
            assertEquals(expected.size(), actual.size());
            assertEquals(expected.isEmpty(), actual.isEmpty());
        }
    }
}

From source file:org.craftercms.deployer.impl.TargetResolverImpl.java

protected void destroyContextsWithNoCustomConfigFile(Collection<File> configFiles) {
    targetContextCache.values().removeIf(context -> {
        String contextId = context.getId();
        if (!configFiles.contains(getConfigFileFromTargetId(contextId))) {
            logger.info("No YAML config file found for target '{}' under {}. Destroying target context...",
                    contextId, configFolder);

            context.destroy();//from   www .  ja va  2 s  .  c  o m

            return true;
        } else {
            return false;
        }
    });
}

From source file:gobblin.util.TemplateTest.java

@Test
public void testRequiredAttrList() throws Exception {
    Properties jobProps = this.userProp;

    Collection<String> requiredConfigList = ResourceBasedJobTemplate
            .forURI(new URI(jobProps.getProperty(ConfigurationKeys.JOB_TEMPLATE_PATH)),
                    new PackagedTemplatesJobCatalogDecorator())
            .getRequiredConfigList();//  ww w. j a v a2  s  . co m
    Assert.assertEquals(requiredConfigList.size(), 3);
    Assert.assertTrue(requiredConfigList.contains("required0"));
    Assert.assertTrue(requiredConfigList.contains("required1"));
    Assert.assertTrue(requiredConfigList.contains("required2"));
}

From source file:io.github.jeddict.jcode.util.JavaSourceHelper.java

public static void addImports(WorkingCopy copy, String[] imports) {
    Collection<String> existingImports = getImports(copy);
    TreeMaker maker = copy.getTreeMaker();

    CompilationUnitTree tree = copy.getCompilationUnit();
    CompilationUnitTree modifiedTree = tree;

    for (String imp : imports) {
        if (!existingImports.contains(imp)) {
            modifiedTree = maker.addCompUnitImport(modifiedTree, maker.Import(maker.Identifier(imp), false));
        }//ww  w  .j  a va2s .c om
    }

    copy.rewrite(tree, modifiedTree);
}

From source file:org.openvpms.component.business.service.lookup.AbstractLookupServiceTest.java

/**
 * Tests the {@link ILookupService#getLookups} method.
 *//*from w  ww .j  a  va 2  s . co  m*/
@Test
public void testGetLookups() {
    Collection<Lookup> lookups1 = lookupService.getLookups("lookup.country");

    Lookup lookup1 = createLookup("lookup.country", "AU");
    Lookup lookup2 = createLookup("lookup.country", "NZ");
    save(lookup1);
    save(lookup2);

    Collection<Lookup> lookups2 = lookupService.getLookups("lookup.country");
    assertEquals(lookups1.size() + 2, lookups2.size());
    assertTrue(lookups2.contains(lookup1));
    assertTrue(lookups2.contains(lookup2));

    lookup2.setActive(false);
    save(lookup2);

    Collection<Lookup> lookups3 = lookupService.getLookups("lookup.country");
    assertEquals(lookups1.size() + 1, lookups3.size());
    assertTrue(lookups3.contains(lookup1));
    assertFalse(lookups3.contains(lookup2));
}

From source file:org.openmrs.module.pharmacyapi.api.prescription.validation.PrescriptionItemRule.java

@SuppressWarnings("unchecked")
private void checkAllArvItemHaveUniqueRegimen(final Prescription prescription,
        final List<PrescriptionItem> prescriptionItems) throws PharmacyBusinessException {

    final DrugRegimeService drugRegimeService = Context.getService(DrugRegimeService.class);

    final Concept regimen = prescription.getRegime();

    if (regimen != null) {

        final Collection<Concept> itemsRegimens = new ArrayList<>();

        for (final PrescriptionItem prescriptionItem : prescriptionItems) {

            final Drug drug = Context.getConceptService()
                    .getDrugByUuid(prescriptionItem.getDrugOrder().getDrug().getUuid());
            final List<DrugRegime> drugRegimens = drugRegimeService.findDrugRegimeByDrugUuid(drug.getUuid());

            final Collection<Concept> regimens = CollectionUtils.collect(drugRegimens,
                    TransformerUtils.invokerTransformer("getRegime"));

            if (!regimens.isEmpty() && !regimens.contains(regimen)) {
                final Collection<String> regimeNames = CollectionUtils.collect(regimens,
                        TransformerUtils.invokerTransformer("getDisplayString"));
                throw new PharmacyBusinessException("Nao foi encontrada correspondencia entre os regimes "
                        + StringUtils.join(regimeNames, "|") + " do medicamento " + drug.getDisplayName()
                        + " e o regime " + regimen.getDisplayString() + " informado");
            }/*from w  w w . j  a va 2s  .c o  m*/
            itemsRegimens.addAll(regimens);
        }

        if (itemsRegimens.isEmpty()) {
            throw new PharmacyBusinessException("Nao pode ser criada Prescricao ARV para medicamentos nao ARV");
        }
    }
}

From source file:com.cloudera.oryx.common.collection.LongSetTest.java

@Test
public void testVersusHashSet() {
    LongSet actual = new LongSet(1);
    Collection<Integer> expected = Sets.newHashSet();
    RandomGenerator r = RandomManager.getRandom();
    for (int i = 0; i < 1000000; i++) {
        double d = r.nextDouble();
        Integer key = r.nextInt(100);
        if (d < 0.4) {
            assertEquals(expected.contains(key), actual.contains(key));
        } else {/*from w  w  w  .ja v  a2 s .c om*/
            if (d < 0.7) {
                assertEquals(expected.add(key), actual.add(key));
            } else {
                assertEquals(expected.remove(key), actual.remove(key));
            }
            assertEquals(expected.size(), actual.size());
            assertEquals(expected.isEmpty(), actual.isEmpty());
        }
    }
}

From source file:CountedNumberedSet.java

public boolean retainAll(Collection c) {
    boolean changed = false;
    for (Iterator ki = nset.keySet().iterator(); ki.hasNext();) {
        Object key = ki.next();/*ww w  . ja v a  2  s .c  o  m*/
        if (!c.contains(key)) {
            nset.remove(key);
            changed = true;
        }
    }
    return changed;
}

From source file:de.alpharogroup.random.RandomExtensionsTest.java

/**
 * Test method for {@link RandomExtensions#getRandomEntry(java.util.Map)} .
 *//*from  w  ww . j  ava2 s.  c  om*/
@Test
public void testGetRandomEntryMap() {
    final Map<String, String> map = new HashMap<>();
    map.put("1", "novalue");
    map.put("2", "somevalue");
    map.put("3", "othervalue");
    map.put("4", "value");
    map.put("5", "value");
    final Collection<String> values = map.values();
    for (int i = 0; i < 100; i++) {
        final String randomValue = (String) RandomExtensions.getRandomEntry(map);
        this.result = values.contains(randomValue);
        AssertJUnit.assertTrue("", this.result);
    }
}

From source file:com.acc.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.
 * //from  w w  w  .  java 2 s.  com
 * @param httpRequest
 *           current request
 * @param previewLanguage
 *           the preview language
 * @return LanguageModel the filtered language for previewing
 */
protected LanguageModel filterPreviewLanguageForSite(final HttpServletRequest httpRequest,
        final LanguageModel previewLanguage) {
    final CMSSiteModel currentSite = getCurrentCmsSite();
    final CommerceCommonI18NService commerceCommonI18NService = getCommerceCommonI18NService();

    getBaseSiteService().setCurrentBaseSite(currentSite, false);
    final Collection<LanguageModel> siteLanguages = commerceCommonI18NService.getAllLanguages();
    if (siteLanguages.contains(previewLanguage)) {
        // The preview language is supported
        return previewLanguage;
    }
    return commerceCommonI18NService.getDefaultLanguage();
}