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.ocs.dynamo.filter.Contains.java

@Override
public boolean evaluate(Object that) {
    if (that == null) {
        return false;
    }/*ww  w  .jav a  2s . c  o m*/
    Object collection = getProperty(that, getPropertyId());
    if (collection != null && Collection.class.isAssignableFrom(collection.getClass())) {
        Collection<?> col = (Collection<?>) collection;
        return col.contains(value);
    }
    return false;
}

From source file:eionet.cr.util.Util.java

/**
 * If the given element name already exists (case insensitive) in the list of element names, then append a trailing unique
 * number.//ww w.jav  a2  s .c o  m
 *
 * @param element
 * @param elements
 *            elements
 * @return
 */
public static String getUniqueElementName(String element, Collection<String> elements) {

    if (element == null || element.length() == 0) {
        element = XmlUtil.INVALID_ELEMENT_NAME;
    }

    if (elements != null) {
        while (elements.contains(element)) {
            int dashPos = element.lastIndexOf("_");
            if (dashPos > 1 && dashPos < element.length() - 1) {
                String snum = element.substring(dashPos + 1);
                try {
                    int inum = Integer.parseInt(snum);
                    element = element.substring(0, dashPos) + "_" + (inum + 1);
                } catch (Exception e) {
                    element = element + "_1";
                }
            } else {
                element = element + "_1";
            }
        }
    }
    return element;
}

From source file:eu.artist.migration.mdt.umlprofilediscovery.codemodel2umlprofile.files.CodeModel2UMLProfilePostProcessor.java

/**
 * /* w w w .  j av  a2  s . c o  m*/
 * @param codeModel
 * @param profileModel
 * @param traceModel
 */
public static void runPostProcessing(IModel codeModel, IModel profileModel, IModel traceModel) {
    // init the trace map
    initProfileModel2CodeModelTraceMap(traceModel);
    initCodeModel2ProfileModelTraceMap(traceModel);

    // set default values
    setDefaultValues();

    // helper collection to find property duplicates
    Collection<String> properties = new ArrayList<String>();

    // helper collection that stores the elements to destroy
    Collection<Element> umlRemovals = new ArrayList<Element>();
    Set<TraceLink> traceRemovals = new HashSet<TraceLink>();

    // check the stereotypes for duplicates -> Property, Association,
    // Operation
    Set<? extends Object> stereotypes = profileModel.getElementsByType(UMLPackage.eINSTANCE.getStereotype());

    for (Object obj : stereotypes) {
        Stereotype stereotype = (Stereotype) obj;

        // TODO: maybe work with validators here !!
        for (Property property : stereotype.getAllAttributes()) {
            if (properties.contains(property.getName())) {

                // the extension member ends of the Extension
                for (Property extensionEnd : property.getAssociation().getMemberEnds()) {
                    umlRemovals.add(extensionEnd);

                    // if we remove an Operation extension, we should remove
                    // the constructor
                    // constraint as well
                    if (property.getType().getName().equalsIgnoreCase("Operation")) {
                        umlRemovals.add(stereotype.getOwnedRule("constructorConstraint"));
                    }

                    // if we remove a Property extension, we should remove
                    // the method
                    // constraint as well
                    if (property.getType().getName().equalsIgnoreCase("Property")) {
                        umlRemovals.add(stereotype.getOwnedRule("methodConstraint"));
                    }

                    traceRemovals.add(profileModel2CodeModeltraceMap.get(extensionEnd));
                }

                // the Extension
                umlRemovals.add(property.getAssociation());
                traceRemovals.add(profileModel2CodeModeltraceMap.get(property.getAssociation()));

                // TODO: we need to remove constraints regarding operations
                // as well!
            } else {
                properties.add(property.getName());
            }
        }

        // clear the collection of properties for the next stereotype
        properties.clear();
    }

    // remove the trace links
    for (TraceLink traceLink : traceRemovals) {
        Trace trace = (Trace) traceLink.eContainer();
        trace.getTraceLinks().remove(traceLink);
    }

    // remove the uml elements
    for (Element element : umlRemovals) {
        element.destroy();
    }
}

From source file:org.apache.camel.component.hazelcast.TestHazelcastMultimapProducerForSpring.java

@Test
public void testPut() throws InterruptedException {
    template.sendBodyAndHeader("direct:put", "my-foo", HazelcastConstants.OBJECT_ID, "4711");
    template.sendBodyAndHeader("direct:put", "my-bar", HazelcastConstants.OBJECT_ID, "4711");

    assertTrue(map.containsKey("4711"));
    Collection<Object> values = map.get("4711");

    assertTrue(values.contains("my-foo"));
    assertTrue(values.contains("my-bar"));
}

From source file:org.deeplearning4j.spark.models.embeddings.word2vec.Word2VecTest.java

@Test
public void testConcepts() throws Exception {
    JavaRDD<String> corpus = sc.textFile(new ClassPathResource("raw_sentences.txt").getFile().getAbsolutePath())
            .map(new Function<String, String>() {
                @Override//from w  w w .  ja  v  a  2  s  .c  o m
                public String call(String s) throws Exception {
                    return s.toLowerCase();
                }
            }).cache();

    Word2Vec word2Vec = new Word2Vec();
    sc.getConf().set(Word2VecPerformer.NEGATIVE, String.valueOf(0));
    Pair<VocabCache, WeightLookupTable> table = word2Vec.train(corpus);
    WordVectors vectors = WordVectorSerializer.fromPair(new Pair<>(table.getSecond(), table.getFirst()));
    Collection<String> words = vectors.wordsNearest("day", 20);
    assertTrue(words.contains("week"));
}

From source file:de.lgblaumeiser.ptm.analysis.DataAnalysisServiceTest.java

@Test
public void testDataAnalysisServiceClean() {
    Collection<Collection<Object>> result = testee.analyze(ANALYSISID, asList(PARAM1, PARAM2));
    assertEquals(1, result.size());//from w  w w.  ja  v  a  2 s . com
    Collection<Object> content = get(result, 0);
    assertEquals(2, content.size());
    assertTrue(content.contains(PARAM1));
    assertTrue(content.contains(PARAM2));

}

From source file:com.github.shirashiki.ideastore.cloud.test.integration.AbstractApiTest.java

@Test
public void testAddIdea() throws Exception {
    // this uses Gson to convert dates to a specific format.
    // A similar task to be done in the server side in spring;
    // retrofit is used in the client, jackson is used in the server
    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") // this is one of the jackson accepted formats
            .create();/*from   w w w  .j a va2s.  co m*/

    IdeaSvcApi ideaService = new RestAdapter.Builder().setConverter(new GsonConverter(gson))
            .setEndpoint(TEST_URL).setLogLevel(LogLevel.FULL).build().create(IdeaSvcApi.class);

    Idea newIdea = TestData.randomIdea();

    // adds idea
    boolean ok = ideaService.addIdea(newIdea);

    // checks if it was added
    Collection<Idea> ideas = ideaService.getIdeaList();
    assertTrue(ideas.contains(newIdea));

}

From source file:com.devnexus.ting.security.RoleAwareSimpleUrlAuthenticationSuccessHandler.java

@Override
protected void handle(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
        throws IOException, ServletException {
    String targetUrl = determineTargetUrl(request, response);

    if (response.isCommitted()) {
        logger.debug("Response has already been committed. Unable to redirect to " + targetUrl);
        return;/* w ww .  j  a  v  a 2  s  .c  o  m*/
    }

    final Collection<? extends GrantedAuthority> auths = authentication.getAuthorities();

    if (auths.size() == 1 && auths.contains("ROLE_APP_USER")) {
        super.getRedirectStrategy().sendRedirect(request, response, "/s/cfp/index");
    }

    super.getRedirectStrategy().sendRedirect(request, response, targetUrl);
}

From source file:org.mule.modules.automation.testcases.CreateIssueTestCases.java

@Category({ RegressionTests.class, SmokeTests.class })
@Test/*from  w  w  w .  ja v a2  s. c om*/
public void testCreateIssue() throws Exception {
    Issue result = runFlowAndGetPayload("create-issue");
    Collection<Issue> projectIssues = runFlowAndGetPayload("get-project-issues");
    Assert.notNull(result);
    Assert.isTrue(projectIssues.contains(result));
    Assert.isTrue(result.getSubject().contentEquals("Connector Testing: Creating new Issue"));
    Assert.isTrue(result.getDescription().contentEquals("Connector Testing: Description for the new Issue"));
    Assert.isTrue(result.getPriorityId() == 4);
    Assert.isTrue(result.getStatusId() == 1);
    Assert.isTrue(result.getStatusName().contentEquals("New"));
}

From source file:com.xpn.xwiki.export.html.HtmlPackager.java

/**
 * Add a directory and all its sub-directories to the package.
 * /*from w ww.ja  v a2  s.c om*/
 * @param directory the directory to add.
 * @param out the ZIP output stream where to put the skin.
 * @param basePath the path where to put the directory in the package.
 * @throws IOException error when adding the directory to package.
 */
private static void addDirToZip(File directory, ZipOutputStream out, String basePath,
        Collection<String> exportedSkinFiles) throws IOException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Adding dir [" + directory.getPath() + "] to the Zip file being generated.");
    }

    if (!directory.isDirectory()) {
        return;
    }

    File[] files = directory.listFiles();

    if (files == null) {
        return;
    }

    for (int i = 0; i < files.length; ++i) {
        File file = files[i];
        if (file.isDirectory()) {
            addDirToZip(file, out, basePath + file.getName() + ZIPPATH_SEPARATOR, exportedSkinFiles);
        } else {
            String path = basePath + file.getName();

            if (exportedSkinFiles != null && exportedSkinFiles.contains(path)) {
                continue;
            }

            FileInputStream in = new FileInputStream(file);

            try {
                // Starts a new Zip entry. It automatically closes the previous entry if present.
                out.putNextEntry(new ZipEntry(path));

                try {
                    IOUtils.copy(in, out);
                } finally {
                    out.closeEntry();
                }
            } finally {
                in.close();
            }
        }
    }
}